Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / tools / perf / measurements / power.py
blobef03596aae741631fa9949b5ae9824a8ccfe927b
1 # Copyright 2014 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 time
7 from metrics import network
8 from metrics import power
9 from telemetry.core import util
10 from telemetry.page import page_test
13 class Power(page_test.PageTest):
14 """Measures power draw and idle wakeups during the page's interactions."""
16 def __init__(self):
17 super(Power, self).__init__()
18 self._power_metric = None
19 self._network_metric = None
21 def WillStartBrowser(self, platform):
22 self._power_metric = power.PowerMetric(platform)
23 self._network_metric = network.NetworkMetric(platform)
25 def WillNavigateToPage(self, page, tab):
26 self._network_metric.Start(page, tab)
28 def DidNavigateToPage(self, page, tab):
29 self._power_metric.Start(page, tab)
31 def ValidateAndMeasurePage(self, page, tab, results):
32 self._network_metric.Stop(page, tab)
33 self._power_metric.Stop(page, tab)
34 self._network_metric.AddResults(tab, results)
35 self._power_metric.AddResults(tab, results)
38 class LoadPower(Power):
39 def WillNavigateToPage(self, page, tab):
40 self._network_metric.Start(page, tab)
41 self._power_metric.Start(page, tab)
43 def DidNavigateToPage(self, page, tab):
44 pass
47 class QuiescentPower(page_test.PageTest):
48 """Measures power draw and idle wakeups after the page finished loading."""
50 # Amount of time to measure, in seconds.
51 SAMPLE_TIME = 30
53 def ValidateAndMeasurePage(self, page, tab, results):
54 if not tab.browser.platform.CanMonitorPower():
55 return
57 util.WaitFor(tab.HasReachedQuiescence, 60)
59 metric = power.PowerMetric(tab.browser.platform)
60 metric.Start(page, tab)
62 time.sleep(QuiescentPower.SAMPLE_TIME)
64 metric.Stop(page, tab)
65 metric.AddResults(tab, results)