OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/param.h> | 12 #include <sys/param.h> |
13 #include <sys/sysctl.h> | 13 #include <sys/sysctl.h> |
14 #include <sys/time.h> | 14 #include <sys/time.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <sys/user.h> | 16 #include <sys/user.h> |
17 #include <sys/wait.h> | 17 #include <sys/wait.h> |
18 #include <time.h> | 18 #include <time.h> |
19 #include <unistd.h> | 19 #include <unistd.h> |
20 | 20 |
21 #include "base/file_util.h" | |
22 #include "base/logging.h" | 21 #include "base/logging.h" |
23 #include "base/string_tokenizer.h" | 22 #include "base/string_tokenizer.h" |
24 #include "base/string_util.h" | 23 #include "base/string_util.h" |
25 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
27 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
28 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
29 | 28 |
30 namespace base { | 29 namespace base { |
31 | 30 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 203 |
205 mib[5] = (length / sizeof(struct kinfo_proc)); | 204 mib[5] = (length / sizeof(struct kinfo_proc)); |
206 | 205 |
207 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) | 206 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) |
208 return -1; | 207 return -1; |
209 | 208 |
210 return (info.p_vm_tsize + info.p_vm_dsize + info.p_vm_ssize); | 209 return (info.p_vm_tsize + info.p_vm_dsize + info.p_vm_ssize); |
211 } | 210 } |
212 | 211 |
213 size_t ProcessMetrics::GetPeakPagefileUsage() const { | 212 size_t ProcessMetrics::GetPeakPagefileUsage() const { |
214 | |
215 return 0; | 213 return 0; |
216 } | 214 } |
217 | 215 |
218 size_t ProcessMetrics::GetWorkingSetSize() const { | 216 size_t ProcessMetrics::GetWorkingSetSize() const { |
219 struct kinfo_proc info; | 217 struct kinfo_proc info; |
220 size_t length; | 218 size_t length; |
221 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_, | 219 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_, |
222 sizeof(struct kinfo_proc), 0 }; | 220 sizeof(struct kinfo_proc), 0 }; |
223 | 221 |
224 if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0) | 222 if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0) |
225 return -1; | 223 return -1; |
226 | 224 |
227 mib[5] = (length / sizeof(struct kinfo_proc)); | 225 mib[5] = (length / sizeof(struct kinfo_proc)); |
228 | 226 |
229 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) | 227 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) |
230 return -1; | 228 return -1; |
231 | 229 |
232 return info.p_vm_rssize * getpagesize(); | 230 return info.p_vm_rssize * getpagesize(); |
233 } | 231 } |
234 | 232 |
235 size_t ProcessMetrics::GetPeakWorkingSetSize() const { | 233 size_t ProcessMetrics::GetPeakWorkingSetSize() const { |
236 | |
237 return 0; | 234 return 0; |
238 } | 235 } |
239 | 236 |
240 bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, | 237 bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, |
241 size_t* shared_bytes) { | 238 size_t* shared_bytes) { |
242 WorkingSetKBytes ws_usage; | 239 WorkingSetKBytes ws_usage; |
243 | 240 |
244 if (!GetWorkingSetKBytes(&ws_usage)) | 241 if (!GetWorkingSetKBytes(&ws_usage)) |
245 return false; | 242 return false; |
246 | 243 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); | 334 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); |
338 } | 335 } |
339 | 336 |
340 void EnableTerminationOnOutOfMemory() { | 337 void EnableTerminationOnOutOfMemory() { |
341 } | 338 } |
342 | 339 |
343 void EnableTerminationOnHeapCorruption() { | 340 void EnableTerminationOnHeapCorruption() { |
344 } | 341 } |
345 | 342 |
346 } // namespace base | 343 } // namespace base |
OLD | NEW |