OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import time | 5 import time |
6 | 6 |
7 from metrics import network | 7 from metrics import network |
8 from metrics import power | 8 from metrics import power |
9 from telemetry.core import util | 9 from telemetry.core import util |
10 from telemetry.page import page_test | 10 from telemetry.page import legacy_page_test |
11 | 11 |
12 | 12 |
13 class Power(page_test.PageTest): | 13 class Power(legacy_page_test.LegacyPageTest): |
14 """Measures power draw and idle wakeups during the page's interactions.""" | 14 """Measures power draw and idle wakeups during the page's interactions.""" |
15 | 15 |
16 def __init__(self): | 16 def __init__(self): |
17 super(Power, self).__init__() | 17 super(Power, self).__init__() |
18 self._power_metric = None | 18 self._power_metric = None |
19 self._network_metric = None | 19 self._network_metric = None |
20 | 20 |
21 def WillStartBrowser(self, platform): | 21 def WillStartBrowser(self, platform): |
22 self._power_metric = power.PowerMetric(platform) | 22 self._power_metric = power.PowerMetric(platform) |
23 self._network_metric = network.NetworkMetric(platform) | 23 self._network_metric = network.NetworkMetric(platform) |
(...skipping 17 matching lines...) Expand all Loading... |
41 class LoadPower(Power): | 41 class LoadPower(Power): |
42 | 42 |
43 def WillNavigateToPage(self, page, tab): | 43 def WillNavigateToPage(self, page, tab): |
44 self._network_metric.Start(page, tab) | 44 self._network_metric.Start(page, tab) |
45 self._power_metric.Start(page, tab) | 45 self._power_metric.Start(page, tab) |
46 | 46 |
47 def DidNavigateToPage(self, page, tab): | 47 def DidNavigateToPage(self, page, tab): |
48 pass | 48 pass |
49 | 49 |
50 | 50 |
51 class QuiescentPower(page_test.PageTest): | 51 class QuiescentPower(legacy_page_test.LegacyPageTest): |
52 """Measures power draw and idle wakeups after the page finished loading.""" | 52 """Measures power draw and idle wakeups after the page finished loading.""" |
53 | 53 |
54 # Amount of time to measure, in seconds. | 54 # Amount of time to measure, in seconds. |
55 SAMPLE_TIME = 30 | 55 SAMPLE_TIME = 30 |
56 | 56 |
57 def ValidateAndMeasurePage(self, page, tab, results): | 57 def ValidateAndMeasurePage(self, page, tab, results): |
58 if not tab.browser.platform.CanMonitorPower(): | 58 if not tab.browser.platform.CanMonitorPower(): |
59 return | 59 return |
60 | 60 |
61 util.WaitFor(tab.HasReachedQuiescence, 60) | 61 util.WaitFor(tab.HasReachedQuiescence, 60) |
62 | 62 |
63 metric = power.PowerMetric(tab.browser.platform) | 63 metric = power.PowerMetric(tab.browser.platform) |
64 metric.Start(page, tab) | 64 metric.Start(page, tab) |
65 | 65 |
66 time.sleep(QuiescentPower.SAMPLE_TIME) | 66 time.sleep(QuiescentPower.SAMPLE_TIME) |
67 | 67 |
68 metric.Stop(page, tab) | 68 metric.Stop(page, tab) |
69 metric.AddResults(tab, results) | 69 metric.AddResults(tab, results) |
OLD | NEW |