OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 | 4 |
5 import json | 5 import json |
6 | 6 |
7 from dashboard.pinpoint.models.quest import execution | 7 from dashboard.pinpoint.models.quest import execution |
8 from dashboard.pinpoint.models.quest import quest | 8 from dashboard.pinpoint.models.quest import quest |
9 from dashboard.services import isolate_service | 9 from dashboard.services import isolate_service |
10 | 10 |
11 | 11 |
12 class ReadChartJsonValue(quest.Quest): | 12 class ReadChartJsonValue(quest.Quest): |
13 | 13 |
14 def __init__(self, metric, test): | 14 def __init__(self, metric, test): |
15 self._metric = metric | 15 self._metric = metric |
16 self._test = test | 16 self._test = test |
17 | 17 |
18 def __eq__(self, other): | 18 def __eq__(self, other): |
19 return (isinstance(other, type(self)) and | 19 return (isinstance(other, type(self)) and |
20 self._metric == other._metric and | 20 self._metric == other._metric and |
21 self._test == other._test) | 21 self._test == other._test) |
22 | 22 |
23 def __str__(self): | 23 def __str__(self): |
24 return 'Value of ' + self._metric | 24 return 'Value of ' + self._metric |
25 | 25 |
26 def Start(self, isolate_hash): | 26 def Start(self, isolate_hashes): |
27 return _ReadChartJsonValueExecution(self._metric, self._test, isolate_hash) | 27 return _ReadChartJsonValueExecution(self._metric, self._test, |
| 28 isolate_hashes) |
28 | 29 |
29 | 30 |
30 class _ReadChartJsonValueExecution(execution.Execution): | 31 class _ReadChartJsonValueExecution(execution.Execution): |
31 | 32 |
32 def __init__(self, metric, test, isolate_hash): | 33 def __init__(self, metric, test, isolate_hashes): |
33 super(_ReadChartJsonValueExecution, self).__init__() | 34 super(_ReadChartJsonValueExecution, self).__init__() |
34 self._metric = metric | 35 self._metric = metric |
35 self._test = test or 'summary' | 36 self._test = test or 'summary' |
36 self._isolate_hash = isolate_hash | 37 self._isolate_hashes = isolate_hashes |
37 | 38 |
38 def _Poll(self): | 39 def _Poll(self): |
39 test_output = isolate_service.Retrieve(self._isolate_hash) | 40 result_values = [] |
40 chartjson_isolate_hash = test_output['files']['chartjson-output.json']['h'] | 41 |
41 chartjson = json.loads(isolate_service.Retrieve(chartjson_isolate_hash)) | 42 for isolate_hash in self._isolate_hashes: |
42 chart = chartjson['charts'][self._metric][self._test] | 43 output = isolate_service.Retrieve(isolate_hash) |
43 if chart['type'] == 'list_of_scalar_values': | 44 chartjson_isolate_hash = output['files']['chartjson-output.json']['h'] |
44 result_values = tuple(chart['values']) | 45 chartjson = json.loads(isolate_service.Retrieve(chartjson_isolate_hash)) |
45 elif chart['type'] == 'histogram': | 46 chart = chartjson['charts'][self._metric][self._test] |
46 result_values = _ResultValuesFromHistogram(chart['buckets']) | 47 if chart['type'] == 'list_of_scalar_values': |
47 elif chart['type'] == 'scalar': | 48 result_values += chart['values'] |
48 result_values = (chart['value'],) | 49 elif chart['type'] == 'histogram': |
49 self._Complete(result_values=result_values) | 50 result_values += _ResultValuesFromHistogram(chart['buckets']) |
| 51 elif chart['type'] == 'scalar': |
| 52 result_values.append(chart['value']) |
| 53 |
| 54 self._Complete(result_values=tuple(result_values)) |
50 | 55 |
51 | 56 |
52 def _ResultValuesFromHistogram(buckets): | 57 def _ResultValuesFromHistogram(buckets): |
53 total_count = sum(bucket['count'] for bucket in buckets) | 58 total_count = sum(bucket['count'] for bucket in buckets) |
54 | 59 |
55 result_values = [] | 60 result_values = [] |
56 for bucket in buckets: | 61 for bucket in buckets: |
57 # TODO: Assumes the bucket is evenly distributed. | 62 # TODO: Assumes the bucket is evenly distributed. |
58 bucket_mean = (bucket['low'] + bucket.get('high', bucket['low'])) / 2 | 63 bucket_mean = (bucket['low'] + bucket.get('high', bucket['low'])) / 2 |
59 if total_count > 10000: | 64 if total_count > 10000: |
(...skipping 12 matching lines...) Expand all Loading... |
72 self._trace = trace | 77 self._trace = trace |
73 | 78 |
74 def __eq__(self, other): | 79 def __eq__(self, other): |
75 return (isinstance(other, type(self)) and | 80 return (isinstance(other, type(self)) and |
76 self._chart == other._chart and | 81 self._chart == other._chart and |
77 self._trace == other._trace) | 82 self._trace == other._trace) |
78 | 83 |
79 def __str__(self): | 84 def __str__(self): |
80 return 'Value' | 85 return 'Value' |
81 | 86 |
82 def Start(self, isolate_hash): | 87 def Start(self, isolate_hashes): |
83 return _ReadGraphJsonValueExecution(self._chart, self._trace, isolate_hash) | 88 return _ReadGraphJsonValueExecution(self._chart, self._trace, |
| 89 isolate_hashes) |
84 | 90 |
85 | 91 |
86 class _ReadGraphJsonValueExecution(execution.Execution): | 92 class _ReadGraphJsonValueExecution(execution.Execution): |
87 | 93 |
88 def __init__(self, chart, trace, isolate_hash): | 94 def __init__(self, chart, trace, isolate_hashes): |
89 super(_ReadGraphJsonValueExecution, self).__init__() | 95 super(_ReadGraphJsonValueExecution, self).__init__() |
90 self._chart = chart | 96 self._chart = chart |
91 self._trace = trace | 97 self._trace = trace |
92 self._isolate_hash = isolate_hash | 98 self._isolate_hashes = isolate_hashes |
93 | 99 |
94 def _Poll(self): | 100 def _Poll(self): |
95 test_output = isolate_service.Retrieve(self._isolate_hash) | 101 result_values = [] |
96 graphjson_isolate_hash = test_output['files']['chartjson-output.json']['h'] | 102 |
97 graphjson = json.loads(isolate_service.Retrieve(graphjson_isolate_hash)) | 103 for isolate_hash in self._isolate_hashes: |
98 result_values = (float(graphjson[self._chart]['traces'][self._trace][0]),) | 104 output = isolate_service.Retrieve(isolate_hash) |
99 self._Complete(result_values=result_values) | 105 graphjson_isolate_hash = output['files']['chartjson-output.json']['h'] |
| 106 graphjson = json.loads(isolate_service.Retrieve(graphjson_isolate_hash)) |
| 107 result_value = float(graphjson[self._chart]['traces'][self._trace][0]) |
| 108 result_values.append(result_value) |
| 109 |
| 110 self._Complete(result_values=tuple(result_values)) |
OLD | NEW |