OLD | NEW |
(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 if start_parsed: |
| 73 start_page_visits = sum(b['count'] for b in start_parsed['buckets'] |
| 74 if b['low'] == UseCounterMetric.PAGE_VISITS_BUCKET) |
| 75 else: |
| 76 start_page_visits = 0 |
| 77 end_page_visits = sum(b['count'] for b in end_parsed['buckets'] |
| 78 if b['low'] == UseCounterMetric.PAGE_VISITS_BUCKET) |
| 79 |
| 80 if (not start_parsed or |
| 81 start_parsed['pid'] != end_parsed['pid'] or |
| 82 start_parsed['sum'] > end_parsed['sum'] or |
| 83 start_page_visits > end_page_visits): |
| 84 # Just use the raw ending histogram |
| 85 histogram_delta = histogram |
| 86 else: |
| 87 # Use the difference between the start and end histograms |
| 88 histogram_delta = histogram_util.SubtractHistogram(histogram, |
| 89 self._histogram_start) |
| 90 |
| 91 buckets = histogram_util.GetHistogramBucketsFromJson(histogram_delta) |
| 92 |
| 93 if UseCounterMetric.LIMITED_BUCKETS_MODE: |
| 94 for bucketValue in UseCounterMetric.BUCKET_VALUES: |
| 95 useCount = sum(bucket['count'] for bucket in buckets |
| 96 if bucket['low'] == bucketValue) |
| 97 results.AddValue(scalar.ScalarValue(results.current_page, |
| 98 'Feature' + str(bucketValue), 'count', useCount)) |
| 99 |
| 100 else: |
| 101 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| 102 results.current_page, 'features', 'list-of-ids', |
| 103 [b['low'] for b in buckets])) |
| 104 |
OLD | NEW |