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 <sys/resource.h> |
7 #include <sys/time.h> | 8 #include <sys/time.h> |
8 | 9 |
| 10 #include "base/logging.h" |
| 11 |
9 namespace base { | 12 namespace base { |
10 | 13 |
11 int64 TimeValToMicroseconds(const struct timeval& tv) { | 14 int64 TimeValToMicroseconds(const struct timeval& tv) { |
12 static const int kMicrosecondsPerSecond = 1000000; | 15 static const int kMicrosecondsPerSecond = 1000000; |
13 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow. | 16 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow. |
14 ret *= kMicrosecondsPerSecond; | 17 ret *= kMicrosecondsPerSecond; |
15 ret += tv.tv_usec; | 18 ret += tv.tv_usec; |
16 return ret; | 19 return ret; |
17 } | 20 } |
18 | 21 |
19 ProcessMetrics::~ProcessMetrics() { } | 22 ProcessMetrics::~ProcessMetrics() { } |
20 | 23 |
| 24 #if defined(OS_LINUX) |
| 25 static const rlim_t kSystemDefaultMaxFds = 8192; |
| 26 #elif defined(OS_MACOSX) |
| 27 static const rlim_t kSystemDefaultMaxFds = 256; |
| 28 #elif defined(OS_SOLARIS) |
| 29 static const rlim_t kSystemDefaultMaxFds = 8192; |
| 30 #elif defined(OS_FREEBSD) |
| 31 static const rlim_t kSystemDefaultMaxFds = 8192; |
| 32 #elif defined(OS_OPENBSD) |
| 33 static const rlim_t kSystemDefaultMaxFds = 256; |
| 34 #elif defined(OS_ANDROID) |
| 35 static const rlim_t kSystemDefaultMaxFds = 1024; |
| 36 #endif |
| 37 |
| 38 size_t GetMaxFds() { |
| 39 rlim_t max_fds; |
| 40 struct rlimit nofile; |
| 41 if (getrlimit(RLIMIT_NOFILE, &nofile)) { |
| 42 // getrlimit failed. Take a best guess. |
| 43 max_fds = kSystemDefaultMaxFds; |
| 44 RAW_LOG(ERROR, "getrlimit(RLIMIT_NOFILE) failed"); |
| 45 } else { |
| 46 max_fds = nofile.rlim_cur; |
| 47 } |
| 48 |
| 49 if (max_fds > INT_MAX) |
| 50 max_fds = INT_MAX; |
| 51 |
| 52 return static_cast<size_t>(max_fds); |
| 53 } |
| 54 |
21 } // namespace base | 55 } // namespace base |
OLD | NEW |