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

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

Issue 1244223002: Create classes_util API, change discover to return a list instead of a dict. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 4 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
« no previous file with comments | « tools/telemetry/telemetry/util/classes_util.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 The Value hierarchy provides a way of representing the values measurements 5 The Value hierarchy provides a way of representing the values measurements
6 produce such that they can be merged across runs, grouped by page, and output 6 produce such that they can be merged across runs, grouped by page, and output
7 to different targets. 7 to different targets.
8 8
9 The core Value concept provides the basic functionality: 9 The core Value concept provides the basic functionality:
10 - association with a page, may be none 10 - association with a page, may be none
11 - naming and units 11 - naming and units
12 - importance tracking [whether a value will show up on a waterfall or output 12 - importance tracking [whether a value will show up on a waterfall or output
13 file by default] 13 file by default]
14 - other metadata, such as a description of what was measured 14 - other metadata, such as a description of what was measured
15 - default conversion to scalar and string 15 - default conversion to scalar and string
16 - merging properties 16 - merging properties
17 17
18 A page may actually run a few times during a single telemetry session. 18 A page may actually run a few times during a single telemetry session.
19 Downstream consumers of test results typically want to group these runs 19 Downstream consumers of test results typically want to group these runs
20 together, then compute summary statistics across runs. Value provides the 20 together, then compute summary statistics across runs. Value provides the
21 Merge* family of methods for this kind of aggregation. 21 Merge* family of methods for this kind of aggregation.
22 """ 22 """
23 import os 23 import os
24 24
25 from telemetry.core import discover
26 from telemetry.core import util 25 from telemetry.core import util
26 from telemetry.util import classes_util
27
27 28
28 # When combining a pair of Values togehter, it is sometimes ambiguous whether 29 # When combining a pair of Values togehter, it is sometimes ambiguous whether
29 # the values should be concatenated, or one should be picked as representative. 30 # the values should be concatenated, or one should be picked as representative.
30 # The possible merging policies are listed here. 31 # The possible merging policies are listed here.
31 CONCATENATE = 'concatenate' 32 CONCATENATE = 'concatenate'
32 PICK_FIRST = 'pick-first' 33 PICK_FIRST = 'pick-first'
33 34
34 # When converting a Value to its buildbot equivalent, the context in which the 35 # When converting a Value to its buildbot equivalent, the context in which the
35 # value is being interpreted actually affects the conversion. This is insane, 36 # value is being interpreted actually affects the conversion. This is insane,
36 # but there you have it. There are three contexts in which Values are converted 37 # but there you have it. There are three contexts in which Values are converted
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 Given a list of value dicts produced by AsDict, this method 243 Given a list of value dicts produced by AsDict, this method
243 deserializes the dicts given a dict mapping page IDs to pages. 244 deserializes the dicts given a dict mapping page IDs to pages.
244 This method performs memoization for deserializing a list of values 245 This method performs memoization for deserializing a list of values
245 efficiently, where FromDict is meant to handle one-offs. 246 efficiently, where FromDict is meant to handle one-offs.
246 247
247 values: a list of value dicts produced by AsDict() on a value subclass. 248 values: a list of value dicts produced by AsDict() on a value subclass.
248 page_dict: a dictionary mapping IDs to page objects. 249 page_dict: a dictionary mapping IDs to page objects.
249 """ 250 """
250 value_dir = os.path.dirname(__file__) 251 value_dir = os.path.dirname(__file__)
251 value_classes = discover.DiscoverClasses( 252 value_classes = classes_util.DiscoverClassesByClassName(
252 value_dir, util.GetTelemetryDir(), 253 value_dir, util.GetTelemetryDir(), Value)
253 Value, index_by_class_name=True)
254 254
255 value_json_types = dict((value_classes[x].GetJSONTypeName(), x) for x in 255 value_json_types = dict((value_classes[x].GetJSONTypeName(), x) for x in
256 value_classes) 256 value_classes)
257 257
258 values = [] 258 values = []
259 for value_dict in value_dicts: 259 for value_dict in value_dicts:
260 value_class = value_classes[value_json_types[value_dict['type']]] 260 value_class = value_classes[value_json_types[value_dict['type']]]
261 assert 'FromDict' in value_class.__dict__, \ 261 assert 'FromDict' in value_class.__dict__, \
262 'Subclass doesn\'t override FromDict' 262 'Subclass doesn\'t override FromDict'
263 values.append(value_class.FromDict(value_dict, page_dict)) 263 values.append(value_class.FromDict(value_dict, page_dict))
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 whereas telemetry represents values with a chart_name.trace_name convention, 327 whereas telemetry represents values with a chart_name.trace_name convention,
328 where chart_name is optional. This convention is also used by chart_json. 328 where chart_name is optional. This convention is also used by chart_json.
329 329
330 This converts from the telemetry convention to the buildbot convention, 330 This converts from the telemetry convention to the buildbot convention,
331 returning a 2-tuple (measurement_name, trace_name). 331 returning a 2-tuple (measurement_name, trace_name).
332 """ 332 """
333 if '.' in value_name: 333 if '.' in value_name:
334 return value_name.split('.', 1) 334 return value_name.split('.', 1)
335 else: 335 else:
336 return value_name, value_name 336 return value_name, value_name
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/util/classes_util.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698