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

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

Issue 2719853003: [Telemetry refactor] Drop "2" from method calls to JS API (Closed)
Patch Set: Created 3 years, 9 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/perf/metrics/media.py ('k') | tools/perf/metrics/webrtc_stats.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 collections 5 import collections
6 import json 6 import json
7 import logging 7 import logging
8 8
9 from telemetry.core import exceptions 9 from telemetry.core import exceptions
10 from telemetry.value import histogram_util 10 from telemetry.value import histogram_util
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return (int(high_bytes) << 32) | (int(low_bytes) << 1) 50 return (int(high_bytes) << 32) | (int(low_bytes) << 1)
51 51
52 def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): 52 def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results):
53 """Records the tab load times for the browser. """ 53 """Records the tab load times for the browser. """
54 TabLoadTime = collections.namedtuple( 54 TabLoadTime = collections.namedtuple(
55 'TabLoadTime', 55 'TabLoadTime',
56 ['request_start_ms', 'load_end_ms']) 56 ['request_start_ms', 'load_end_ms'])
57 57
58 def RecordOneTab(t): 58 def RecordOneTab(t):
59 def EvaluateInt(exp): 59 def EvaluateInt(exp):
60 val = t.EvaluateJavaScript2(exp) 60 val = t.EvaluateJavaScript(exp)
61 if not val: 61 if not val:
62 logging.warn('%s undefined', exp) 62 logging.warn('%s undefined', exp)
63 return 0 63 return 0
64 return int(val) 64 return int(val)
65 65
66 try: 66 try:
67 t.WaitForJavaScriptCondition2( 67 t.WaitForJavaScriptCondition(
68 'window.performance.timing["loadEventEnd"] > 0', 68 'window.performance.timing["loadEventEnd"] > 0',
69 timeout=self.DEFAULT_LOADING_TIMEOUT) 69 timeout=self.DEFAULT_LOADING_TIMEOUT)
70 70
71 # EvaluateJavaScript(window.performance.timing) doesn't guarantee to 71 # EvaluateJavaScript(window.performance.timing) doesn't guarantee to
72 # return the desired javascript object (crbug/472603). It may return an 72 # return the desired javascript object (crbug/472603). It may return an
73 # empty object. However getting individual field works. 73 # empty object. However getting individual field works.
74 # The behavior depends on WebKit implementation on different platforms. 74 # The behavior depends on WebKit implementation on different platforms.
75 load_event_end = EvaluateInt( 75 load_event_end = EvaluateInt(
76 'window.performance.timing["loadEventEnd"]') 76 'window.performance.timing["loadEventEnd"]')
77 request_start = EvaluateInt( 77 request_start = EvaluateInt(
(...skipping 20 matching lines...) Expand all
98 results.AddValue(scalar.ScalarValue( 98 results.AddValue(scalar.ScalarValue(
99 results.current_page, 'foreground_tab_load_complete', 'ms', 99 results.current_page, 'foreground_tab_load_complete', 'ms',
100 foreground_tab_load_complete)) 100 foreground_tab_load_complete))
101 if foreground_tab_stats.request_start_ms > 0: 101 if foreground_tab_stats.request_start_ms > 0:
102 results.AddValue(scalar.ScalarValue( 102 results.AddValue(scalar.ScalarValue(
103 results.current_page, 'foreground_tab_request_start', 'ms', 103 results.current_page, 'foreground_tab_request_start', 'ms',
104 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) 104 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms))
105 105
106 def AddResults(self, tab, results): 106 def AddResults(self, tab, results):
107 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): 107 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems():
108 result = tab.EvaluateJavaScript2( 108 result = tab.EvaluateJavaScript(
109 'statsCollectionController.getBrowserHistogram({{ name }})', 109 'statsCollectionController.getBrowserHistogram({{ name }})',
110 name=histogram_name) 110 name=histogram_name)
111 result = json.loads(result) 111 result = json.loads(result)
112 measured_time = 0 112 measured_time = 0
113 113
114 if 'sum' in result: 114 if 'sum' in result:
115 # For all the histograms logged here, there's a single entry so sum 115 # For all the histograms logged here, there's a single entry so sum
116 # is the exact value for that entry. 116 # is the exact value for that entry.
117 measured_time = result['sum'] 117 measured_time = result['sum']
118 elif 'buckets' in result: 118 elif 'buckets' in result:
119 measured_time = (result['buckets'][0]['high'] + 119 measured_time = (result['buckets'][0]['high'] +
120 result['buckets'][0]['low']) / 2 120 result['buckets'][0]['low']) / 2
121 121
122 results.AddValue(scalar.ScalarValue( 122 results.AddValue(scalar.ScalarValue(
123 results.current_page, display_name, 'ms', measured_time)) 123 results.current_page, display_name, 'ms', measured_time))
124 124
125 # Get tab load times. 125 # Get tab load times.
126 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) 126 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab)
127 if browser_main_entry_time_ms is None: 127 if browser_main_entry_time_ms is None:
128 print 'Outdated Chrome version, browser main entry time not supported.' 128 print 'Outdated Chrome version, browser main entry time not supported.'
129 return 129 return
130 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) 130 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results)
OLDNEW
« no previous file with comments | « tools/perf/metrics/media.py ('k') | tools/perf/metrics/webrtc_stats.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698