Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: base/process/process_metrics_ios.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix integer overflow in unittest. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_metrics.cc ('k') | base/process/process_metrics_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "base/numerics/safe_conversions.h"
13 15
14 namespace base { 16 namespace base {
15 17
16 namespace { 18 namespace {
17 19
18 bool GetTaskInfo(task_basic_info_64* task_info_data) { 20 bool GetTaskInfo(task_basic_info_64* task_info_data) {
19 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; 21 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
20 kern_return_t kr = task_info(mach_task_self(), 22 kern_return_t kr = task_info(mach_task_self(),
21 TASK_BASIC_INFO_64, 23 TASK_BASIC_INFO_64,
22 reinterpret_cast<task_info_t>(task_info_data), 24 reinterpret_cast<task_info_t>(task_info_data),
23 &count); 25 &count);
24 return kr == KERN_SUCCESS; 26 return kr == KERN_SUCCESS;
25 } 27 }
26 28
27 } // namespace 29 } // namespace
28 30
29 SystemMemoryInfoKB::SystemMemoryInfoKB() : total(0), free(0) {}
30
31 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) =
32 default;
33
34 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} 31 ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
35 32
36 ProcessMetrics::~ProcessMetrics() {} 33 ProcessMetrics::~ProcessMetrics() {}
37 34
38 // static 35 // static
39 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( 36 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
40 ProcessHandle process) { 37 ProcessHandle process) {
41 return WrapUnique(new ProcessMetrics(process)); 38 return WrapUnique(new ProcessMetrics(process));
42 } 39 }
43 40
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 size_t GetPageSize() { 81 size_t GetPageSize() {
85 return getpagesize(); 82 return getpagesize();
86 } 83 }
87 84
88 // Bytes committed by the system. 85 // Bytes committed by the system.
89 size_t GetSystemCommitCharge() { 86 size_t GetSystemCommitCharge() {
90 NOTIMPLEMENTED(); 87 NOTIMPLEMENTED();
91 return 0; 88 return 0;
92 } 89 }
93 90
94 // Bytes committed by the system.
95 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 91 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
96 // Unimplemented. Must enable unittest for IOS when this gets implemented. 92 struct host_basic_info hostinfo;
97 NOTIMPLEMENTED(); 93 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
98 return false; 94 base::mac::ScopedMachSendRight host(mach_host_self());
95 int result = host_info(host.get(), HOST_BASIC_INFO,
96 reinterpret_cast<host_info_t>(&hostinfo), &count);
97 if (result != KERN_SUCCESS)
98 return false;
99
100 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
101 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024);
102
103 vm_statistics64_data_t vm_info;
104 count = HOST_VM_INFO64_COUNT;
105
106 if (host_statistics64(host.get(), HOST_VM_INFO64,
107 reinterpret_cast<host_info64_t>(&vm_info),
108 &count) != KERN_SUCCESS) {
109 return false;
110 }
111 DCHECK_EQ(HOST_VM_INFO64_COUNT, count);
112
113 // Check that PAGE_SIZE is divisible by 1024 (2^10).
114 CHECK_EQ(PAGE_SIZE, (PAGE_SIZE >> 10) << 10);
115 meminfo->free = saturated_cast<int>(
116 PAGE_SIZE / 1024 * (vm_info.free_count - vm_info.speculative_count));
117 meminfo->speculative =
118 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.speculative_count);
119 meminfo->file_backed =
120 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.external_page_count);
121 meminfo->purgeable =
122 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.purgeable_count);
123
124 return true;
99 } 125 }
100 126
101 } // namespace base 127 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_metrics.cc ('k') | base/process/process_metrics_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698