Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / tools / perf / perf_tools / loading_benchmark.py
blobd0aa214183149796a5b2b8194f78180fdc54cdf7
1 # Copyright (c) 2012 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.
5 import collections
7 from telemetry.core import util
8 from telemetry.page import page_benchmark
10 class LoadingBenchmark(page_benchmark.PageBenchmark):
11 @property
12 def results_are_the_same_on_every_page(self):
13 return False
15 def WillNavigateToPage(self, page, tab):
16 tab.StartTimelineRecording()
18 def MeasurePage(self, page, tab, results):
19 # In current telemetry tests, all tests wait for DocumentComplete state,
20 # but we need to wait for the load event.
21 def IsLoaded():
22 return bool(tab.EvaluateJavaScript('performance.timing.loadEventStart'))
23 util.WaitFor(IsLoaded, 30)
25 # TODO(nduca): when crbug.com/168431 is fixed, modify the page sets to
26 # recognize loading as a toplevel action.
27 tab.StopTimelineRecording()
29 load_timings = tab.EvaluateJavaScript('window.performance.timing')
30 load_time_ms = (
31 float(load_timings['loadEventStart']) -
32 load_timings['navigationStart'])
33 dom_content_loaded_time_ms = (
34 float(load_timings['domContentLoadedEventStart']) -
35 load_timings['navigationStart'])
36 results.Add('load_time', 'ms', load_time_ms)
37 results.Add('dom_content_loaded_time', 'ms',
38 dom_content_loaded_time_ms)
40 events = tab.timeline_model.GetAllEvents()
42 events_by_name = collections.defaultdict(list)
43 for e in events:
44 events_by_name[e.name].append(e)
46 for key, group in events_by_name.items():
47 times = [e.self_time_ms for e in group]
48 total = sum(times)
49 biggest_jank = max(times)
50 results.Add(key, 'ms', total)
51 results.Add(key + '_max', 'ms', biggest_jank)
52 results.Add(key + '_avg', 'ms', total / len(times))