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

Side by Side Diff: tools/perf/metrics/usecounter.py

Issue 2572003003: NOT FOR SUBMIT: use counters for jdm@
Patch Set: Merge branch 'jdm-usecounters' into jdm-merge Created 4 years 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/perf/measurements/usecounter.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
(Empty)
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
3 # found in the LICENSE file.
4
5 import json
6
7 from telemetry.value import histogram_util
8 from telemetry.value import list_of_scalar_values
9 from telemetry.value import scalar
10
11 from metrics import Metric
12
13 class UseCounterMetric(Metric):
14 """UseCounterMetric trackers whether specific blink UseCounters were hit
15 """
16
17 HISTOGRAM_NAME = 'WebCore.UseCounter_TEST.Features'
18
19 PAGE_VISITS_BUCKET = 52
20
21 LIMITED_BUCKETS_MODE = False
22
23 # If the above is true, then use only the features specified here.
24 # Telemetry doesn't appear to have any way of passing options into
25 # a benchmark from the command line.
26 BUCKET_VALUES = [
27 0, # PageDestruction
28 52, # PageVisits
29 343, # EventSrcElement
30 677, # XMLHttpRequestAsynchronous (a popular JS metric as a control)
31 1075, # V8SloppyMode
32 1076, # V8StrictMode
33 1077, # V8StrongMode
34 # 967, # AddEventListenerThirdArgumentIsObject
35 # 968, # RemoveEventListenerThirdArgumentIsObject
36 # 1279, # AddEventListenerFourArguments
37 # 1280, # RemoveEventListenerFourArguments
38 575, # WindowPostMessageWithLegacyTargetOriginArgument
39 ]
40
41 @classmethod
42 def CustomizeBrowserOptions(cls, options):
43 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
44
45 def __init__(self):
46 super(UseCounterMetric, self).__init__()
47 self._histogram_start = ""
48
49 def Start(self, page, tab):
50 self._histogram_start = histogram_util.GetHistogram(
51 histogram_util.RENDERER_HISTOGRAM,
52 UseCounterMetric.HISTOGRAM_NAME,
53 tab)
54
55 def AddResults(self, tab, results):
56 """Adds the number of times the specified metrics were hit
57 Should be 0 or 1 if UseCounter and the user story are functioning correctly.
58 """
59
60 histogram = histogram_util.GetHistogram(
61 histogram_util.RENDERER_HISTOGRAM,
62 UseCounterMetric.HISTOGRAM_NAME,
63 tab)
64
65 # Determine if the renderer has been restarted as a result of the
66 # navigation. Normally checking the 'pid' should be sufficient, but the fix
67 # for crbug.com/666912 may not be in the build under test, and besides it
68 # may be possible (if unlikely) for a unique process ID to get recycled.
69 # So also check for a decrease in the histogram.
70 start_parsed = json.loads(self._histogram_start)
71 end_parsed = json.loads(histogram)
72 start_page_visits = sum(b['count'] for b in start_parsed['buckets']
73 if b['low'] == UseCounterMetric.PAGE_VISITS_BUCKET)
74 end_page_visits = sum(b['count'] for b in end_parsed['buckets']
75 if b['low'] == UseCounterMetric.PAGE_VISITS_BUCKET)
76
77 if (start_parsed['pid'] != end_parsed['pid'] or
78 start_parsed['sum'] > end_parsed['sum'] or
79 start_page_visits > end_page_visits):
80 # Just use the raw ending histogram
81 histogram_delta = histogram
82 else:
83 # Use the difference between the start and end histograms
84 histogram_delta = histogram_util.SubtractHistogram(histogram,
85 self._histogram_start)
86
87 buckets = histogram_util.GetHistogramBucketsFromJson(histogram_delta)
88
89 if UseCounterMetric.LIMITED_BUCKETS_MODE:
90 for bucketValue in UseCounterMetric.BUCKET_VALUES:
91 useCount = sum(bucket['count'] for bucket in buckets
92 if bucket['low'] == bucketValue)
93 results.AddValue(scalar.ScalarValue(results.current_page,
94 'Feature' + str(bucketValue), 'count', useCount))
95
96 else:
97 results.AddValue(list_of_scalar_values.ListOfScalarValues(
98 results.current_page, 'features', 'list-of-ids',
99 [b['low'] for b in buckets]))
100
OLDNEW
« no previous file with comments | « tools/perf/measurements/usecounter.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698