OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <sys/resource.h> | 7 #include <sys/resource.h> |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 #include <limits> |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 | 18 |
18 const int kMicrosecondsPerSecond = 1000000; | 19 const int kMicrosecondsPerSecond = 1000000; |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 | 22 |
22 int GetCurrentProcId() { | 23 int GetCurrentProcId() { |
23 return getpid(); | 24 return getpid(); |
24 } | 25 } |
25 | 26 |
26 ProcessHandle GetCurrentProcessHandle() { | 27 ProcessHandle GetCurrentProcessHandle() { |
27 return GetCurrentProcId(); | 28 return GetCurrentProcId(); |
28 } | 29 } |
29 | 30 |
30 int GetProcId(ProcessHandle process) { | 31 int GetProcId(ProcessHandle process) { |
31 return process; | 32 return process; |
32 } | 33 } |
33 | 34 |
| 35 int GetMaxFilesOpenInProcess() { |
| 36 struct rlimit rlimit; |
| 37 if (getrlimit(RLIMIT_NOFILE, &rlimit) != 0) { |
| 38 return 0; |
| 39 } |
| 40 |
| 41 // rlim_t is a uint64 - clip to maxint. |
| 42 // We do this since we use the value of this function to close FD #s in a loop |
| 43 // if we didn't clamp the value, doing this would be too time consuming. |
| 44 rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max()); |
| 45 if (rlimit.rlim_cur > max_int) { |
| 46 return max_int; |
| 47 } |
| 48 |
| 49 return rlimit.rlim_cur; |
| 50 } |
| 51 |
34 ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), | 52 ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), |
35 last_time_(0), | 53 last_time_(0), |
36 last_system_time_(0) { | 54 last_system_time_(0) { |
37 processor_count_ = base::SysInfo::NumberOfProcessors(); | 55 processor_count_ = base::SysInfo::NumberOfProcessors(); |
38 } | 56 } |
39 | 57 |
40 // static | 58 // static |
41 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { | 59 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { |
42 return new ProcessMetrics(process); | 60 return new ProcessMetrics(process); |
43 } | 61 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 int cpu = static_cast<int>((system_time_delta * 100 + time_delta / 2) / | 165 int cpu = static_cast<int>((system_time_delta * 100 + time_delta / 2) / |
148 time_delta); | 166 time_delta); |
149 | 167 |
150 last_system_time_ = system_time; | 168 last_system_time_ = system_time; |
151 last_time_ = time; | 169 last_time_ = time; |
152 | 170 |
153 return cpu; | 171 return cpu; |
154 } | 172 } |
155 | 173 |
156 } // namespace base | 174 } // namespace base |
OLD | NEW |