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 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 assert process_type in start_cpu_stats, 'Mismatching process types' | 80 assert process_type in start_cpu_stats, 'Mismatching process types' |
| 81 # Skip any process_types that are empty. | 81 # Skip any process_types that are empty. |
| 82 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): | 82 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): |
| 83 continue | 83 continue |
| 84 cpu_process_time = (cpu_stats[process_type]['CpuProcessTime'] - | 84 cpu_process_time = (cpu_stats[process_type]['CpuProcessTime'] - |
| 85 start_cpu_stats[process_type]['CpuProcessTime']) | 85 start_cpu_stats[process_type]['CpuProcessTime']) |
| 86 total_time = (cpu_stats[process_type]['TotalTime'] - | 86 total_time = (cpu_stats[process_type]['TotalTime'] - |
| 87 start_cpu_stats[process_type]['TotalTime']) | 87 start_cpu_stats[process_type]['TotalTime']) |
| 88 # Fix overflow for 32-bit jiffie counter, 64-bit counter will not overflow. | 88 # Fix overflow for 32-bit jiffie counter, 64-bit counter will not overflow. |
| 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. Assume jiffie counter is at 100 Hz. |
| 91 if total_time < 0: | 91 if total_time < 0: |
| 92 total_time += 2 ** 32 | 92 total_time += 2 ** 32 / 100. |
|
mikecase (-- gone --)
2016/12/06 19:54:15
do you need to divide by 100 if total_time > 0?
dtu
2016/12/06 20:33:58
No, the log shows that the values in cpu_stats wer
| |
| 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, ( |
|
Sami
2016/12/07 17:20:12
Should this upper limit be fixed too?
dtu
2016/12/08 00:55:29
Done.
| |
| 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 |
| OLD | NEW |