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"
9 #include "base/logging.h"
15 bool GetTaskInfo(task_basic_info_64
* task_info_data
) {
16 mach_msg_type_number_t count
= TASK_BASIC_INFO_64_COUNT
;
17 kern_return_t kr
= task_info(mach_task_self(),
19 reinterpret_cast<task_info_t
>(task_info_data
),
21 return kr
== KERN_SUCCESS
;
26 ProcessMetrics::ProcessMetrics(ProcessHandle process
) {}
28 ProcessMetrics::~ProcessMetrics() {}
31 ProcessMetrics
* ProcessMetrics::CreateProcessMetrics(ProcessHandle process
) {
32 return new ProcessMetrics(process
);
35 double ProcessMetrics::GetCPUUsage() {
40 size_t ProcessMetrics::GetPagefileUsage() const {
41 task_basic_info_64 task_info_data
;
42 if (!GetTaskInfo(&task_info_data
))
44 return task_info_data
.virtual_size
;
47 size_t ProcessMetrics::GetWorkingSetSize() const {
48 task_basic_info_64 task_info_data
;
49 if (!GetTaskInfo(&task_info_data
))
51 return task_info_data
.resident_size
;
55 static const rlim_t kSystemDefaultMaxFds
= 256;
58 if (getrlimit(RLIMIT_NOFILE
, &nofile
)) {
59 // Error case: Take a best guess.
60 max_fds
= kSystemDefaultMaxFds
;
62 max_fds
= nofile
.rlim_cur
;
65 if (max_fds
> INT_MAX
)
68 return static_cast<size_t>(max_fds
);
71 void SetFdLimit(unsigned int max_descriptors
) {
75 size_t GetPageSize() {
79 // Bytes committed by the system.
80 size_t GetSystemCommitCharge() {