| 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 scalar |
| 8 from telemetry.web_perf import timeline_interaction_record as tir_module | 9 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 9 from telemetry.web_perf.metrics import timeline_based_metric | 10 from telemetry.web_perf.metrics import timeline_based_metric |
| 10 | 11 |
| 11 | 12 |
| 12 class FastMetric(timeline_based_metric.TimelineBasedMetric): | 13 class FastMetric(timeline_based_metric.TimelineBasedMetric): |
| 13 def __init__(self): | 14 def __init__(self): |
| 14 super(FastMetric, self).__init__() | 15 super(FastMetric, self).__init__() |
| 15 | 16 |
| 16 def AddResults(self, model, renderer_thread, interaction_records, results): | 17 def AddResults(self, model, renderer_thread, interaction_records, results): |
| 17 """Add three results: duration, cpu_time, and idle_time. | 18 """Add three results: duration, cpu_time, and idle_time. |
| 18 | 19 |
| 19 duration is the total wall time for |interaction_records|. | 20 duration is the total wall time for |interaction_records|. |
| 20 cpu_time is the renderer thread time that intersects |interaction_records|. | 21 cpu_time is the renderer thread time that intersects |interaction_records|. |
| 21 idle time is wall time for |interaction_records| for which renderer slices | 22 idle time is wall time for |interaction_records| for which renderer slices |
| 22 do not overlap. Note that unscheduled renderer thread time is not | 23 do not overlap. Note that unscheduled renderer thread time is not |
| 23 counted. Idle time is time for which there was nothing to do. | 24 counted. Idle time is time for which there was nothing to do. |
| 24 | 25 |
| 25 Args: | 26 Args: |
| 26 model: a TimelineModule instance | 27 model: a TimelineModule instance |
| 27 renderer_thread: a telemetry.timeline.thread.Thread() instance | 28 renderer_thread: a telemetry.timeline.thread.Thread() instance |
| 28 interaction_records: an iterable of TimelineInteractionRecord instances | 29 interaction_records: an iterable of TimelineInteractionRecord instances |
| 29 results: an instance of page.PageTestResults | 30 results: an instance of page.PageTestResults |
| 30 """ | 31 """ |
| 31 self.VerifyNonOverlappedRecords(interaction_records) | 32 self.VerifyNonOverlappedRecords(interaction_records) |
| 32 | 33 |
| 33 duration = sum(r.end - r.start for r in interaction_records) | 34 duration = sum(r.end - r.start for r in interaction_records) |
| 34 results.Add('fast-duration', 'ms', duration) | 35 results.AddValue(scalar.ScalarValue( |
| 36 results.current_page, 'fast-duration', 'ms', duration)) |
| 35 | 37 |
| 36 try: | 38 try: |
| 37 cpu_time = sum( | 39 cpu_time = sum( |
| 38 r.GetOverlappedThreadTimeForSlice(s) | 40 r.GetOverlappedThreadTimeForSlice(s) |
| 39 for r in interaction_records | 41 for r in interaction_records |
| 40 for s in renderer_thread.toplevel_slices) | 42 for s in renderer_thread.toplevel_slices) |
| 41 except tir_module.NoThreadTimeDataException: | 43 except tir_module.NoThreadTimeDataException: |
| 42 logging.warning( | 44 logging.warning( |
| 43 'Main thread cpu_time cannot be computed for records %s since ' | 45 'Main thread cpu_time cannot be computed for records %s since ' |
| 44 'trace does not contain thread time data.', | 46 'trace does not contain thread time data.', |
| 45 repr(interaction_records)) | 47 repr(interaction_records)) |
| 46 else: | 48 else: |
| 47 results.Add('fast-cpu_time', 'ms', cpu_time) | 49 results.AddValue(scalar.ScalarValue( |
| 50 results.current_page, 'fast-cpu_time', 'ms', cpu_time)) |
| 48 | 51 |
| 49 idle_time = duration - sum( | 52 idle_time = duration - sum( |
| 50 bounds.Bounds.GetOverlap(r.start, r.end, s.start, s.end) | 53 bounds.Bounds.GetOverlap(r.start, r.end, s.start, s.end) |
| 51 for r in interaction_records | 54 for r in interaction_records |
| 52 for s in renderer_thread.toplevel_slices) | 55 for s in renderer_thread.toplevel_slices) |
| 53 results.Add('fast-idle_time', 'ms', idle_time) | 56 results.AddValue(scalar.ScalarValue( |
| 57 results.current_page, 'fast-idle_time', 'ms', idle_time)) |
| OLD | NEW |