summaryrefslogtreecommitdiffstats
path: root/tools/perf/measurements/loading_trace.py
blob: 16d930027ecb25be1e2c31cc66c191b3e00b77bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from metrics import loading
from metrics import timeline
from telemetry.core import util
from telemetry.page import page_measurement

class LoadingTrace(page_measurement.PageMeasurement):
  def __init__(self, *args, **kwargs):
    super(LoadingTrace, self).__init__(*args, **kwargs)
    self._timeline_metric = timeline.TimelineMetric(timeline.TRACING_MODE)

  @property
  def results_are_the_same_on_every_page(self):
    return False

  def WillNavigateToPage(self, page, tab):
    self._timeline_metric.Start(page, tab)

  def MeasurePage(self, page, tab, results):
    # In current telemetry tests, all tests wait for DocumentComplete state,
    # but we need to wait for the load event.
    def IsLoaded():
      return bool(tab.EvaluateJavaScript('performance.timing.loadEventStart'))
    util.WaitFor(IsLoaded, 300)

    # TODO(nduca): when crbug.com/168431 is fixed, modify the page sets to
    # recognize loading as a toplevel action.
    self._timeline_metric.Stop(page, tab)

    loading.LoadingMetric().AddResults(tab, results)
    self._timeline_metric.AddResults(tab, results)