| 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 from telemetry.value import scalar |
| 6 |
| 5 from metrics import Metric | 7 from metrics import Metric |
| 6 from telemetry.value import scalar | |
| 7 | 8 |
| 8 | 9 |
| 9 class CpuMetric(Metric): | 10 class CpuMetric(Metric): |
| 10 """Calulates CPU load over a span of time.""" | 11 """Calulates CPU load over a span of time.""" |
| 11 | 12 |
| 12 def __init__(self, browser): | 13 def __init__(self, browser): |
| 13 super(CpuMetric, self).__init__() | 14 super(CpuMetric, self).__init__() |
| 14 self._browser = browser | 15 self._browser = browser |
| 15 self._start_cpu = None | 16 self._start_cpu = None |
| 16 self._stop_cpu = None | 17 self._stop_cpu = None |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 # Linux kernel starts with a value close to an overflow, so correction is | 71 # Linux kernel starts with a value close to an overflow, so correction is |
| 71 # necessary. | 72 # necessary. |
| 72 if total_time < 0: | 73 if total_time < 0: |
| 73 total_time += 2**32 | 74 total_time += 2**32 |
| 74 # Assert that the arguments were given in the correct order. | 75 # Assert that the arguments were given in the correct order. |
| 75 assert total_time > 0 and total_time < 2**31, ( | 76 assert total_time > 0 and total_time < 2**31, ( |
| 76 'Expected total_time > 0, was: %d' % total_time) | 77 'Expected total_time > 0, was: %d' % total_time) |
| 77 cpu_usage[process_type] = float(cpu_process_time) / total_time | 78 cpu_usage[process_type] = float(cpu_process_time) / total_time |
| 78 return cpu_usage | 79 return cpu_usage |
| 79 | 80 |
| OLD | NEW |