Index: tools/telemetry/examples/measure_trace.py |
diff --git a/tools/telemetry/examples/measure_trace.py b/tools/telemetry/examples/measure_trace.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..7fa843a53f3e956e7603b5bc43047cde483b248b |
--- /dev/null |
+++ b/tools/telemetry/examples/measure_trace.py |
@@ -0,0 +1,70 @@ |
+#!/usr/bin/env python |
+# 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 os |
+import sys |
+ |
+sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
+sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
+ 'perf')) |
+ |
+from telemetry.page import page as page_module |
+from telemetry.timeline import model |
+from telemetry.timeline import tracing_timeline_data |
+from telemetry.results import page_test_results |
+from telemetry.results import buildbot_output_formatter |
+from telemetry.web_perf import timeline_interaction_record as tir_module |
+from telemetry.web_perf.metrics import smoothness |
+# pylint: disable=F0401 |
+from measurements import smooth_gesture_util |
+ |
+ |
+def _ExtractInteractionsRecordFromThread(thread, timeline_model): |
+ records = [] |
+ for event in thread.async_slices: |
+ if not tir_module.IsTimelineInteractionRecord(event.name): |
+ continue |
+ assert event.start_thread |
+ assert event.start_thread is event.end_thread |
+ records.append( |
+ smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
+ timeline_model, |
+ tir_module.TimelineInteractionRecord.FromAsyncEvent(event))) |
+ return records |
+ |
+ |
+def Main(args): |
+ if len(args) is not 1: |
+ print 'Invalid arguments. Usage: measure_trace.py <trace file>' |
+ return 1 |
+ with open(args[0]) as trace_file: |
+ trace_data = tracing_timeline_data.TracingTimelineData( |
+ json.load(trace_file)) |
+ |
+ timeline_model = model.TimelineModel(trace_data) |
+ smoothness_metric = smoothness.SmoothnessMetric() |
+ formatters = [ |
+ buildbot_output_formatter.BuildbotOutputFormatter(sys.stdout) |
+ ] |
+ results = page_test_results.PageTestResults(output_formatters=formatters) |
+ page = page_module.Page('http://measure-trace-dummy-page') |
+ |
+ results.WillRunPage(page) |
+ for thread in timeline_model.GetAllThreads(): |
+ interaction_records = _ExtractInteractionsRecordFromThread( |
+ thread, timeline_model) |
+ if not any(interaction_records): |
+ continue |
+ for record in interaction_records: |
+ smoothness_metric.AddResults( |
chrishenry
2014/08/15 17:14:56
This is specifically for smoothness metric? Do you
|
+ timeline_model, thread, [record], results) |
+ results.DidRunPage(page) |
+ results.PrintSummary() |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(Main(sys.argv[1:])) |