Clean up the sampling profiler
- rename variables/fields names to match the code style (use
_underscore_names_)
- extract common property parsing in utils.cc
- fail to load profile file if any line is malformed
- added ProfileFile to manage the profile data generate in the previous
runs (replaces ProfileHelper and nests ProfileData)
Bug: 12877748
Change-Id: Ie7bda30bfdeb7e78534c986615b0649eac12a97b
diff --git a/runtime/utils.cc b/runtime/utils.cc
index f562252..05ff5ff 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -1302,4 +1302,23 @@
return true;
}
+double GetDoubleProperty(const char* property, double min_value, double max_value, double default_value) {
+#ifndef HAVE_ANDROID_OS
+ return default_value;
+#else
+ char buf[PROP_VALUE_MAX];
+ char* endptr;
+
+ property_get(property, buf, "");
+ double value = strtod(buf, &endptr);
+
+ // Return the defalt value if the string is invalid or the value is outside the given range
+ if ((value == 0 && endptr == buf) // Invalid string
+ || (value < min_value) || (value > max_value)) { // Out of range value
+ return default_value;
+ }
+ return value;
+#endif
+}
+
} // namespace art