Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: tools/perf/metrics/histogram.py

Issue 22492004: Move memory-related histogram data collection to metrics/memory.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/perf/metrics/histogram.py
diff --git a/tools/perf/metrics/histogram.py b/tools/perf/metrics/histogram.py
index 147ae966321606dcb6b47a2863b47311dfa55021..6a45b1cb3cd29de8a99e9b974dd10ba77d8cf2d4 100644
--- a/tools/perf/metrics/histogram.py
+++ b/tools/perf/metrics/histogram.py
@@ -1,40 +1,72 @@
# Copyright 2013 The Chromium Authors. All rights reserved.
qyearsley 2013/08/08 17:35:52 This module contains basically what was just in 'h
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-from metrics import histogram_util
+
+"""This is a helper module to get and manipulate histogram data.
+
+The histogram data is the same data as is visible from "chrome://histograms".
+More information can be found at: chromium/src/base/metrics/histogram.h
+
+Histogram data is collected with either the window.statsCollectionController
+object or the window.domAutomationController object.
+"""
+
+import json
+import logging
BROWSER_HISTOGRAM = 'browser_histogram'
RENDERER_HISTOGRAM = 'renderer_histogram'
-class HistogramMetric(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_util.SubtractHistogram(
- data, self._start_values[page.url + self.name])
- results.Add(self.name, self.units, new_histogram,
- data_type='unimportant-histogram')
-
- @property
- def histogram_function(self):
- if self.histogram_type == BROWSER_HISTOGRAM:
- return 'getBrowserHistogram'
- return 'getHistogram'
-
- def _GetHistogramFromDomAutomation(self, tab):
- return histogram_util.GetHistogramFromDomAutomation(
- self.histogram_function, self.name, tab)
+def GetHistogramData(histogram_type, histogram_name, tab):
qyearsley 2013/08/08 17:35:52 I renamed GetHistogramFromDomAutomation to GetHist
+ """Get a json serialization of a histogram."""
+ assert histogram_type in [BROWSER_HISTOGRAM, RENDERER_HISTOGRAM]
+ function = 'getHistogram'
+ if histogram_type == BROWSER_HISTOGRAM:
+ function = 'getBrowserHistogram'
+ # TODO(jeremy): Remove references to
+ # domAutomationController when we update the reference builds.
+ return tab.EvaluateJavaScript(
+ '(window.statsCollectionController ? '
+ 'statsCollectionController : '
+ 'domAutomationController).%s("%s")' %
+ (function, histogram_name))
+
+
+def SubtractHistogram(histogram_json, start_histogram_json):
+ """Subtracts a previous histogram from a histogram.
+
+ Both parameters and the returned result are json serializations.
+ """
+ start_histogram = json.loads(start_histogram_json)
+ # It's ok if the start histogram is empty (we had no data, maybe even no
+ # histogram at all, at the start of the test).
+ if 'buckets' not in start_histogram:
+ return histogram_json
+
+ histogram = json.loads(histogram_json)
+ if ('pid' in start_histogram and 'pid' in histogram
+ and start_histogram['pid'] != histogram['pid']):
+ raise Exception(
+ 'Trying to compare histograms from different processes (%d and %d)'
+ % (start_histogram['pid'], histogram['pid']))
+
+ start_histogram_buckets = dict()
+ for b in start_histogram['buckets']:
+ start_histogram_buckets[b['low']] = b['count']
+
+ new_buckets = []
+ for b in histogram['buckets']:
+ new_bucket = b
+ low = b['low']
+ if low in start_histogram_buckets:
+ new_bucket['count'] = b['count'] - start_histogram_buckets[low]
+ if new_bucket['count'] < 0:
+ logging.error('Histogram subtraction error, starting histogram most '
+ 'probably invalid.')
+ if new_bucket['count']:
+ new_buckets.append(new_bucket)
+ histogram['buckets'] = new_buckets
+ histogram['count'] -= start_histogram['count']
+
+ return json.dumps(histogram)
+

Powered by Google App Engine
This is Rietveld 408576698