| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 telemetry.value import scalar | 7 from telemetry.value import scalar |
| 8 | 8 |
| 9 from metrics import Metric | 9 from metrics import Metric |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 self._start_cpu = self._browser.cpu_stats | 30 self._start_cpu = self._browser.cpu_stats |
| 31 | 31 |
| 32 def Stop(self, page, tab): | 32 def Stop(self, page, tab): |
| 33 if not self._browser.supports_cpu_metrics: | 33 if not self._browser.supports_cpu_metrics: |
| 34 return | 34 return |
| 35 | 35 |
| 36 assert self._start_cpu, 'Must call Start() first' | 36 assert self._start_cpu, 'Must call Start() first' |
| 37 self._stop_cpu = self._browser.cpu_stats | 37 self._stop_cpu = self._browser.cpu_stats |
| 38 | 38 |
| 39 # Optional argument trace_name is not in base class Metric. | 39 # Optional argument trace_name is not in base class Metric. |
| 40 # pylint: disable=W0221 | 40 # pylint: disable=arguments-differ |
| 41 def AddResults(self, tab, results, trace_name='cpu_utilization'): | 41 def AddResults(self, tab, results, trace_name='cpu_utilization'): |
| 42 if not self._browser.supports_cpu_metrics: | 42 if not self._browser.supports_cpu_metrics: |
| 43 return | 43 return |
| 44 | 44 |
| 45 assert self._stop_cpu, 'Must call Stop() first' | 45 assert self._stop_cpu, 'Must call Stop() first' |
| 46 cpu_stats = _SubtractCpuStats(self._stop_cpu, self._start_cpu) | 46 cpu_stats = _SubtractCpuStats(self._stop_cpu, self._start_cpu) |
| 47 | 47 |
| 48 # FIXME: Renderer process CPU times are impossible to compare correctly. | 48 # FIXME: Renderer process CPU times are impossible to compare correctly. |
| 49 # http://crbug.com/419786#c11 | 49 # http://crbug.com/419786#c11 |
| 50 if 'Renderer' in cpu_stats: | 50 if 'Renderer' in cpu_stats: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 # Linux kernel starts with a value close to an overflow, so correction is | 89 # Linux kernel starts with a value close to an overflow, so correction is |
| 90 # necessary. | 90 # necessary. |
| 91 if total_time < 0: | 91 if total_time < 0: |
| 92 total_time += 2**32 | 92 total_time += 2**32 |
| 93 # Assert that the arguments were given in the correct order. | 93 # Assert that the arguments were given in the correct order. |
| 94 assert total_time > 0 and total_time < 2**31, ( | 94 assert total_time > 0 and total_time < 2**31, ( |
| 95 'Expected total_time > 0, was: %d' % total_time) | 95 'Expected total_time > 0, was: %d' % total_time) |
| 96 cpu_usage[process_type] = float(cpu_process_time) / total_time | 96 cpu_usage[process_type] = float(cpu_process_time) / total_time |
| 97 return cpu_usage | 97 return cpu_usage |
| 98 | 98 |
| OLD | NEW |