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

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

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

Powered by Google App Engine
This is Rietveld 408576698