- add sources.
[platform/framework/web/crosswalk.git] / src / tools / perf / metrics / startup_metric.py
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.
4 import json
5
6 from metrics import Metric
7
8
9 class StartupMetric(Metric):
10   "A metric for browser startup time."
11
12   HISTOGRAMS_TO_RECORD = {
13     'messageloop_start_time' :
14         'Startup.BrowserMessageLoopStartTimeFromMainEntry',
15     'window_display_time' : 'Startup.BrowserWindowDisplay',
16     'open_tabs_time' : 'Startup.BrowserOpenTabs'}
17
18   def Start(self, page, tab):
19     raise NotImplementedError()
20
21   def Stop(self, page, tab):
22     raise NotImplementedError()
23
24   def AddResults(self, tab, results):
25     get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")'
26
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)
30       measured_time = 0
31
32       if 'sum' in 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:
37         measured_time = \
38             (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2
39
40       results.Add(display_name, 'ms', measured_time)