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

Unified Diff: tools/telemetry/telemetry/core/platform/process_statistic_timeline_data.py

Issue 501813002: [Telemetry] Fix idle wakeup reporting in the face of dead processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cpu_stats comment. Created 6 years, 4 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: tools/telemetry/telemetry/core/platform/process_statistic_timeline_data.py
diff --git a/tools/telemetry/telemetry/core/platform/process_statistic_timeline_data.py b/tools/telemetry/telemetry/core/platform/process_statistic_timeline_data.py
new file mode 100644
index 0000000000000000000000000000000000000000..b44f03ddb5b43183088accfbcaca0e513b3440ca
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/process_statistic_timeline_data.py
@@ -0,0 +1,58 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+class ProcessStatisticTimelineData(object):
+ """Holds value of a stat for one or more processes.
+
+ This object can hold a value for more than one pid by adding another
+ object."""
+
+ def __init__(self, pid, value):
+ super(ProcessStatisticTimelineData, self).__init__()
+ assert value >= 0
+ self._value_by_pid = {pid: value}
+
+ def __sub__(self, other):
+ """The results of subtraction is an object holding only the pids contained
+ in |self|.
+
+ The motivation is that some processes may have died between two consecutive
+ measurements. The desired behavior is to only make calculations based on
+ the processes that are alive at the end of the second measurement."""
+ # pylint: disable=W0212
+ ret = self.__class__(0, 0)
+ my_dict = self._value_by_pid
+
+ ret._value_by_pid = (
+ {k: my_dict[k] - other._value_by_pid.get(k, 0) for
+ k in my_dict.keys()})
nednguyen 2014/08/28 15:29:00 Shouldn't it be an error if some values are less t
+ return ret
+
+ def __add__(self, other):
+ """The result contains pids from both |self| and |other|, if duplicate
+ pids are found between objects, an error will occur. """
+ # pylint: disable=W0212
+ intersecting_pids = (set(self._value_by_pid.keys()) &
+ set(other._value_by_pid.keys()))
+ assert len(intersecting_pids) == 0
+
+ ret = self.__class__(0, 0)
+ ret._value_by_pid = {}
+ ret._value_by_pid.update(self._value_by_pid)
+ ret._value_by_pid.update(other._value_by_pid)
+ return ret
+
+ @property
+ def value_by_pid(self):
+ return self._value_by_pid
+
+ def total_sum(self):
+ """Returns the sum of all values contained by this object. """
+ return sum(self._value_by_pid.values())
+
+
+class IdleWakeupTimelineData(ProcessStatisticTimelineData):
+ """A ProcessStatisticTimelineData to hold idle wakeups."""
+ pass

Powered by Google App Engine
This is Rietveld 408576698