OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <sys/time.h> | 12 #include <sys/time.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <sys/wait.h> | 14 #include <sys/wait.h> |
15 #include <time.h> | 15 #include <time.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/stringprintf.h" |
20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
21 #include "base/string_split.h" | 22 #include "base/string_split.h" |
22 #include "base/string_tokenizer.h" | 23 #include "base/string_tokenizer.h" |
23 #include "base/string_util.h" | 24 #include "base/string_util.h" |
24 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
25 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 enum ParsingState { | 30 enum ParsingState { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return true; | 69 return true; |
69 } | 70 } |
70 | 71 |
71 // Get the total CPU of a single process. Return value is number of jiffies | 72 // Get the total CPU of a single process. Return value is number of jiffies |
72 // on success or -1 on error. | 73 // on success or -1 on error. |
73 int GetProcessCPU(pid_t pid) { | 74 int GetProcessCPU(pid_t pid) { |
74 // Synchronously reading files in /proc is safe. | 75 // Synchronously reading files in /proc is safe. |
75 base::ThreadRestrictions::ScopedAllowIO allow_io; | 76 base::ThreadRestrictions::ScopedAllowIO allow_io; |
76 | 77 |
77 // Use /proc/<pid>/task to find all threads and parse their /stat file. | 78 // Use /proc/<pid>/task to find all threads and parse their /stat file. |
78 FilePath path = FilePath(StringPrintf("/proc/%d/task/", pid)); | 79 FilePath path = FilePath(base::StringPrintf("/proc/%d/task/", pid)); |
79 | 80 |
80 DIR* dir = opendir(path.value().c_str()); | 81 DIR* dir = opendir(path.value().c_str()); |
81 if (!dir) { | 82 if (!dir) { |
82 PLOG(ERROR) << "opendir(" << path.value() << ")"; | 83 PLOG(ERROR) << "opendir(" << path.value() << ")"; |
83 return -1; | 84 return -1; |
84 } | 85 } |
85 | 86 |
86 int total_cpu = 0; | 87 int total_cpu = 0; |
87 while (struct dirent* ent = readdir(dir)) { | 88 while (struct dirent* ent = readdir(dir)) { |
88 if (ent->d_name[0] == '.') | 89 if (ent->d_name[0] == '.') |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 707 |
707 if (!file_util::PathExists(oom_adj)) | 708 if (!file_util::PathExists(oom_adj)) |
708 return false; | 709 return false; |
709 | 710 |
710 std::string score_str = base::IntToString(score); | 711 std::string score_str = base::IntToString(score); |
711 return (static_cast<int>(score_str.length()) == | 712 return (static_cast<int>(score_str.length()) == |
712 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); | 713 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); |
713 } | 714 } |
714 | 715 |
715 } // namespace base | 716 } // namespace base |
OLD | NEW |