Chromium Code Reviews| Index: tools/telemetry/telemetry/histogram_measurement.py |
| diff --git a/tools/telemetry/telemetry/histogram_measurement.py b/tools/telemetry/telemetry/histogram_measurement.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e00b80108cd2ce461799672673116cb476fc6bfc |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/histogram_measurement.py |
| @@ -0,0 +1,39 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +from telemetry.perf_tests_helper import SubtractHistogram |
| + |
| +class HistogramMeasurement(object): |
| + def __init__(self, histogram, is_browser_histogram=False): |
|
nduca
2013/02/13 18:45:55
at the module level
BROWSER_HISTOGRAM = 'browser_
marja
2013/02/14 13:06:53
Done.
|
| + self.name = histogram['name'] |
| + self.units = histogram['units'] |
| + self.is_browser_histogram = is_browser_histogram |
| + self._start_values = dict() |
| + |
| + def Start(self, page, tab): |
| + """Get the starting value for the histogram. This value will then be |
| + subtracted from the actual measurement.""" |
| + data = self._GetHistogramFromDomAutomation(tab) |
| + if data: |
| + self._start_values[page.url + self.name] = data |
| + |
| + def GetValue(self, page, tab, results): |
| + data = self._GetHistogramFromDomAutomation(tab) |
| + if not data: |
| + return |
| + new_histogram = SubtractHistogram( |
| + data, self._start_values[page.url + self.name]) |
| + results.Add(self.name.replace('.', '_'), self.units, |
| + new_histogram, data_type='histogram') |
| + |
| + @property |
| + def histogram_function(self): |
| + if self.is_browser_histogram: |
| + return 'getBrowserHistogram' |
| + return 'getHistogram' |
| + |
| + def _GetHistogramFromDomAutomation(self, tab): |
| + js = ('window.domAutomationController.%s ? ' |
| + 'window.domAutomationController.%s("%s") : ""' % |
| + (self.histogram_function, self.histogram_function, self.name)) |
| + return tab.EvaluateJavaScript(js) |