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

Unified Diff: tools/telemetry/telemetry/core/platform/timeline_objects_unittest.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: 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/timeline_objects_unittest.py
diff --git a/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py b/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..19029a4add159569bc03a3113844ea7001e7347c
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py
@@ -0,0 +1,48 @@
+# 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.
+
+import json
+import unittest
+import StringIO
+
+from telemetry.core.platform import timeline_objects
+
+
+class PlatformTimeLineObjectTest(unittest.TestCase):
+
+ def testIdleWakeupCountMath(self):
+ pid1 = 1
+ pid2 = 2
+
+ a = timeline_objects.IdleStatsData(pid1, 5)
+ b = timeline_objects.IdleStatsData(pid2, 1)
+ c = timeline_objects.IdleStatsData(pid1, 1)
+
+ # Test addition.
+ addition_result = (a + b).idle_wakeup_count_by_pid
+ self.assertEquals(5, addition_result[pid1])
+ self.assertEquals(1, addition_result[pid2])
+ self.assertEquals(2, len(addition_result.keys()))
+
+ # Test subtraction.
+ subtraction_result = ((a + b) - c).idle_wakeup_count_by_pid
+ self.assertEquals(4, subtraction_result[pid1])
+ self.assertEquals(1, len(subtraction_result.keys()))
+
+ self.assertEquals(6, (a + b).IdleWakeupCount())
+
+ def testIdleWakeupCountReporting(self):
+ pid1 = 1
+ pid2 = 2
+
+ a = timeline_objects.IdleStatsData(pid1, 1)
+ b = timeline_objects.IdleStatsData(pid2, 99)
+ c = a + b
+ self.assertEquals(100, c.IdleWakeupCount())
+
+ # Test serialization.
+ output = StringIO.StringIO()
+ c.Serialize(output)
+ deserialized = json.loads(output.getvalue())
+ self.assertEquals(100, deserialized['idleWakeupCount'])

Powered by Google App Engine
This is Rietveld 408576698