| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/process/process_metrics.h" | |
| 6 | |
| 7 #include <sys/resource.h> | |
| 8 #include <sys/time.h> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 | |
| 12 namespace base { | |
| 13 | |
| 14 int64 TimeValToMicroseconds(const struct timeval& tv) { | |
| 15 int64 ret = tv.tv_sec; // Avoid (int * int) integer overflow. | |
| 16 ret *= Time::kMicrosecondsPerSecond; | |
| 17 ret += tv.tv_usec; | |
| 18 return ret; | |
| 19 } | |
| 20 | |
| 21 ProcessMetrics::~ProcessMetrics() { } | |
| 22 | |
| 23 #if defined(OS_LINUX) | |
| 24 static const rlim_t kSystemDefaultMaxFds = 8192; | |
| 25 #elif defined(OS_MACOSX) | |
| 26 static const rlim_t kSystemDefaultMaxFds = 256; | |
| 27 #elif defined(OS_SOLARIS) | |
| 28 static const rlim_t kSystemDefaultMaxFds = 8192; | |
| 29 #elif defined(OS_FREEBSD) | |
| 30 static const rlim_t kSystemDefaultMaxFds = 8192; | |
| 31 #elif defined(OS_OPENBSD) | |
| 32 static const rlim_t kSystemDefaultMaxFds = 256; | |
| 33 #elif defined(OS_ANDROID) | |
| 34 static const rlim_t kSystemDefaultMaxFds = 1024; | |
| 35 #endif | |
| 36 | |
| 37 size_t GetMaxFds() { | |
| 38 rlim_t max_fds; | |
| 39 struct rlimit nofile; | |
| 40 if (getrlimit(RLIMIT_NOFILE, &nofile)) { | |
| 41 // getrlimit failed. Take a best guess. | |
| 42 max_fds = kSystemDefaultMaxFds; | |
| 43 RAW_LOG(ERROR, "getrlimit(RLIMIT_NOFILE) failed"); | |
| 44 } else { | |
| 45 max_fds = nofile.rlim_cur; | |
| 46 } | |
| 47 | |
| 48 if (max_fds > INT_MAX) | |
| 49 max_fds = INT_MAX; | |
| 50 | |
| 51 return static_cast<size_t>(max_fds); | |
| 52 } | |
| 53 | |
| 54 | |
| 55 void SetFdLimit(unsigned int max_descriptors) { | |
| 56 struct rlimit limits; | |
| 57 if (getrlimit(RLIMIT_NOFILE, &limits) == 0) { | |
| 58 unsigned int new_limit = max_descriptors; | |
| 59 if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) { | |
| 60 new_limit = limits.rlim_max; | |
| 61 } | |
| 62 limits.rlim_cur = new_limit; | |
| 63 if (setrlimit(RLIMIT_NOFILE, &limits) != 0) { | |
| 64 PLOG(INFO) << "Failed to set file descriptor limit"; | |
| 65 } | |
| 66 } else { | |
| 67 PLOG(INFO) << "Failed to get file descriptor limit"; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 size_t GetPageSize() { | |
| 72 return getpagesize(); | |
| 73 } | |
| 74 | |
| 75 } // namespace base | |
| OLD | NEW |