| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 | 6 |
| 7 from telemetry.timeline import bounds | 7 from telemetry.timeline import bounds |
| 8 from telemetry.value import improvement_direction |
| 8 from telemetry.value import scalar | 9 from telemetry.value import scalar |
| 9 from telemetry.web_perf import timeline_interaction_record as tir_module | 10 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 10 from telemetry.web_perf.metrics import timeline_based_metric | 11 from telemetry.web_perf.metrics import timeline_based_metric |
| 11 from telemetry.web_perf.metrics import v8_stats as v8_stats_module | 12 from telemetry.web_perf.metrics import v8_stats as v8_stats_module |
| 12 | 13 |
| 13 | 14 |
| 14 class FastMetric(timeline_based_metric.TimelineBasedMetric): | 15 class FastMetric(timeline_based_metric.TimelineBasedMetric): |
| 15 def __init__(self): | 16 def __init__(self): |
| 16 super(FastMetric, self).__init__() | 17 super(FastMetric, self).__init__() |
| 17 | 18 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 46 Args: | 47 Args: |
| 47 model: a TimelineModule instance | 48 model: a TimelineModule instance |
| 48 renderer_thread: a telemetry.timeline.thread.Thread() instance | 49 renderer_thread: a telemetry.timeline.thread.Thread() instance |
| 49 interaction_records: an iterable of TimelineInteractionRecord instances | 50 interaction_records: an iterable of TimelineInteractionRecord instances |
| 50 results: an instance of page.PageTestResults | 51 results: an instance of page.PageTestResults |
| 51 """ | 52 """ |
| 52 self.VerifyNonOverlappedRecords(interaction_records) | 53 self.VerifyNonOverlappedRecords(interaction_records) |
| 53 | 54 |
| 54 duration = sum(r.end - r.start for r in interaction_records) | 55 duration = sum(r.end - r.start for r in interaction_records) |
| 55 results.AddValue(scalar.ScalarValue( | 56 results.AddValue(scalar.ScalarValue( |
| 56 results.current_page, 'fast-duration', 'ms', duration)) | 57 results.current_page, 'fast-duration', 'ms', duration, |
| 58 improvement_direction=improvement_direction.DOWN)) |
| 57 | 59 |
| 58 try: | 60 try: |
| 59 cpu_time = sum( | 61 cpu_time = sum( |
| 60 r.GetOverlappedThreadTimeForSlice(s) | 62 r.GetOverlappedThreadTimeForSlice(s) |
| 61 for r in interaction_records | 63 for r in interaction_records |
| 62 for s in renderer_thread.toplevel_slices) | 64 for s in renderer_thread.toplevel_slices) |
| 63 except tir_module.NoThreadTimeDataException: | 65 except tir_module.NoThreadTimeDataException: |
| 64 logging.warning( | 66 logging.warning( |
| 65 'Main thread cpu_time cannot be computed for records %s since ' | 67 'Main thread cpu_time cannot be computed for records %s since ' |
| 66 'trace does not contain thread time data.', | 68 'trace does not contain thread time data.', |
| 67 repr(interaction_records)) | 69 repr(interaction_records)) |
| 68 else: | 70 else: |
| 69 results.AddValue(scalar.ScalarValue( | 71 results.AddValue(scalar.ScalarValue( |
| 70 results.current_page, 'fast-cpu_time', 'ms', cpu_time)) | 72 results.current_page, 'fast-cpu_time', 'ms', cpu_time, |
| 73 improvement_direction=improvement_direction.DOWN)) |
| 71 | 74 |
| 72 idle_time = duration - sum( | 75 idle_time = duration - sum( |
| 73 bounds.Bounds.GetOverlap(r.start, r.end, s.start, s.end) | 76 bounds.Bounds.GetOverlap(r.start, r.end, s.start, s.end) |
| 74 for r in interaction_records | 77 for r in interaction_records |
| 75 for s in renderer_thread.toplevel_slices) | 78 for s in renderer_thread.toplevel_slices) |
| 76 results.AddValue(scalar.ScalarValue( | 79 results.AddValue(scalar.ScalarValue( |
| 77 results.current_page, 'fast-idle_time', 'ms', idle_time)) | 80 results.current_page, 'fast-idle_time', 'ms', idle_time, |
| 81 improvement_direction=improvement_direction.UP)) |
| 78 | 82 |
| 79 v8_stats = v8_stats_module.V8Stats(renderer_thread, interaction_records) | 83 v8_stats = v8_stats_module.V8Stats(renderer_thread, interaction_records) |
| 80 | 84 |
| 81 for event_stats in v8_stats.all_event_stats: | 85 for event_stats in v8_stats.all_event_stats: |
| 82 results.AddValue(scalar.ScalarValue( | 86 results.AddValue(scalar.ScalarValue( |
| 83 results.current_page, 'fast-' + event_stats.result_name, 'ms', | 87 results.current_page, 'fast-' + event_stats.result_name, 'ms', |
| 84 event_stats.thread_duration, | 88 event_stats.thread_duration, |
| 85 event_stats.result_description)) | 89 event_stats.result_description, |
| 90 improvement_direction=improvement_direction.DOWN)) |
| 86 results.AddValue(scalar.ScalarValue( | 91 results.AddValue(scalar.ScalarValue( |
| 87 results.current_page, | 92 results.current_page, |
| 88 'fast-' + event_stats.result_name + '_outside_idle', 'ms', | 93 'fast-' + event_stats.result_name + '_outside_idle', 'ms', |
| 89 event_stats.thread_duration_outside_idle, | 94 event_stats.thread_duration_outside_idle, |
| 90 event_stats.result_description + 'outside of idle notifications')) | 95 event_stats.result_description + 'outside of idle notifications', |
| 96 improvement_direction=improvement_direction.DOWN)) |
| 91 | 97 |
| 92 results.AddValue(scalar.ScalarValue( | 98 results.AddValue(scalar.ScalarValue( |
| 93 results.current_page, 'fast-total_garbage_collection', 'ms', | 99 results.current_page, 'fast-total_garbage_collection', 'ms', |
| 94 v8_stats.total_gc_thread_duration, | 100 v8_stats.total_gc_thread_duration, |
| 95 'Total thread duration of all garbage collection events')) | 101 'Total thread duration of all garbage collection events', |
| 102 improvement_direction=improvement_direction.DOWN)) |
| 96 | 103 |
| 97 results.AddValue(scalar.ScalarValue( | 104 results.AddValue(scalar.ScalarValue( |
| 98 results.current_page, 'fast-total_garbage_collection_outside_idle', | 105 results.current_page, 'fast-total_garbage_collection_outside_idle', |
| 99 'ms', v8_stats.total_gc_thread_duration_outside_idle, | 106 'ms', v8_stats.total_gc_thread_duration_outside_idle, |
| 100 'Total thread duration of all garbage collection events outside of idle' | 107 'Total thread duration of all garbage collection events outside of idle' |
| 101 'notifications')) | 108 'notifications', improvement_direction=improvement_direction.DOWN)) |
| OLD | NEW |