Index: tools/perf/perf_tools/histogram_measurement.py |
diff --git a/tools/perf/perf_tools/histogram_measurement.py b/tools/perf/perf_tools/histogram_measurement.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0cdbd0eb51c33b67602d7eb5ab19a61673624d02 |
--- /dev/null |
+++ b/tools/perf/perf_tools/histogram_measurement.py |
@@ -0,0 +1,42 @@ |
+# 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 perf_tools import histogram as histogram_module |
+ |
+BROWSER_HISTOGRAM = 'browser_histogram' |
+RENDERER_HISTOGRAM = 'renderer_histogram' |
+ |
+class HistogramMeasurement(object): |
+ def __init__(self, histogram, histogram_type): |
+ self.name = histogram['name'] |
+ self.units = histogram['units'] |
+ self.histogram_type = histogram_type |
+ 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 = histogram_module.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.histogram_type == 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) |