Chromium Code Reviews| 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 metrics import Metric | 5 from metrics import Metric |
| 6 from telemetry.value import scalar | 6 from telemetry.value import scalar |
| 7 | 7 |
| 8 | 8 |
| 9 class CpuMetric(Metric): | 9 class CpuMetric(Metric): |
| 10 """Calulates CPU load over a span of time.""" | 10 """Calulates CPU load over a span of time.""" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 Returns: | 54 Returns: |
| 55 A dict of process type names (Browser, Renderer, etc.) to ratios of cpu | 55 A dict of process type names (Browser, Renderer, etc.) to ratios of cpu |
| 56 time used to total time elapsed. | 56 time used to total time elapsed. |
| 57 """ | 57 """ |
| 58 cpu_usage = {} | 58 cpu_usage = {} |
| 59 for process_type in cpu_stats: | 59 for process_type in cpu_stats: |
| 60 assert process_type in start_cpu_stats, 'Mismatching process types' | 60 assert process_type in start_cpu_stats, 'Mismatching process types' |
| 61 # Skip any process_types that are empty. | 61 # Skip any process_types that are empty. |
| 62 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): | 62 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): |
| 63 continue | 63 continue |
| 64 cpu_process_time = (cpu_stats[process_type]['CpuProcessTime'] - | 64 cpu_process_time = (cpu_stats[process_type]['CpuProcessTime'] - |
|
Sami
2014/06/30 15:52:26
Does this field have the same problem? If so, mayb
Victor Starodub
2014/06/30 16:15:02
No, this field is counted from the process start r
| |
| 65 start_cpu_stats[process_type]['CpuProcessTime']) | 65 start_cpu_stats[process_type]['CpuProcessTime']) |
| 66 total_time = (cpu_stats[process_type]['TotalTime'] - | 66 total_time = (cpu_stats[process_type]['TotalTime'] - |
| 67 start_cpu_stats[process_type]['TotalTime']) | 67 start_cpu_stats[process_type]['TotalTime']) |
| 68 assert total_time > 0, 'Expected total_time > 0, was: %d' % total_time | 68 # Fix overflow for 32-bit jiffie counter, 64-bit counter will not overflow. |
| 69 # Android devices start with a value close to an overflow, so correction is | |
|
Sami
2014/06/30 15:52:26
Looks like this isn't really Android-specific but
Victor Starodub
2014/06/30 16:15:02
Thanks. Fixed the comment
| |
| 70 # necessary. | |
| 71 if total_time < 0: | |
| 72 total_time += 2**32 | |
| 73 # Assert that the arguments were given in the correct order. | |
| 74 assert total_time > 0 and total_time < 2**31, ( | |
| 75 'Expected total_time > 0, was: %d' % total_time) | |
| 69 cpu_usage[process_type] = float(cpu_process_time) / total_time | 76 cpu_usage[process_type] = float(cpu_process_time) / total_time |
| 70 return cpu_usage | 77 return cpu_usage |
| 71 | 78 |
| OLD | NEW |