Chromium Code Reviews| 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 | |
| 6 class _ResultsWrapper(object): | |
|
nduca
2014/03/07 20:05:56
this class should be in TimelineBasedMeasurement
| |
| 7 def __init__(self, results, interaction_record): | |
| 8 self._results = results | |
| 9 self._interaction_record = interaction_record | |
| 10 | |
| 11 def Add(self, trace_name, units, value, chart_name=None, data_type='default'): | |
| 12 trace_name = self._interaction_record.GetResultNameFor(trace_name) | |
| 13 self._results.Add(trace_name, units, value, chart_name, data_type) | |
| 14 | |
| 15 def AddSummary(self, trace_name, units, value, chart_name=None, | |
| 16 data_type='default'): | |
| 17 trace_name = self._interaction_record.GetResultNameFor(trace_name) | |
| 18 self._results.AddSummary(trace_name, units, value, chart_name, data_type) | |
| 19 | |
| 20 | |
| 21 def WrapResults(add_results_func): | |
| 22 def WrappedAddResults(self, model, renderer_thread, interaction_record, | |
| 23 results): | |
| 24 wrapped_results = _ResultsWrapper(results, interaction_record) | |
| 25 return add_results_func(self, model, renderer_thread, interaction_record, | |
| 26 wrapped_results) | |
| 27 return WrappedAddResults | |
| 28 | |
| 29 | |
| 5 class TimelineBasedMetric(object): | 30 class TimelineBasedMetric(object): |
| 6 def __init__(self): | 31 def __init__(self): |
| 7 """Computes metrics from a telemetry.core.timeline Model and a range | 32 """Computes metrics from a telemetry.core.timeline Model and a range |
| 8 | 33 |
| 9 """ | 34 """ |
| 10 super(TimelineBasedMetric, self).__init__() | 35 super(TimelineBasedMetric, self).__init__() |
| 11 | 36 |
| 37 @WrapResults | |
|
nduca
2014/03/07 20:05:56
i'd rather that the measurement construct this wra
| |
| 12 def AddResults(self, model, renderer_thread, | 38 def AddResults(self, model, renderer_thread, |
| 13 interaction_record, results): | 39 interaction_record, results): |
| 14 """Computes and adds metrics for the interaction_record's time range. | 40 """Computes and adds metrics for the interaction_record's time range. |
| 15 | 41 |
| 16 The override of this method should compute results on the data **only** | 42 The override of this method should compute results on the data **only** |
| 17 within the interaction_record's start and end time. | 43 within the interaction_record's start and end time. |
| 18 | 44 |
| 19 model is an instance of telemetry.core.timeline.model.TimelineModel. | 45 model is an instance of telemetry.core.timeline.model.TimelineModel. |
| 20 interaction_record is an instance of TimelineInteractionRecord. | 46 interaction_record is an instance of TimelineInteractionRecord. |
| 21 results is an instance of page.PageTestResults. | 47 results is an instance of page.PageTestResults. |
| 22 | 48 |
| 23 """ | 49 """ |
| 24 raise NotImplementedError() | 50 raise NotImplementedError() |
| OLD | NEW |