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
3 # found in the LICENSE file.
6 from metrics import Metric
9 class StartupMetric(Metric):
10 "A metric for browser startup time."
12 HISTOGRAMS_TO_RECORD = {
13 'messageloop_start_time' :
14 'Startup.BrowserMessageLoopStartTimeFromMainEntry',
15 'window_display_time' : 'Startup.BrowserWindowDisplay',
16 'open_tabs_time' : 'Startup.BrowserOpenTabs'}
18 def Start(self, page, tab):
19 raise NotImplementedError()
21 def Stop(self, page, tab):
22 raise NotImplementedError()
24 def AddResults(self, tab, results):
25 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")'
27 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems():
28 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name)
29 result = json.loads(result)
33 # For all the histograms logged here, there's a single entry so sum
34 # is the exact value for that entry.
35 measured_time = result['sum']
36 elif 'buckets' in result:
38 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2
40 results.Add(display_name, 'ms', measured_time)