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 logging | 5 import logging |
6 | 6 |
7 from metrics import Metric | 7 from metrics import Metric |
8 from telemetry.core.platform import factory | 8 from telemetry.core.platform import factory |
9 | 9 |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 parent = super(PowerMetric, self) | 27 parent = super(PowerMetric, self) |
28 if hasattr(parent, '__del__'): | 28 if hasattr(parent, '__del__'): |
29 parent.__del__() | 29 parent.__del__() |
30 | 30 |
31 def _StopInternal(self): | 31 def _StopInternal(self): |
32 """ Stop monitoring power if measurement is running. This function is | 32 """ Stop monitoring power if measurement is running. This function is |
33 idempotent.""" | 33 idempotent.""" |
34 if not self._running: | 34 if not self._running: |
35 return | 35 return |
36 self._running = False | 36 self._running = False |
37 self._results = self._browser.platform.StopMonitoringPowerAsync() | 37 self._results = self._browser.platform.StopMonitoringPower() |
38 if self._results: # StopMonitoringPowerAsync() can return None. | 38 if self._results: # StopMonitoringPower() can return None. |
39 self._results['cpu_stats'] = ( | 39 self._results['cpu_stats'] = ( |
40 _SubtractCpuStats(self._browser.cpu_stats, self._starting_cpu_stats)) | 40 _SubtractCpuStats(self._browser.cpu_stats, self._starting_cpu_stats)) |
41 | 41 |
42 @classmethod | 42 @classmethod |
43 def CustomizeBrowserOptions(cls, options): | 43 def CustomizeBrowserOptions(cls, options): |
44 PowerMetric.enabled = options.report_root_metrics | 44 PowerMetric.enabled = options.report_root_metrics |
45 | 45 |
46 # Friendly informational messages if measurement won't run. | 46 # Friendly informational messages if measurement won't run. |
47 system_supports_power_monitoring = ( | 47 system_supports_power_monitoring = ( |
48 factory.GetPlatformBackendForCurrentOS().CanMonitorPowerAsync()) | 48 factory.GetPlatformBackendForCurrentOS().CanMonitorPower()) |
49 if system_supports_power_monitoring: | 49 if system_supports_power_monitoring: |
50 if not PowerMetric.enabled: | 50 if not PowerMetric.enabled: |
51 logging.warning( | 51 logging.warning( |
52 "--report-root-metrics omitted, power measurement disabled.") | 52 "--report-root-metrics omitted, power measurement disabled.") |
53 else: | 53 else: |
54 logging.info("System doesn't support power monitoring, power measurement" | 54 logging.info("System doesn't support power monitoring, power measurement" |
55 " disabled.") | 55 " disabled.") |
56 | 56 |
57 def Start(self, _, tab): | 57 def Start(self, _, tab): |
58 if not PowerMetric.enabled: | 58 if not PowerMetric.enabled: |
59 return | 59 return |
60 | 60 |
61 if not tab.browser.platform.CanMonitorPowerAsync(): | 61 if not tab.browser.platform.CanMonitorPower(): |
62 return | 62 return |
63 | 63 |
64 self._results = None | 64 self._results = None |
65 self._browser = tab.browser | 65 self._browser = tab.browser |
66 self._StopInternal() | 66 self._StopInternal() |
67 | 67 |
68 # This line invokes top a few times, call before starting power measurement. | 68 # This line invokes top a few times, call before starting power measurement. |
69 self._starting_cpu_stats = self._browser.cpu_stats | 69 self._starting_cpu_stats = self._browser.cpu_stats |
70 self._browser.platform.StartMonitoringPowerAsync() | 70 self._browser.platform.StartMonitoringPower(self._browser) |
71 self._running = True | 71 self._running = True |
72 | 72 |
73 def Stop(self, _, tab): | 73 def Stop(self, _, tab): |
74 if not PowerMetric.enabled: | 74 if not PowerMetric.enabled: |
75 return | 75 return |
76 | 76 |
77 if not tab.browser.platform.CanMonitorPowerAsync(): | 77 if not tab.browser.platform.CanMonitorPower(): |
78 return | 78 return |
79 | 79 |
80 self._StopInternal() | 80 self._StopInternal() |
81 | 81 |
82 def AddResults(self, _, results): | 82 def AddResults(self, _, results): |
83 if not self._results: | 83 if not self._results: |
84 return | 84 return |
85 | 85 |
86 energy_consumption_mwh = self._results['energy_consumption_mwh'] | 86 energy_consumption_mwh = self._results['energy_consumption_mwh'] |
87 results.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh) | 87 results.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh) |
(...skipping 15 matching lines...) Expand all Loading... |
103 Returns: | 103 Returns: |
104 A dict of process type names (Browser, Renderer, etc.) to idle wakeup count | 104 A dict of process type names (Browser, Renderer, etc.) to idle wakeup count |
105 over the period recorded by the input. | 105 over the period recorded by the input. |
106 """ | 106 """ |
107 cpu_delta = {} | 107 cpu_delta = {} |
108 for process_type in cpu_stats: | 108 for process_type in cpu_stats: |
109 assert process_type in start_cpu_stats, 'Mismatching process types' | 109 assert process_type in start_cpu_stats, 'Mismatching process types' |
110 # Skip any process_types that are empty. | 110 # Skip any process_types that are empty. |
111 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): | 111 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): |
112 continue | 112 continue |
| 113 # Skip if IdleWakeupCount is not present. |
| 114 if (('IdleWakeupCount' not in cpu_stats[process_type]) or |
| 115 ('IdleWakeupCount' not in start_cpu_stats[process_type])): |
| 116 continue |
113 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - | 117 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - |
114 start_cpu_stats[process_type]['IdleWakeupCount']) | 118 start_cpu_stats[process_type]['IdleWakeupCount']) |
115 cpu_delta[process_type] = idle_wakeup_delta | 119 cpu_delta[process_type] = idle_wakeup_delta |
116 return cpu_delta | 120 return cpu_delta |
OLD | NEW |