| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/internal_linux.h" | 5 #include "base/process/internal_linux.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return 0; | 47 return 0; |
| 48 } | 48 } |
| 49 return pid; | 49 return pid; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool ReadProcFile(const FilePath& file, std::string* buffer) { | 52 bool ReadProcFile(const FilePath& file, std::string* buffer) { |
| 53 buffer->clear(); | 53 buffer->clear(); |
| 54 // Synchronously reading files in /proc is safe. | 54 // Synchronously reading files in /proc is safe. |
| 55 ThreadRestrictions::ScopedAllowIO allow_io; | 55 ThreadRestrictions::ScopedAllowIO allow_io; |
| 56 | 56 |
| 57 if (!file_util::ReadFileToString(file, buffer)) { | 57 if (!ReadFileToString(file, buffer)) { |
| 58 DLOG(WARNING) << "Failed to read " << file.MaybeAsASCII(); | 58 DLOG(WARNING) << "Failed to read " << file.MaybeAsASCII(); |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 return !buffer->empty(); | 61 return !buffer->empty(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool ReadProcStats(pid_t pid, std::string* buffer) { | 64 bool ReadProcStats(pid_t pid, std::string* buffer) { |
| 65 FilePath stat_file = internal::GetProcPidDir(pid).Append(kStatFile); | 65 FilePath stat_file = internal::GetProcPidDir(pid).Append(kStatFile); |
| 66 return ReadProcFile(stat_file, buffer); | 66 return ReadProcFile(stat_file, buffer); |
| 67 } | 67 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // which means the answer is 100. | 181 // which means the answer is 100. |
| 182 // It may be the case that this value is always 100. | 182 // It may be the case that this value is always 100. |
| 183 static const int kHertz = sysconf(_SC_CLK_TCK); | 183 static const int kHertz = sysconf(_SC_CLK_TCK); |
| 184 | 184 |
| 185 return TimeDelta::FromMicroseconds( | 185 return TimeDelta::FromMicroseconds( |
| 186 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); | 186 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace internal | 189 } // namespace internal |
| 190 } // namespace base | 190 } // namespace base |
| OLD | NEW |