From 5014e16e50fbb3566a8a055919d245f385b0163d Mon Sep 17 00:00:00 2001 From: aerotwist Date: Wed, 15 Jul 2015 05:33:49 -0700 Subject: [PATCH] Adds labels to processes. We don't currently populate labels with the other information for a process. This adds labels to the importer. R=skyostil@chromium.org BUG= Review URL: https://codereview.chromium.org/1235433003 Cr-Commit-Position: refs/heads/master@{#338842} --- tools/telemetry/telemetry/timeline/process.py | 1 + .../telemetry/timeline/trace_event_importer.py | 3 +++ .../timeline/trace_event_importer_unittest.py | 23 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/tools/telemetry/telemetry/timeline/process.py b/tools/telemetry/telemetry/timeline/process.py index df93fedd33a8..8accaa56460b 100644 --- a/tools/telemetry/telemetry/timeline/process.py +++ b/tools/telemetry/telemetry/timeline/process.py @@ -15,6 +15,7 @@ class Process(event_container.TimelineEventContainer): def __init__(self, parent, pid): super(Process, self).__init__('process %s' % pid, parent) self.pid = pid + self.labels = None self._threads = {} self._counters = {} self._trace_buffer_overflow_event = None diff --git a/tools/telemetry/telemetry/timeline/trace_event_importer.py b/tools/telemetry/telemetry/timeline/trace_event_importer.py index c4ac82173626..6d79d41033ae 100644 --- a/tools/telemetry/telemetry/timeline/trace_event_importer.py +++ b/tools/telemetry/telemetry/timeline/trace_event_importer.py @@ -148,6 +148,9 @@ class TraceEventTimelineImporter(importer.TimelineImporter): elif event['name'] == 'process_name': process = self._GetOrCreateProcess(event['pid']) process.name = event['args']['name'] + elif event['name'] == 'process_labels': + process = self._GetOrCreateProcess(event['pid']) + process.labels = event['args']['labels'] elif event['name'] == 'trace_buffer_overflowed': process = self._GetOrCreateProcess(event['pid']) process.SetTraceBufferOverflowTimestamp(event['args']['overflowed_at_ts']) diff --git a/tools/telemetry/telemetry/timeline/trace_event_importer_unittest.py b/tools/telemetry/telemetry/timeline/trace_event_importer_unittest.py index 02908374a174..10fd01f85a9a 100644 --- a/tools/telemetry/telemetry/timeline/trace_event_importer_unittest.py +++ b/tools/telemetry/telemetry/timeline/trace_event_importer_unittest.py @@ -1063,3 +1063,26 @@ class TraceEventTimelineImporterTest(unittest.TestCase): self.assertEquals(dump_id, memory_dump.dump_id) self.assertAlmostEqual(start / 1000.0, memory_dump.start) self.assertAlmostEqual(duration / 1000.0, memory_dump.duration) + + def testMetadataImport(self): + events = [ + {'cat': '__metadata', 'pid': 14689, 'tid': 14740, 'ts': 245, + 'ph': 'M', 'name': 'process_name', 'args': {'name': 'Browser'}}, + {'cat': '__metadata', 'pid': 23828, 'tid': 23828, 'ts': 0, + 'ph': 'M', 'name': 'process_labels', + 'args': {'labels': 'huge image - Google Search'}} + ] + + expected = [ + [None, 'Browser'], + ['huge image - Google Search', 'process 23828'] + ] + trace_data = trace_data_module.TraceData(events) + m = timeline_model.TimelineModel(trace_data) + processes = m.GetAllProcesses() + + self.assertEqual(len(processes), len(expected)) + for process, test_values in zip(processes, expected): + process_labels, process_name = test_values + self.assertEquals(process_labels, process.labels) + self.assertEquals(process_name, process.name) -- 2.11.4.GIT