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