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

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

Issue 2766623002: Revert of Fix free memory calculation. (Closed)
Patch Set: 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"
13 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
14 #include "base/numerics/safe_conversions.h"
15 13
16 namespace base { 14 namespace base {
17 15
18 namespace { 16 namespace {
19 17
20 bool GetTaskInfo(task_basic_info_64* task_info_data) { 18 bool GetTaskInfo(task_basic_info_64* task_info_data) {
21 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; 19 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
22 kern_return_t kr = task_info(mach_task_self(), 20 kern_return_t kr = task_info(mach_task_self(),
23 TASK_BASIC_INFO_64, 21 TASK_BASIC_INFO_64,
24 reinterpret_cast<task_info_t>(task_info_data), 22 reinterpret_cast<task_info_t>(task_info_data),
25 &count); 23 &count);
26 return kr == KERN_SUCCESS; 24 return kr == KERN_SUCCESS;
27 } 25 }
28 26
29 } // namespace 27 } // namespace
30 28
29 SystemMemoryInfoKB::SystemMemoryInfoKB() : total(0), free(0) {}
30
31 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) =
32 default;
33
31 ProcessMetrics::ProcessMetrics(ProcessHandle process) {} 34 ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
32 35
33 ProcessMetrics::~ProcessMetrics() {} 36 ProcessMetrics::~ProcessMetrics() {}
34 37
35 // static 38 // static
36 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( 39 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
37 ProcessHandle process) { 40 ProcessHandle process) {
38 return WrapUnique(new ProcessMetrics(process)); 41 return WrapUnique(new ProcessMetrics(process));
39 } 42 }
40 43
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 size_t GetPageSize() { 84 size_t GetPageSize() {
82 return getpagesize(); 85 return getpagesize();
83 } 86 }
84 87
85 // Bytes committed by the system. 88 // Bytes committed by the system.
86 size_t GetSystemCommitCharge() { 89 size_t GetSystemCommitCharge() {
87 NOTIMPLEMENTED(); 90 NOTIMPLEMENTED();
88 return 0; 91 return 0;
89 } 92 }
90 93
94 // Bytes committed by the system.
91 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 95 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
92 struct host_basic_info hostinfo; 96 // Unimplemented. Must enable unittest for IOS when this gets implemented.
93 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; 97 NOTIMPLEMENTED();
94 base::mac::ScopedMachSendRight host(mach_host_self()); 98 return false;
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;
125 } 99 }
126 100
127 } // namespace base 101 } // 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