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.
5 #include "base/process/process_metrics.h"
7 #include <sys/resource.h>
10 #include "base/logging.h"
14 int64
TimeValToMicroseconds(const struct timeval
& tv
) {
15 static const int kMicrosecondsPerSecond
= 1000000;
16 int64 ret
= tv
.tv_sec
; // Avoid (int * int) integer overflow.
17 ret
*= kMicrosecondsPerSecond
;
22 ProcessMetrics::~ProcessMetrics() { }
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;
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");
46 max_fds
= nofile
.rlim_cur
;
49 if (max_fds
> INT_MAX
)
52 return static_cast<size_t>(max_fds
);