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

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

Issue 99903009: Allowing V8ObjectStatsMetric users to specify metrics to capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 | « no previous file | 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 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 logging 6 import logging
7 7
8 from metrics import Metric 8 from metrics import Metric
9 9
10 _COUNTER_NAMES = [ 10 _COUNTER_NAMES = [
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 'V8.SizeOf_TYPE_SWITCH_INFO_TYPE' 155 'V8.SizeOf_TYPE_SWITCH_INFO_TYPE'
156 ] 156 ]
157 157
158 class V8ObjectStatsMetric(Metric): 158 class V8ObjectStatsMetric(Metric):
159 """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap. 159 """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap.
160 160
161 It does this by enabling the --track_gc_object_stats flag on V8 and reading 161 It does this by enabling the --track_gc_object_stats flag on V8 and reading
162 these statistics from the StatsTableMetric. 162 these statistics from the StatsTableMetric.
163 """ 163 """
164 164
165 def __init__(self): 165 def __init__(self, counters=None):
166 super(V8ObjectStatsMetric, self).__init__() 166 super(V8ObjectStatsMetric, self).__init__()
167 self._results = None 167 self._results = None
168 self._counters = counters or _COUNTER_NAMES
168 169
169 @classmethod 170 @classmethod
170 def CustomizeBrowserOptions(cls, options): 171 def CustomizeBrowserOptions(cls, options):
171 options.AppendExtraBrowserArgs([ 172 options.AppendExtraBrowserArgs([
172 '--enable-stats-table', 173 '--enable-stats-table',
173 '--enable-benchmarking', 174 '--enable-benchmarking',
174 '--js-flags=--track_gc_object_stats --expose_gc', 175 '--js-flags=--track_gc_object_stats --expose_gc',
175 # TODO(rmcilroy): This is needed for --enable-stats-table. Update once 176 # TODO(rmcilroy): This is needed for --enable-stats-table. Update once
176 # https://codereview.chromium.org/22911027/ lands. 177 # https://codereview.chromium.org/22911027/ lands.
177 '--no-sandbox' 178 '--no-sandbox'
178 ]) 179 ])
179 180
180 @staticmethod 181 @staticmethod
181 def GetV8StatsTable(tab, counters=None): 182 def GetV8StatsTable(tab, counters=None):
182 counters = counters or _COUNTER_NAMES 183 counters = counters or _COUNTER_NAMES
rmcilroy 2014/01/03 09:58:28 nit - drop the default argument, and "counters = c
183 184
184 return tab.EvaluateJavaScript(""" 185 return tab.EvaluateJavaScript("""
185 (function(counters) { 186 (function(counters) {
186 var results = {}; 187 var results = {};
187 if (!window.chrome || !window.chrome.benchmarking) 188 if (!window.chrome || !window.chrome.benchmarking)
188 return results; 189 return results;
189 try { 190 try {
190 window.gc(); // Trigger GC to ensure stats are checkpointed. 191 window.gc(); // Trigger GC to ensure stats are checkpointed.
191 } catch(e) { 192 } catch(e) {
192 // window.gc() could have been mapped to something else, just continue. 193 // window.gc() could have been mapped to something else, just continue.
193 } 194 }
194 for (var i = 0; i < counters.length; i++) 195 for (var i = 0; i < counters.length; i++)
195 results[counters[i]] = 196 results[counters[i]] =
196 chrome.benchmarking.counterForRenderer(counters[i]); 197 chrome.benchmarking.counterForRenderer(counters[i]);
197 return results; 198 return results;
198 })(%s); 199 })(%s);
199 """ % json.dumps(counters)) 200 """ % json.dumps(counters))
200 201
201 def Start(self, page, tab): 202 def Start(self, page, tab):
202 """Do Nothing.""" 203 """Do Nothing."""
203 pass 204 pass
204 205
205 def Stop(self, page, tab): 206 def Stop(self, page, tab):
206 """Get the values in the stats table after the page is loaded.""" 207 """Get the values in the stats table after the page is loaded."""
207 self._results = V8ObjectStatsMetric.GetV8StatsTable(tab) 208 self._results = V8ObjectStatsMetric.GetV8StatsTable(tab, self._counters)
208 if not self._results: 209 if not self._results:
209 logging.warning('No V8 object stats from website: ' + page.display_name) 210 logging.warning('No V8 object stats from website: ' + page.display_name)
210 211
211 def AddResults(self, tab, results): 212 def AddResults(self, tab, results):
212 """Add results for this page to the results object.""" 213 """Add results for this page to the results object."""
213 assert self._results != None, 'Must call Stop() first' 214 assert self._results != None, 'Must call Stop() first'
214 for counter_name in self._results: 215 for counter_name in self._results:
215 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0) 216 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698