| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """URL endpoint to add new histograms to the datastore.""" | 5 """URL endpoint to add new histograms to the datastore.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 # TODO(eakuefner): Move these helpers so we don't have to import add_point or | 10 # TODO(eakuefner): Move these helpers so we don't have to import add_point or |
| 11 # add_point_queue directly. | 11 # add_point_queue directly. |
| 12 from dashboard import add_histograms | 12 from dashboard import add_histograms |
| 13 from dashboard import add_point | 13 from dashboard import add_point |
| 14 from dashboard import add_point_queue | 14 from dashboard import add_point_queue |
| 15 from dashboard.common import datastore_hooks | 15 from dashboard.common import datastore_hooks |
| 16 from dashboard.common import request_handler | 16 from dashboard.common import request_handler |
| 17 from dashboard.common import stored_object | 17 from dashboard.common import stored_object |
| 18 from dashboard.common import utils | 18 from dashboard.common import utils |
| 19 from dashboard.models import anomaly | 19 from dashboard.models import anomaly |
| 20 from dashboard.models import graph_data | 20 from dashboard.models import graph_data |
| 21 from dashboard.models import histogram | 21 from dashboard.models import histogram |
| 22 from tracing.value import histogram as histogram_module | 22 from tracing.value import histogram as histogram_module |
| 23 from tracing.value import histogram_set | 23 from tracing.value import histogram_set |
| 24 from tracing.value.diagnostics import diagnostic_ref | 24 from tracing.value.diagnostics import diagnostic_ref |
| 25 from tracing.value.diagnostics import reserved_infos |
| 25 | 26 |
| 26 | 27 DIAGNOSTIC_NAMES_TO_ANNOTATION_NAMES = { |
| 27 REVISION_FIELDS_TO_ANNOTATION_NAMES = { | 28 reserved_infos.CHROMIUM_COMMIT_POSITIONS.name: 'r_chromium_commit_pos', |
| 28 'chromium_commit_position': 'r_chromium_commit_pos', | 29 reserved_infos.V8_COMMIT_POSITIONS.name: 'r_v8_rev', |
| 29 'v8_commit_position': 'r_v8_rev', | 30 reserved_infos.CHROMIUM_REVISIONS.name: 'r_chromium_git', |
| 30 'chromium': 'r_chromium_git', | 31 reserved_infos.V8_REVISIONS.name: 'r_v8_git', |
| 31 'v8': 'r_v8_git', | |
| 32 # TODO(eakuefner): Add r_catapult_git to Dashboard revision_info map (see | 32 # TODO(eakuefner): Add r_catapult_git to Dashboard revision_info map (see |
| 33 # https://github.com/catapult-project/catapult/issues/3545). | 33 # https://github.com/catapult-project/catapult/issues/3545). |
| 34 'catapult': 'r_catapult_git', | 34 reserved_infos.CATAPULT_REVISIONS.name: 'r_catapult_git', |
| 35 'angle': 'r_angle_git', | 35 reserved_infos.ANGLE_REVISIONS.name: 'r_angle_git', |
| 36 'webrtc': 'r_webrtc_git' | 36 reserved_infos.WEBRTC_REVISIONS.name: 'r_webrtc_git' |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 class BadRequestError(Exception): | 40 class BadRequestError(Exception): |
| 41 pass | 41 pass |
| 42 | 42 |
| 43 | 43 |
| 44 def _CheckRequest(condition, msg): | 44 def _CheckRequest(condition, msg): |
| 45 if not condition: | 45 if not condition: |
| 46 raise BadRequestError(msg) | 46 raise BadRequestError(msg) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 def _MakeRowDict(revision, test_path, tracing_histogram): | 163 def _MakeRowDict(revision, test_path, tracing_histogram): |
| 164 d = {} | 164 d = {} |
| 165 # TODO(#3563): Wire up a_tracing_uri. | 165 # TODO(#3563): Wire up a_tracing_uri. |
| 166 test_parts = test_path.split('/') | 166 test_parts = test_path.split('/') |
| 167 d['master'] = test_parts[0] | 167 d['master'] = test_parts[0] |
| 168 d['bot'] = test_parts[1] | 168 d['bot'] = test_parts[1] |
| 169 d['test'] = '/'.join(test_parts[2:]) | 169 d['test'] = '/'.join(test_parts[2:]) |
| 170 d['revision'] = revision | 170 d['revision'] = revision |
| 171 d['supplemental_columns'] = {} | 171 d['supplemental_columns'] = {} |
| 172 | 172 |
| 173 revision_info = tracing_histogram.diagnostics['revisions'] | 173 for diag_name, annotation in DIAGNOSTIC_NAMES_TO_ANNOTATION_NAMES.iteritems(): |
| 174 for attribute, annotation in REVISION_FIELDS_TO_ANNOTATION_NAMES.iteritems(): | 174 revision_info = tracing_histogram.diagnostics.get(diag_name) |
| 175 value = getattr(revision_info, attribute) | 175 value = list(revision_info) if revision_info else None |
| 176 # TODO(eakuefner): Formalize unique-per-upload diagnostics to make this | 176 # TODO(eakuefner): Formalize unique-per-upload diagnostics to make this |
| 177 # check an earlier error. RevisionInfo's fields have to be lists, but there | 177 # check an earlier error. RevisionInfo's fields have to be lists, but there |
| 178 # should be only one revision of each type per upload. | 178 # should be only one revision of each type per upload. |
| 179 if not value: | 179 if not value: |
| 180 continue | 180 continue |
| 181 _CheckRequest( | 181 _CheckRequest( |
| 182 isinstance(value, list) and len(value) == 1, | 182 len(value) == 1, |
| 183 'RevisionInfo fields must contain at most one revision') | 183 'RevisionInfo fields must contain at most one revision') |
| 184 | 184 |
| 185 d['supplemental_columns'][annotation] = value[0] | 185 d['supplemental_columns'][annotation] = value[0] |
| 186 | 186 |
| 187 _PopulateNumericalFields(d, tracing_histogram) | 187 _PopulateNumericalFields(d, tracing_histogram) |
| 188 return d | 188 return d |
| 189 | 189 |
| 190 def _PopulateNumericalFields(row_dict, tracing_histogram): | 190 def _PopulateNumericalFields(row_dict, tracing_histogram): |
| 191 statistics_scalars = tracing_histogram.statistics_scalars | 191 statistics_scalars = tracing_histogram.statistics_scalars |
| 192 for name, scalar in statistics_scalars.iteritems(): | 192 for name, scalar in statistics_scalars.iteritems(): |
| 193 # We'll skip avg/std since these are already stored as value/error in rows. | 193 # We'll skip avg/std since these are already stored as value/error in rows. |
| 194 if name in ('avg', 'std'): | 194 if name in ('avg', 'std'): |
| 195 continue | 195 continue |
| 196 | 196 |
| 197 row_dict['supplemental_columns']['d_%s' % name] = scalar.value | 197 row_dict['supplemental_columns']['d_%s' % name] = scalar.value |
| 198 | 198 |
| 199 row_dict['value'] = tracing_histogram.average | 199 row_dict['value'] = tracing_histogram.average |
| 200 row_dict['error'] = tracing_histogram.standard_deviation | 200 row_dict['error'] = tracing_histogram.standard_deviation |
| OLD | NEW |