| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (time_delta == 0) | 221 if (time_delta == 0) |
| 222 return 0; | 222 return 0; |
| 223 | 223 |
| 224 int cpu = GetProcessCPU(process_); | 224 int cpu = GetProcessCPU(process_); |
| 225 | 225 |
| 226 // We have the number of jiffies in the time period. Convert to percentage. | 226 // We have the number of jiffies in the time period. Convert to percentage. |
| 227 // Note this means we will go *over* 100 in the case where multiple threads | 227 // Note this means we will go *over* 100 in the case where multiple threads |
| 228 // are together adding to more than one CPU's worth. | 228 // are together adding to more than one CPU's worth. |
| 229 TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu); | 229 TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu); |
| 230 TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_); | 230 TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_); |
| 231 int percentage = 100 * (cpu_time - last_cpu_time).InSecondsF() / | 231 double percentage = 100.0 * (cpu_time - last_cpu_time).InSecondsF() / |
| 232 TimeDelta::FromMicroseconds(time_delta).InSecondsF(); | 232 TimeDelta::FromMicroseconds(time_delta).InSecondsF(); |
| 233 | 233 |
| 234 last_cpu_time_ = time; | 234 last_cpu_time_ = time; |
| 235 last_cpu_ = cpu; | 235 last_cpu_ = cpu; |
| 236 | 236 |
| 237 return percentage; | 237 return percentage; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING | 240 // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING |
| 241 // in your kernel configuration. | 241 // in your kernel configuration. |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 #if defined(OS_LINUX) | 907 #if defined(OS_LINUX) |
| 908 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 908 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
| 909 uint64 wake_ups; | 909 uint64 wake_ups; |
| 910 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 910 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
| 911 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 911 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
| 912 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 912 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
| 913 } | 913 } |
| 914 #endif // defined(OS_LINUX) | 914 #endif // defined(OS_LINUX) |
| 915 | 915 |
| 916 } // namespace base | 916 } // namespace base |
| OLD | NEW |