| 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.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 from telemetry.value import summarizable |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 def ToJSONString(self): | 25 def ToJSONString(self): |
| 26 return '{%s}' % ', '.join([ | 26 return '{%s}' % ', '.join([ |
| 27 '"low": %i' % self.low, | 27 '"low": %i' % self.low, |
| 28 '"high": %i' % self.high, | 28 '"high": %i' % self.high, |
| 29 '"count": %i' % self.count]) | 29 '"count": %i' % self.count]) |
| 30 | 30 |
| 31 class HistogramValue(summarizable.SummarizableValue): | 31 class HistogramValue(summarizable.SummarizableValue): |
| 32 def __init__(self, page, name, units, | 32 def __init__(self, page, name, units, |
| 33 raw_value=None, raw_value_json=None, important=True, | 33 raw_value=None, raw_value_json=None, important=True, |
| 34 description=None, tir_label=None, improvement_direction=None): | 34 description=None, tir_label=None, improvement_direction=None, |
| 35 grouping_keys=None): |
| 35 super(HistogramValue, self).__init__(page, name, units, important, | 36 super(HistogramValue, self).__init__(page, name, units, important, |
| 36 description, tir_label, | 37 description, tir_label, |
| 37 improvement_direction) | 38 improvement_direction, grouping_keys) |
| 38 if raw_value_json: | 39 if raw_value_json: |
| 39 assert raw_value == None, \ | 40 assert raw_value == None, \ |
| 40 'Don\'t specify both raw_value and raw_value_json' | 41 'Don\'t specify both raw_value and raw_value_json' |
| 41 raw_value = json.loads(raw_value_json) | 42 raw_value = json.loads(raw_value_json) |
| 42 if raw_value: | 43 if raw_value: |
| 43 self.buckets = [] | 44 self.buckets = [] |
| 44 for bucket in histogram_util.GetHistogramBucketsFromRawValue(raw_value): | 45 for bucket in histogram_util.GetHistogramBucketsFromRawValue(raw_value): |
| 45 self.buckets.append(HistogramValueBucket( | 46 self.buckets.append(HistogramValueBucket( |
| 46 low=bucket['low'], | 47 low=bucket['low'], |
| 47 high=bucket['high'], | 48 high=bucket['high'], |
| 48 count=bucket['count'])) | 49 count=bucket['count'])) |
| 49 else: | 50 else: |
| 50 self.buckets = [] | 51 self.buckets = [] |
| 51 | 52 |
| 52 def __repr__(self): | 53 def __repr__(self): |
| 53 if self.page: | 54 if self.page: |
| 54 page_name = self.page.display_name | 55 page_name = self.page.display_name |
| 55 else: | 56 else: |
| 56 page_name = 'None' | 57 page_name = 'None' |
| 57 return ('HistogramValue(%s, %s, %s, raw_json_string=%s, ' | 58 return ('HistogramValue(%s, %s, %s, raw_json_string=%s, ' |
| 58 'important=%s, description=%s, tir_label=%s, ' | 59 'important=%s, description=%s, tir_label=%s, ' |
| 59 'improvement_direction=%s)') % ( | 60 'improvement_direction=%s, grouping_keys=%s)') % ( |
| 60 page_name, | 61 page_name, |
| 61 self.name, self.units, | 62 self.name, self.units, |
| 62 self.ToJSONString(), | 63 self.ToJSONString(), |
| 63 self.important, | 64 self.important, |
| 64 self.description, | 65 self.description, |
| 65 self.tir_label, | 66 self.tir_label, |
| 66 self.improvement_direction) | 67 self.improvement_direction, |
| 68 self.grouping_keys) |
| 67 | 69 |
| 68 def GetBuildbotDataType(self, output_context): | 70 def GetBuildbotDataType(self, output_context): |
| 69 if self._IsImportantGivenOutputIntent(output_context): | 71 if self._IsImportantGivenOutputIntent(output_context): |
| 70 return 'histogram' | 72 return 'histogram' |
| 71 return 'unimportant-histogram' | 73 return 'unimportant-histogram' |
| 72 | 74 |
| 73 def GetBuildbotValue(self): | 75 def GetBuildbotValue(self): |
| 74 # More buildbot insanity: perf_tests_results_helper requires the histogram | 76 # More buildbot insanity: perf_tests_results_helper requires the histogram |
| 75 # to be an array of size one. | 77 # to be an array of size one. |
| 76 return [self.ToJSONString()] | 78 return [self.ToJSONString()] |
| (...skipping 27 matching lines...) Expand all Loading... |
| 104 d['buckets'] = [b.AsDict() for b in self.buckets] | 106 d['buckets'] = [b.AsDict() for b in self.buckets] |
| 105 return d | 107 return d |
| 106 | 108 |
| 107 @staticmethod | 109 @staticmethod |
| 108 def FromDict(value_dict, page_dict): | 110 def FromDict(value_dict, page_dict): |
| 109 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) | 111 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) |
| 110 kwargs['raw_value'] = value_dict | 112 kwargs['raw_value'] = value_dict |
| 111 | 113 |
| 112 if 'improvement_direction' in value_dict: | 114 if 'improvement_direction' in value_dict: |
| 113 kwargs['improvement_direction'] = value_dict['improvement_direction'] | 115 kwargs['improvement_direction'] = value_dict['improvement_direction'] |
| 114 if 'tir_label' in value_dict: | |
| 115 kwargs['tir_label'] = value_dict['tir_label'] | |
| 116 | 116 |
| 117 return HistogramValue(**kwargs) | 117 return HistogramValue(**kwargs) |
| 118 | 118 |
| 119 @classmethod | 119 @classmethod |
| 120 def MergeLikeValuesFromSamePage(cls, values): | 120 def MergeLikeValuesFromSamePage(cls, values): |
| 121 assert len(values) > 0 | 121 assert len(values) > 0 |
| 122 v0 = values[0] | 122 v0 = values[0] |
| 123 return HistogramValue( | 123 return HistogramValue( |
| 124 v0.page, v0.name, v0.units, | 124 v0.page, v0.name, v0.units, |
| 125 raw_value_json=histogram_util.AddHistograms( | 125 raw_value_json=histogram_util.AddHistograms( |
| 126 [v.ToJSONString() for v in values]), | 126 [v.ToJSONString() for v in values]), |
| 127 important=v0.important, tir_label=v0.tir_label, | 127 important=v0.important, tir_label=v0.tir_label, |
| 128 improvement_direction=v0.improvement_direction) | 128 improvement_direction=v0.improvement_direction, |
| 129 grouping_keys=v0.grouping_keys) |
| 129 | 130 |
| 130 @classmethod | 131 @classmethod |
| 131 def MergeLikeValuesFromDifferentPages(cls, values): | 132 def MergeLikeValuesFromDifferentPages(cls, values): |
| 132 # Histograms cannot be merged across pages, at least for now. It should be | 133 # Histograms cannot be merged across pages, at least for now. It should be |
| 133 # theoretically possible, just requires more work. Instead, return None. | 134 # theoretically possible, just requires more work. Instead, return None. |
| 134 # This signals to the merging code that the data is unmergable and it will | 135 # This signals to the merging code that the data is unmergable and it will |
| 135 # cope accordingly. | 136 # cope accordingly. |
| 136 return None | 137 return None |
| OLD | NEW |