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

Unified Diff: tools/telemetry/telemetry/timeline/tab_id_importer_unittest.py

Issue 441873007: Move timeline and importers to use telemetry.value.TraceValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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/timeline/tab_id_importer_unittest.py
diff --git a/tools/telemetry/telemetry/timeline/tab_id_importer_unittest.py b/tools/telemetry/telemetry/timeline/tab_id_importer_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..49541c0a0f58e408feed19edb8f0bc0b728b8325
--- /dev/null
+++ b/tools/telemetry/telemetry/timeline/tab_id_importer_unittest.py
@@ -0,0 +1,72 @@
+# 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
+
+from telemetry.timeline import model as timeline_model
+from telemetry.value import trace as trace_value_module
+from telemetry.timeline import tab_id_importer
+
+class TabIdImporterUnitTest(unittest.TestCase):
+ def testImportOverflowedTrace(self):
+ events = [
+ {'name': 'a', 'args': {}, 'pid': 1, 'ts': 7, 'cat': 'foo',
+ 'tid': 1, 'ph': 'B'},
+ {'name': 'a', 'args': {}, 'pid': 1, 'ts': 8, 'cat': 'foo',
+ 'tid': 1, 'ph': 'E'},
+ {'name': 'b', 'args': {}, 'pid': 2, 'ts': 9, 'cat': 'foo',
+ 'tid': 2, 'ph': 'B'},
+ {'name': 'b', 'args': {}, 'pid': 2, 'ts': 10, 'cat': 'foo',
+ 'tid': 2, 'ph': 'E'},
+ {'name': 'trace_buffer_overflowed',
+ 'args': {'overflowed_at_ts': 12},
+ 'pid': 2, 'ts': 0, 'tid': 2, 'ph': 'M'}
+ ]
+
+ trace_value = trace_value_module.TraceValue(events)
+
+ with self.assertRaises(tab_id_importer.TraceBufferOverflowException) \
+ as context:
+ timeline_model.TimelineModel(trace_value)
+ self.assertTrue(
+ 'Trace buffer of process with pid=2 overflowed at timestamp 12' in
+ context.exception.message)
+
+
+ def testTraceEventsWithTabIdsMarkers(self):
+ builder = trace_value_module.TraceValueBuilder()
+ builder.AddEventsTo(trace_value_module.CHROME_TRACE_PART, [
+ {'name': 'a', 'args': {}, 'pid': 1, 'ts': 20, 'tts': 10, 'cat': 'foo',
+ 'tid': 1, 'ph': 'B'},
+ # tab-id-1
+ {'name': 'tab-id-1', 'args': {}, 'pid': 1, 'ts': 25, 'cat': 'foo',
+ 'tid': 1,
+ 'ph': 'S', 'id': 72},
+ {'name': 'a', 'args': {}, 'pid': 1, 'ts': 30, 'tts': 20, 'cat': 'foo',
+ 'tid': 1, 'ph': 'E'},
+ {'name': 'tab-id-1', 'args': {}, 'pid': 1, 'ts': 35, 'cat': 'foo',
+ 'tid': 1,
+ 'ph': 'F', 'id': 72},
+ # tab-id-2
+ {'name': 'tab-id-2', 'args': {}, 'pid': 1, 'ts': 25, 'cat': 'foo',
+ 'tid': 2,
+ 'ph': 'S', 'id': 72},
+ {'name': 'tab-id-2', 'args': {}, 'pid': 1, 'ts': 26, 'cat': 'foo',
+ 'tid': 2,
+ 'ph': 'F', 'id': 72},
+ ])
+ builder.AddEventsTo(
+ trace_value_module.CHROME_TRACE_PART, ['tab-id-1', 'tab-id-2'])
+
+ m = timeline_model.TimelineModel(builder.AsValue())
+ processes = m.GetAllProcesses()
+ self.assertEqual(1, len(processes))
+ self.assertIs(processes[0], m.GetRendererProcessFromTabId('tab-id-1'))
+ self.assertIs(processes[0], m.GetRendererProcessFromTabId('tab-id-2'))
+
+ p = processes[0]
+ self.assertEqual(2, len(p.threads))
+ self.assertIs(p.threads[1], m.GetRendererThreadFromTabId('tab-id-1'))
+ self.assertIs(p.threads[2], m.GetRendererThreadFromTabId('tab-id-2'))

Powered by Google App Engine
This is Rietveld 408576698