OLD | NEW |
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 Loading... |
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, higher_is_better=None): |
33 super(HistogramValue, self).__init__(page, name, units, important, | 33 super(HistogramValue, self).__init__(page, name, units, important, |
34 description) | 34 description, higher_is_better) |
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 assert 'buckets' in raw_value | 40 assert 'buckets' in raw_value |
41 assert isinstance(raw_value['buckets'], list) | 41 assert isinstance(raw_value['buckets'], list) |
42 self.buckets = [] | 42 self.buckets = [] |
43 for bucket in raw_value['buckets']: | 43 for bucket in raw_value['buckets']: |
44 self.buckets.append(HistogramValueBucket( | 44 self.buckets.append(HistogramValueBucket( |
45 low=bucket['low'], | 45 low=bucket['low'], |
46 high=bucket['high'], | 46 high=bucket['high'], |
47 count=bucket['count'])) | 47 count=bucket['count'])) |
48 else: | 48 else: |
49 self.buckets = [] | 49 self.buckets = [] |
50 | 50 |
51 def __repr__(self): | 51 def __repr__(self): |
52 if self.page: | 52 if self.page: |
53 page_name = self.page.url | 53 page_name = self.page.url |
54 else: | 54 else: |
55 page_name = None | 55 page_name = None |
56 return ('HistogramValue(%s, %s, %s, raw_json_string="%s", ' | 56 return ('HistogramValue(%s, %s, %s, raw_json_string="%s", ' |
57 'important=%s, description=%s') % ( | 57 'important=%s, description=%s, higher_is_better=%s') % ( |
58 page_name, | 58 page_name, |
59 self.name, self.units, | 59 self.name, self.units, |
60 self.ToJSONString(), | 60 self.ToJSONString(), |
61 self.important, | 61 self.important, |
62 self.description) | 62 self.description, |
| 63 self.higher_is_better) |
63 | 64 |
64 def GetBuildbotDataType(self, output_context): | 65 def GetBuildbotDataType(self, output_context): |
65 if self._IsImportantGivenOutputIntent(output_context): | 66 if self._IsImportantGivenOutputIntent(output_context): |
66 return 'histogram' | 67 return 'histogram' |
67 return 'unimportant-histogram' | 68 return 'unimportant-histogram' |
68 | 69 |
69 def GetBuildbotValue(self): | 70 def GetBuildbotValue(self): |
70 # More buildbot insanity: perf_tests_results_helper requires the histogram | 71 # More buildbot insanity: perf_tests_results_helper requires the histogram |
71 # to be an array of size one. | 72 # to be an array of size one. |
72 return [self.ToJSONString()] | 73 return [self.ToJSONString()] |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return HistogramValue(**kwargs) | 109 return HistogramValue(**kwargs) |
109 | 110 |
110 @classmethod | 111 @classmethod |
111 def MergeLikeValuesFromSamePage(cls, values): | 112 def MergeLikeValuesFromSamePage(cls, values): |
112 assert len(values) > 0 | 113 assert len(values) > 0 |
113 v0 = values[0] | 114 v0 = values[0] |
114 return HistogramValue( | 115 return HistogramValue( |
115 v0.page, v0.name, v0.units, | 116 v0.page, v0.name, v0.units, |
116 raw_value_json=histogram_util.AddHistograms( | 117 raw_value_json=histogram_util.AddHistograms( |
117 [v.ToJSONString() for v in values]), | 118 [v.ToJSONString() for v in values]), |
118 important=v0.important) | 119 important=v0.important, higher_is_better=v0.higher_is_better) |
119 | 120 |
120 @classmethod | 121 @classmethod |
121 def MergeLikeValuesFromDifferentPages(cls, values, | 122 def MergeLikeValuesFromDifferentPages(cls, values, |
122 group_by_name_suffix=False): | 123 group_by_name_suffix=False): |
123 # Histograms cannot be merged across pages, at least for now. It should be | 124 # Histograms cannot be merged across pages, at least for now. It should be |
124 # theoretically possible, just requires more work. Instead, return None. | 125 # theoretically possible, just requires more work. Instead, return None. |
125 # This signals to the merging code that the data is unmergable and it will | 126 # This signals to the merging code that the data is unmergable and it will |
126 # cope accordingly. | 127 # cope accordingly. |
127 return None | 128 return None |
OLD | NEW |