| 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return 0; | 79 return 0; |
| 80 } | 80 } |
| 81 size_t value; | 81 size_t value; |
| 82 if (!StringToSizeT(split_value_str[0], &value)) { | 82 if (!StringToSizeT(split_value_str[0], &value)) { |
| 83 NOTREACHED(); | 83 NOTREACHED(); |
| 84 return 0; | 84 return 0; |
| 85 } | 85 } |
| 86 return value; | 86 return value; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 // This can be reached if the process dies when proc is read -- in that case, | 89 NOTREACHED(); |
| 90 // the kernel can return missing fields. | |
| 91 return 0; | 90 return 0; |
| 92 } | 91 } |
| 93 | 92 |
| 94 #if defined(OS_LINUX) | 93 #if defined(OS_LINUX) |
| 95 // Read /proc/<pid>/sched and look for |field|. On succes, return true and | 94 // Read /proc/<pid>/sched and look for |field|. On succes, return true and |
| 96 // write the value for |field| into |result|. | 95 // write the value for |field| into |result|. |
| 97 // Only works for fields in the form of "field : uint_value" | 96 // Only works for fields in the form of "field : uint_value" |
| 98 bool ReadProcSchedAndGetFieldAsUint64(pid_t pid, | 97 bool ReadProcSchedAndGetFieldAsUint64(pid_t pid, |
| 99 const std::string& field, | 98 const std::string& field, |
| 100 uint64_t* result) { | 99 uint64_t* result) { |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 #if defined(OS_LINUX) | 941 #if defined(OS_LINUX) |
| 943 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 942 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
| 944 uint64_t wake_ups; | 943 uint64_t wake_ups; |
| 945 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 944 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
| 946 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 945 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
| 947 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 946 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
| 948 } | 947 } |
| 949 #endif // defined(OS_LINUX) | 948 #endif // defined(OS_LINUX) |
| 950 | 949 |
| 951 } // namespace base | 950 } // namespace base |
| OLD | NEW |