OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <mach/task.h> | 8 #include <mach/task.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/scoped_mach_port.h" |
12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 bool GetTaskInfo(task_basic_info_64* task_info_data) { | 19 bool GetTaskInfo(task_basic_info_64* task_info_data) { |
19 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; | 20 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; |
20 kern_return_t kr = task_info(mach_task_self(), | 21 kern_return_t kr = task_info(mach_task_self(), |
21 TASK_BASIC_INFO_64, | 22 TASK_BASIC_INFO_64, |
22 reinterpret_cast<task_info_t>(task_info_data), | 23 reinterpret_cast<task_info_t>(task_info_data), |
23 &count); | 24 &count); |
24 return kr == KERN_SUCCESS; | 25 return kr == KERN_SUCCESS; |
25 } | 26 } |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 SystemMemoryInfoKB::SystemMemoryInfoKB() : total(0), free(0) {} | 30 SystemMemoryInfoKB::SystemMemoryInfoKB() |
| 31 : total(0), free(0), speculative(0), file_backed(0), purgeable(0) {} |
30 | 32 |
31 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = | 33 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = |
32 default; | 34 default; |
33 | 35 |
34 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} | 36 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} |
35 | 37 |
36 ProcessMetrics::~ProcessMetrics() {} | 38 ProcessMetrics::~ProcessMetrics() {} |
37 | 39 |
38 // static | 40 // static |
39 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( | 41 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 size_t GetPageSize() { | 86 size_t GetPageSize() { |
85 return getpagesize(); | 87 return getpagesize(); |
86 } | 88 } |
87 | 89 |
88 // Bytes committed by the system. | 90 // Bytes committed by the system. |
89 size_t GetSystemCommitCharge() { | 91 size_t GetSystemCommitCharge() { |
90 NOTIMPLEMENTED(); | 92 NOTIMPLEMENTED(); |
91 return 0; | 93 return 0; |
92 } | 94 } |
93 | 95 |
94 // Bytes committed by the system. | |
95 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 96 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
96 // Unimplemented. Must enable unittest for IOS when this gets implemented. | 97 struct host_basic_info hostinfo; |
97 NOTIMPLEMENTED(); | 98 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
98 return false; | 99 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 100 int result = host_info(host.get(), HOST_BASIC_INFO, |
| 101 reinterpret_cast<host_info_t>(&hostinfo), &count); |
| 102 if (result != KERN_SUCCESS) |
| 103 return false; |
| 104 |
| 105 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
| 106 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); |
| 107 |
| 108 vm_statistics64_data_t vm_info; |
| 109 count = HOST_VM_INFO64_COUNT; |
| 110 |
| 111 if (host_statistics64(host.get(), HOST_VM_INFO64, |
| 112 reinterpret_cast<host_info64_t>(&vm_info), |
| 113 &count) != KERN_SUCCESS) { |
| 114 return false; |
| 115 } |
| 116 DCHECK_EQ(HOST_VM_INFO64_COUNT, count); |
| 117 |
| 118 meminfo->free = static_cast<int>( |
| 119 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); |
| 120 meminfo->speculative = |
| 121 static_cast<int>(vm_info.speculative_count * PAGE_SIZE / 1024); |
| 122 meminfo->file_backed = |
| 123 static_cast<int>(vm_info.external_page_count * PAGE_SIZE / 1024); |
| 124 meminfo->purgeable = |
| 125 static_cast<int>(vm_info.purgeable_count * PAGE_SIZE / 1024); |
| 126 |
| 127 return true; |
99 } | 128 } |
100 | 129 |
101 } // namespace base | 130 } // namespace base |
OLD | NEW |