Chromium Code Reviews| 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) {} | |
|
brucedawson
2017/03/11 01:42:08
Don't these need to be =defaulted in?
| |
| 30 | |
| 31 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = | |
| 32 default; | |
| 33 | |
| 34 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} | 30 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} |
| 35 | 31 |
| 36 ProcessMetrics::~ProcessMetrics() {} | 32 ProcessMetrics::~ProcessMetrics() {} |
| 37 | 33 |
| 38 // static | 34 // static |
| 39 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( | 35 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( |
| 40 ProcessHandle process) { | 36 ProcessHandle process) { |
| 41 return WrapUnique(new ProcessMetrics(process)); | 37 return WrapUnique(new ProcessMetrics(process)); |
| 42 } | 38 } |
| 43 | 39 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 size_t GetPageSize() { | 80 size_t GetPageSize() { |
| 85 return getpagesize(); | 81 return getpagesize(); |
| 86 } | 82 } |
| 87 | 83 |
| 88 // Bytes committed by the system. | 84 // Bytes committed by the system. |
| 89 size_t GetSystemCommitCharge() { | 85 size_t GetSystemCommitCharge() { |
| 90 NOTIMPLEMENTED(); | 86 NOTIMPLEMENTED(); |
| 91 return 0; | 87 return 0; |
| 92 } | 88 } |
| 93 | 89 |
| 94 // Bytes committed by the system. | |
| 95 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 90 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
| 96 // Unimplemented. Must enable unittest for IOS when this gets implemented. | 91 struct host_basic_info hostinfo; |
| 97 NOTIMPLEMENTED(); | 92 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 98 return false; | 93 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 94 int result = host_info(host.get(), HOST_BASIC_INFO, | |
| 95 reinterpret_cast<host_info_t>(&hostinfo), &count); | |
| 96 if (result != KERN_SUCCESS) | |
| 97 return false; | |
| 98 | |
| 99 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | |
| 100 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); | |
| 101 | |
| 102 vm_statistics64_data_t vm_info; | |
| 103 count = HOST_VM_INFO64_COUNT; | |
| 104 | |
| 105 if (host_statistics64(host.get(), HOST_VM_INFO64, | |
| 106 reinterpret_cast<host_info64_t>(&vm_info), | |
| 107 &count) != KERN_SUCCESS) { | |
| 108 return false; | |
| 109 } | |
| 110 DCHECK_EQ(HOST_VM_INFO64_COUNT, count); | |
| 111 | |
| 112 meminfo->free = static_cast<int>( | |
|
danakj
2017/03/13 16:01:20
same thing as the _mac file here re casting and in
danakj
2017/03/13 16:01:20
So I'm not sure what you did to relieve my worry h
Michael K. (Yandex Team)
2017/03/14 03:49:09
Done.
Michael K. (Yandex Team)
2017/03/14 03:49:09
Done.
| |
| 113 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); | |
| 114 meminfo->speculative = | |
| 115 static_cast<int>(vm_info.speculative_count * PAGE_SIZE / 1024); | |
| 116 meminfo->file_backed = | |
| 117 static_cast<int>(vm_info.external_page_count * PAGE_SIZE / 1024); | |
| 118 meminfo->purgeable = | |
| 119 static_cast<int>(vm_info.purgeable_count * PAGE_SIZE / 1024); | |
| 120 | |
| 121 return true; | |
| 99 } | 122 } |
| 100 | 123 |
| 101 } // namespace base | 124 } // namespace base |
| OLD | NEW |