| 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 math | 5 import math |
| 6 from telemetry.value import improvement_direction |
| 6 from telemetry.value import scalar | 7 from telemetry.value import scalar |
| 7 from telemetry.web_perf.metrics import timeline_based_metric | 8 from telemetry.web_perf.metrics import timeline_based_metric |
| 8 | 9 |
| 9 | 10 |
| 10 class LayoutMetric(timeline_based_metric.TimelineBasedMetric): | 11 class LayoutMetric(timeline_based_metric.TimelineBasedMetric): |
| 11 """Computes metrics that measure layout performance, specifically, | 12 """Computes metrics that measure layout performance, specifically, |
| 12 avg and stddev of CPU time of layout-related trace events: | 13 avg and stddev of CPU time of layout-related trace events: |
| 13 | 14 |
| 14 layout_total_{avg,stddev}: FrameView::layout | 15 layout_total_{avg,stddev}: FrameView::layout |
| 15 layout_{avg,stddev}: FrameView::performLayout | 16 layout_{avg,stddev}: FrameView::performLayout |
| (...skipping 28 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 for long_name, (short_name, durations) in metrics.iteritems(): | 46 for long_name, (short_name, durations) in metrics.iteritems(): |
| 46 count = len(durations) | 47 count = len(durations) |
| 47 avg = 0.0 | 48 avg = 0.0 |
| 48 stddev = 0.0 | 49 stddev = 0.0 |
| 49 if count: | 50 if count: |
| 50 avg = sum(durations) / count | 51 avg = sum(durations) / count |
| 51 stddev = math.sqrt(sum((d - avg) ** 2 for d in durations) / count) | 52 stddev = math.sqrt(sum((d - avg) ** 2 for d in durations) / count) |
| 52 results.AddValue(scalar.ScalarValue(results.current_page, | 53 results.AddValue(scalar.ScalarValue(results.current_page, |
| 53 short_name + '_avg', 'ms', avg, | 54 short_name + '_avg', 'ms', avg, |
| 54 description='Average duration of %s events' % long_name)) | 55 description='Average duration of %s events' % long_name, |
| 56 improvement_direction=improvement_direction.DOWN)) |
| 55 results.AddValue(scalar.ScalarValue(results.current_page, | 57 results.AddValue(scalar.ScalarValue(results.current_page, |
| 56 short_name + '_stddev', 'ms', stddev, | 58 short_name + '_stddev', 'ms', stddev, |
| 57 description='stddev of duration of %s events' % long_name)) | 59 description='stddev of duration of %s events' % long_name, |
| 60 improvement_direction=improvement_direction.DOWN)) |
| OLD | NEW |