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

Side by Side Diff: tools/perf/benchmarks/dom_perf.py

Issue 714273004: mac: Expose keychain access frequency to Telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mock_keychain_sleep
Patch Set: Add a common subclass to measurements. Created 6 years, 1 month 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 import math 6 import math
7 import os 7 import os
8 8
9 from measurements import PageTestMeasurement
9 from telemetry import benchmark 10 from telemetry import benchmark
10 from telemetry.core import util 11 from telemetry.core import util
11 from telemetry.page import page_set 12 from telemetry.page import page_set
12 from telemetry.page import page_test
13 from telemetry.value import merge_values 13 from telemetry.value import merge_values
14 from telemetry.value import scalar 14 from telemetry.value import scalar
15 15
16 16
17 def _GeometricMean(values): 17 def _GeometricMean(values):
18 """Compute a rounded geometric mean from an array of values.""" 18 """Compute a rounded geometric mean from an array of values."""
19 if not values: 19 if not values:
20 return None 20 return None
21 # To avoid infinite value errors, make sure no value is less than 0.001. 21 # To avoid infinite value errors, make sure no value is less than 0.001.
22 new_values = [] 22 new_values = []
23 for value in values: 23 for value in values:
24 if value > 0.001: 24 if value > 0.001:
25 new_values.append(value) 25 new_values.append(value)
26 else: 26 else:
27 new_values.append(0.001) 27 new_values.append(0.001)
28 # Compute the sum of the log of the values. 28 # Compute the sum of the log of the values.
29 log_sum = sum(map(math.log, new_values)) 29 log_sum = sum(map(math.log, new_values))
30 # Raise e to that sum over the number of values. 30 # Raise e to that sum over the number of values.
31 mean = math.pow(math.e, (log_sum / len(new_values))) 31 mean = math.pow(math.e, (log_sum / len(new_values)))
32 # Return the rounded mean. 32 # Return the rounded mean.
33 return int(round(mean)) 33 return int(round(mean))
34 34
35 35
36 SCORE_UNIT = 'score (bigger is better)' 36 SCORE_UNIT = 'score (bigger is better)'
37 SCORE_TRACE_NAME = 'score' 37 SCORE_TRACE_NAME = 'score'
38 38
39 39
40 class _DomPerfMeasurement(page_test.PageTest): 40 class _DomPerfMeasurement(PageTestMeasurement):
41 def ValidateAndMeasurePage(self, page, tab, results): 41 def ValidateAndMeasurePage(self, page, tab, results):
42 try: 42 try:
43 def _IsDone(): 43 def _IsDone():
44 return tab.GetCookieByName('__domperf_finished') == '1' 44 return tab.GetCookieByName('__domperf_finished') == '1'
45 util.WaitFor(_IsDone, 600) 45 util.WaitFor(_IsDone, 600)
46 46
47 data = json.loads(tab.EvaluateJavaScript('__domperf_result')) 47 data = json.loads(tab.EvaluateJavaScript('__domperf_result'))
48 for suite in data['BenchmarkSuites']: 48 for suite in data['BenchmarkSuites']:
49 # Skip benchmarks that we didn't actually run this time around. 49 # Skip benchmarks that we didn't actually run this time around.
50 if len(suite['Benchmarks']) or suite['score']: 50 if len(suite['Benchmarks']) or suite['score']:
51 results.AddValue(scalar.ScalarValue( 51 results.AddValue(scalar.ScalarValue(
52 results.current_page, '%s.%s' % (suite['name'], SCORE_TRACE_NAME), 52 results.current_page, '%s.%s' % (suite['name'], SCORE_TRACE_NAME),
53 SCORE_UNIT, suite['score'], important=False)) 53 SCORE_UNIT, suite['score'], important=False))
54
54 finally: 55 finally:
55 tab.EvaluateJavaScript('document.cookie = "__domperf_finished=0"') 56 tab.EvaluateJavaScript('document.cookie = "__domperf_finished=0"')
57 super(_DomPerfMeasurement, self).ValidateAndMeasurePage(
58 page, tab, results)
56 59
57 def DidRunTest(self, browser, results): 60 def DidRunTest(self, browser, results):
58 # Now give the geometric mean as the total for the combined runs. 61 # Now give the geometric mean as the total for the combined runs.
59 combined = merge_values.MergeLikeValuesFromDifferentPages( 62 combined = merge_values.MergeLikeValuesFromDifferentPages(
60 results.all_page_specific_values, 63 results.all_page_specific_values,
61 group_by_name_suffix=True) 64 group_by_name_suffix=True)
62 combined_score = [x for x in combined if x.name == SCORE_TRACE_NAME][0] 65 combined_score = [x for x in combined if x.name == SCORE_TRACE_NAME][0]
63 total = _GeometricMean(combined_score.values) 66 total = _GeometricMean(combined_score.values)
64 results.AddSummaryValue( 67 results.AddSummaryValue(
65 scalar.ScalarValue(None, 'Total.' + SCORE_TRACE_NAME, SCORE_UNIT, 68 scalar.ScalarValue(None, 'Total.' + SCORE_TRACE_NAME, SCORE_UNIT,
(...skipping 21 matching lines...) Expand all
87 'Events', 90 'Events',
88 'Get+Elements', 91 'Get+Elements',
89 'GridSort', 92 'GridSort',
90 'Template' 93 'Template'
91 ] 94 ]
92 ps = page_set.PageSet(file_path=dom_perf_dir) 95 ps = page_set.PageSet(file_path=dom_perf_dir)
93 for param in run_params: 96 for param in run_params:
94 ps.AddPageWithDefaultRunNavigate( 97 ps.AddPageWithDefaultRunNavigate(
95 'file://run.html?reportInJS=1&run=%s' % param) 98 'file://run.html?reportInJS=1&run=%s' % param)
96 return ps 99 return ps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698