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

Side by Side Diff: tools/telemetry/telemetry/value/histogram.py

Issue 963313002: [Telemetry] Add interaction_record field to Value (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: misc typo fixes Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 import json 4 import json
5 5
6 from telemetry import value as value_module 6 from telemetry import value as value_module
7 from telemetry import perf_tests_helper 7 from telemetry import perf_tests_helper
8 from telemetry.value import histogram_util 8 from telemetry.value import histogram_util
9 9
10 class HistogramValueBucket(object): 10 class HistogramValueBucket(object):
(...skipping 11 matching lines...) Expand all
22 22
23 def ToJSONString(self): 23 def ToJSONString(self):
24 return '{%s}' % ', '.join([ 24 return '{%s}' % ', '.join([
25 '"low": %i' % self.low, 25 '"low": %i' % self.low,
26 '"high": %i' % self.high, 26 '"high": %i' % self.high,
27 '"count": %i' % self.count]) 27 '"count": %i' % self.count])
28 28
29 class HistogramValue(value_module.Value): 29 class HistogramValue(value_module.Value):
30 def __init__(self, page, name, units, 30 def __init__(self, page, name, units,
31 raw_value=None, raw_value_json=None, important=True, 31 raw_value=None, raw_value_json=None, important=True,
32 description=None): 32 description=None, interaction_record=None):
33 super(HistogramValue, self).__init__(page, name, units, important, 33 super(HistogramValue, self).__init__(page, name, units, important,
34 description) 34 description, interaction_record)
35 if raw_value_json: 35 if raw_value_json:
36 assert raw_value == None, \ 36 assert raw_value == None, \
37 'Don\'t specify both raw_value and raw_value_json' 37 'Don\'t specify both raw_value and raw_value_json'
38 raw_value = json.loads(raw_value_json) 38 raw_value = json.loads(raw_value_json)
39 if raw_value: 39 if raw_value:
40 self.buckets = [] 40 self.buckets = []
41 for bucket in histogram_util.GetHistogramBucketsFromRawValue(raw_value): 41 for bucket in histogram_util.GetHistogramBucketsFromRawValue(raw_value):
42 self.buckets.append(HistogramValueBucket( 42 self.buckets.append(HistogramValueBucket(
43 low=bucket['low'], 43 low=bucket['low'],
44 high=bucket['high'], 44 high=bucket['high'],
45 count=bucket['count'])) 45 count=bucket['count']))
46 else: 46 else:
47 self.buckets = [] 47 self.buckets = []
48 48
49 def __repr__(self): 49 def __repr__(self):
50 if self.page: 50 if self.page:
51 page_name = self.page.url 51 page_name = self.page.url
52 else: 52 else:
53 page_name = None 53 page_name = None
54 return ('HistogramValue(%s, %s, %s, raw_json_string="%s", ' 54 return ('HistogramValue(%s, %s, %s, raw_json_string="%s", '
55 'important=%s, description=%s') % ( 55 'important=%s, description=%s, interaction_record=%s') % (
56 page_name, 56 page_name,
57 self.name, self.units, 57 self.name, self.units,
58 self.ToJSONString(), 58 self.ToJSONString(),
59 self.important, 59 self.important,
60 self.description) 60 self.description,
61 self.interaction_record)
61 62
62 def GetBuildbotDataType(self, output_context): 63 def GetBuildbotDataType(self, output_context):
63 if self._IsImportantGivenOutputIntent(output_context): 64 if self._IsImportantGivenOutputIntent(output_context):
64 return 'histogram' 65 return 'histogram'
65 return 'unimportant-histogram' 66 return 'unimportant-histogram'
66 67
67 def GetBuildbotValue(self): 68 def GetBuildbotValue(self):
68 # More buildbot insanity: perf_tests_results_helper requires the histogram 69 # More buildbot insanity: perf_tests_results_helper requires the histogram
69 # to be an array of size one. 70 # to be an array of size one.
70 return [self.ToJSONString()] 71 return [self.ToJSONString()]
(...skipping 25 matching lines...) Expand all
96 def AsDict(self): 97 def AsDict(self):
97 d = super(HistogramValue, self).AsDict() 98 d = super(HistogramValue, self).AsDict()
98 d['buckets'] = [b.AsDict() for b in self.buckets] 99 d['buckets'] = [b.AsDict() for b in self.buckets]
99 return d 100 return d
100 101
101 @staticmethod 102 @staticmethod
102 def FromDict(value_dict, page_dict): 103 def FromDict(value_dict, page_dict):
103 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) 104 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
104 kwargs['raw_value'] = value_dict 105 kwargs['raw_value'] = value_dict
105 106
107 if 'interaction_record' in value_dict:
108 kwargs['interaction_record'] = value_dict['interaction_record']
109
106 return HistogramValue(**kwargs) 110 return HistogramValue(**kwargs)
107 111
108 @classmethod 112 @classmethod
109 def MergeLikeValuesFromSamePage(cls, values): 113 def MergeLikeValuesFromSamePage(cls, values):
110 assert len(values) > 0 114 assert len(values) > 0
111 v0 = values[0] 115 v0 = values[0]
112 return HistogramValue( 116 return HistogramValue(
113 v0.page, v0.name, v0.units, 117 v0.page, v0.name, v0.units,
114 raw_value_json=histogram_util.AddHistograms( 118 raw_value_json=histogram_util.AddHistograms(
115 [v.ToJSONString() for v in values]), 119 [v.ToJSONString() for v in values]),
116 important=v0.important) 120 important=v0.important, interaction_record=v0.interaction_record)
117 121
118 @classmethod 122 @classmethod
119 def MergeLikeValuesFromDifferentPages(cls, values, 123 def MergeLikeValuesFromDifferentPages(cls, values,
120 group_by_name_suffix=False): 124 group_by_name_suffix=False):
121 # Histograms cannot be merged across pages, at least for now. It should be 125 # Histograms cannot be merged across pages, at least for now. It should be
122 # theoretically possible, just requires more work. Instead, return None. 126 # theoretically possible, just requires more work. Instead, return None.
123 # This signals to the merging code that the data is unmergable and it will 127 # This signals to the merging code that the data is unmergable and it will
124 # cope accordingly. 128 # cope accordingly.
125 return None 129 return None
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/value/failure.py ('k') | tools/telemetry/telemetry/value/list_of_scalar_values.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698