Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1775)

Unified Diff: base/process/process_metrics.cc

Issue 546193002: Add an 'Idle Wake Ups' metric to the Linux task manager, implement backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wakeclean
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/process/process_metrics.cc
diff --git a/base/process/process_metrics.cc b/base/process/process_metrics.cc
index 3465d5782c38e501d5f48d126038e627d54c6eb9..90baae5051c73379308c1effbd3226fab052332d 100644
--- a/base/process/process_metrics.cc
+++ b/base/process/process_metrics.cc
@@ -51,11 +51,37 @@ double ProcessMetrics::GetPlatformIndependentCPUUsage() {
#endif
}
-#if !defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_LINUX)
+int ProcessMetrics::CalculateIdleWakeupsPerSecond(
+ uint64 absolute_idle_wakeups) {
+ TimeTicks time = TimeTicks::Now();
+
+ if (last_absolute_idle_wakeups_ == 0) {
+ // First call, just set the last values.
+ last_idle_wakeups_time_ = time;
+ last_absolute_idle_wakeups_ = absolute_idle_wakeups;
+ return 0;
+ }
+
+ int64 wakeups_delta = absolute_idle_wakeups - last_absolute_idle_wakeups_;
+ int64 time_delta = (time - last_idle_wakeups_time_).InMicroseconds();
+ if (time_delta == 0) {
+ NOTREACHED();
+ return 0;
+ }
+
+ last_idle_wakeups_time_ = time;
+ last_absolute_idle_wakeups_ = absolute_idle_wakeups;
+
+ // Round to average wakeups per second.
+ int64 wakeups_delta_for_ms = wakeups_delta * Time::kMicrosecondsPerSecond;
+ return (wakeups_delta_for_ms + time_delta / 2) / time_delta;
+}
+#else
int ProcessMetrics::GetIdleWakeupsPerSecond() {
NOTIMPLEMENTED(); // http://crbug.com/120488
return 0;
}
-#endif // !defined(OS_MACOSX)
+#endif // defined(OS_MACOSX) || defined(OS_LINUX)
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698