Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import json | |
| 7 import os | |
| 8 import sys | |
| 9 | |
| 10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | |
| 11 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | |
| 12 'perf')) | |
| 13 | |
| 14 from telemetry.page import page as page_module | |
| 15 from telemetry.timeline import model | |
| 16 from telemetry.timeline import tracing_timeline_data | |
| 17 from telemetry.results import page_test_results | |
| 18 from telemetry.results import buildbot_output_formatter | |
| 19 from telemetry.web_perf import timeline_interaction_record as tir_module | |
| 20 from telemetry.web_perf.metrics import smoothness | |
| 21 # pylint: disable=F0401 | |
| 22 from measurements import smooth_gesture_util | |
| 23 | |
| 24 | |
| 25 def _ExtractInteractionsRecordFromThread(thread, timeline_model): | |
| 26 records = [] | |
| 27 for event in thread.async_slices: | |
| 28 if not tir_module.IsTimelineInteractionRecord(event.name): | |
| 29 continue | |
| 30 assert event.start_thread | |
| 31 assert event.start_thread is event.end_thread | |
| 32 records.append( | |
| 33 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | |
| 34 timeline_model, | |
| 35 tir_module.TimelineInteractionRecord.FromAsyncEvent(event))) | |
| 36 return records | |
| 37 | |
| 38 | |
| 39 def Main(args): | |
| 40 if len(args) is not 1: | |
| 41 print 'Invalid arguments. Usage: measure_trace.py <trace file>' | |
| 42 return 1 | |
| 43 with open(args[0]) as trace_file: | |
| 44 trace_data = tracing_timeline_data.TracingTimelineData( | |
| 45 json.load(trace_file)) | |
| 46 | |
| 47 timeline_model = model.TimelineModel(trace_data) | |
| 48 smoothness_metric = smoothness.SmoothnessMetric() | |
| 49 formatters = [ | |
| 50 buildbot_output_formatter.BuildbotOutputFormatter(sys.stdout) | |
| 51 ] | |
| 52 results = page_test_results.PageTestResults(output_formatters=formatters) | |
| 53 page = page_module.Page('http://measure-trace-dummy-page') | |
| 54 | |
| 55 results.WillRunPage(page) | |
| 56 for thread in timeline_model.GetAllThreads(): | |
| 57 interaction_records = _ExtractInteractionsRecordFromThread( | |
| 58 thread, timeline_model) | |
| 59 if not any(interaction_records): | |
| 60 continue | |
| 61 for record in interaction_records: | |
| 62 smoothness_metric.AddResults( | |
|
chrishenry
2014/08/15 17:14:56
This is specifically for smoothness metric? Do you
| |
| 63 timeline_model, thread, [record], results) | |
| 64 results.DidRunPage(page) | |
| 65 results.PrintSummary() | |
| 66 return 0 | |
| 67 | |
| 68 | |
| 69 if __name__ == '__main__': | |
| 70 sys.exit(Main(sys.argv[1:])) | |
| OLD | NEW |