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.
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."""
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
):
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.
53 def ValidateAndMeasurePage(self
, page
, tab
, results
):
54 if not tab
.browser
.platform
.CanMonitorPower():
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
)