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"
13 bool GetTaskInfo(task_basic_info_64* task_info_data) {
14 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
15 kern_return_t kr = task_info(mach_task_self(),
17 reinterpret_cast<task_info_t>(task_info_data),
19 return kr == KERN_SUCCESS;
24 ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
26 ProcessMetrics::~ProcessMetrics() {}
29 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
30 return new ProcessMetrics(process);
33 size_t ProcessMetrics::GetPagefileUsage() const {
34 task_basic_info_64 task_info_data;
35 if (!GetTaskInfo(&task_info_data))
37 return task_info_data.virtual_size;
40 size_t ProcessMetrics::GetWorkingSetSize() const {
41 task_basic_info_64 task_info_data;
42 if (!GetTaskInfo(&task_info_data))
44 return task_info_data.resident_size;
48 static const rlim_t kSystemDefaultMaxFds = 256;
51 if (getrlimit(RLIMIT_NOFILE, &nofile)) {
52 // Error case: Take a best guess.
53 max_fds = kSystemDefaultMaxFds;
55 max_fds = nofile.rlim_cur;
58 if (max_fds > INT_MAX)
61 return static_cast<size_t>(max_fds);
64 void SetFdLimit(unsigned int max_descriptors) {