diff options
author | Than McIntosh <thanm@google.com> | 2015-06-10 11:47:01 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2015-06-11 13:46:33 -0400 |
commit | 2297612246852bd0993e949ceccafd4a36f3a053 (patch) | |
tree | 32099b51d456d22e8c378365b0ca455311299e9a | |
parent | bb6fa058895f5aafd025643b03b8ec6c778369f5 (diff) | |
download | extras-2297612246852bd0993e949ceccafd4a36f3a053.tar.gz |
Record device screen state and system load (from /proc/loadavg).
Bug: http://b/19483574
(cherry picked from commit ebb946827ffbbb7df4c41be262a627c02bd95888)
Change-Id: I2a00e1fb075131e7d7d1a45c196ab0ac414e39c0
-rw-r--r-- | perfprofd/perf_profile.proto | 10 | ||||
-rw-r--r-- | perfprofd/perfprofdcore.cc | 37 |
2 files changed, 46 insertions, 1 deletions
diff --git a/perfprofd/perf_profile.proto b/perfprofd/perf_profile.proto index ee34163f..3932a162 100644 --- a/perfprofd/perf_profile.proto +++ b/perfprofd/perf_profile.proto @@ -91,4 +91,12 @@ message AndroidPerfProfile { // List of all load modules. repeated LoadModule load_modules = 4; -}
\ No newline at end of file + + // is device screen on at point when profile is collected? + optional bool display_on = 5; + + // system load at point when profile is collected; corresponds + // to first value from /proc/loadavg multiplied by 100 then + // converted to int32 + optional int32 sys_load_average = 6; +} diff --git a/perfprofd/perfprofdcore.cc b/perfprofd/perfprofdcore.cc index 1cf08ad1..8f5b013c 100644 --- a/perfprofd/perfprofdcore.cc +++ b/perfprofd/perfprofdcore.cc @@ -34,6 +34,7 @@ #include <set> #include <cctype> +#include <base/file.h> #include <base/stringprintf.h> #include <cutils/properties.h> @@ -481,6 +482,35 @@ static CKPROFILE_RESULT check_profiling_enabled(ConfigReader &config) return DO_COLLECT_PROFILE; } +static void annotate_encoded_perf_profile(wireless_android_play_playlog::AndroidPerfProfile *profile) +{ + // + // Load average as reported by the kernel + // + std::string load; + double fload = 0.0; + if (android::base::ReadFileToString("/proc/loadavg", &load) && + sscanf(load.c_str(), "%lf", &fload) == 1) { + int iload = static_cast<int>(fload * 100.0); + profile->set_sys_load_average(iload); + } else { + W_ALOGE("Failed to read or scan /proc/loadavg (%s)", strerror(errno)); + } + + // + // Examine the contents of wake_unlock to determine whether the + // device display is on or off. NB: is this really the only way to + // determine this info? + // + std::string disp; + if (android::base::ReadFileToString("/sys/power/wake_unlock", &disp)) { + bool ison = (strstr(disp.c_str(), "PowerManagerService.Display") == 0); + profile->set_display_on(ison); + } else { + W_ALOGE("Failed to read /sys/power/wake_unlock (%s)", strerror(errno)); + } +} + inline char* string_as_array(std::string* str) { return str->empty() ? NULL : &*str->begin(); } @@ -501,6 +531,13 @@ PROFILE_RESULT encode_to_proto(const std::string &data_file_path, return ERR_PERF_ENCODE_FAILED; } + // All of the info in 'encodedProfile' is derived from the perf.data file; + // here we tack display status and system load. + wireless_android_play_playlog::AndroidPerfProfile &prof = + const_cast<wireless_android_play_playlog::AndroidPerfProfile&> + (encodedProfile); + annotate_encoded_perf_profile(&prof); + // // Serialize protobuf to array // |