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 SystemMemoryInfoKB::SystemMemoryInfoKB() {
31 ProcessMetrics::ProcessMetrics(ProcessHandle process
) {}
33 ProcessMetrics::~ProcessMetrics() {}
36 ProcessMetrics
* ProcessMetrics::CreateProcessMetrics(ProcessHandle process
) {
37 return new ProcessMetrics(process
);
40 double ProcessMetrics::GetCPUUsage() {
45 size_t ProcessMetrics::GetPagefileUsage() const {
46 task_basic_info_64 task_info_data
;
47 if (!GetTaskInfo(&task_info_data
))
49 return task_info_data
.virtual_size
;
52 size_t ProcessMetrics::GetWorkingSetSize() const {
53 task_basic_info_64 task_info_data
;
54 if (!GetTaskInfo(&task_info_data
))
56 return task_info_data
.resident_size
;
60 static const rlim_t kSystemDefaultMaxFds
= 256;
63 if (getrlimit(RLIMIT_NOFILE
, &nofile
)) {
64 // Error case: Take a best guess.
65 max_fds
= kSystemDefaultMaxFds
;
67 max_fds
= nofile
.rlim_cur
;
70 if (max_fds
> INT_MAX
)
73 return static_cast<size_t>(max_fds
);
76 void SetFdLimit(unsigned int max_descriptors
) {
80 size_t GetPageSize() {
84 // Bytes committed by the system.
85 size_t GetSystemCommitCharge() {
90 // Bytes committed by the system.
91 bool GetSystemMemoryInfo(SystemMemoryInfoKB
* meminfo
) {
92 // Unimplemented. Must enable unittest for IOS when this gets implemented.