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

Side by Side Diff: base/sys_info_mac.mm

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/sys_info_linux.cc ('k') | base/sys_info_openbsd.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #include <mach/mach_host.h> 10 #include <mach/mach_host.h>
11 #include <mach/mach_init.h> 11 #include <mach/mach_init.h>
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 #include <sys/sysctl.h> 14 #include <sys/sysctl.h>
15 #include <sys/types.h> 15 #include <sys/types.h>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
19 #include "base/mac/scoped_mach_port.h" 19 #include "base/mac/scoped_mach_port.h"
20 #import "base/mac/sdk_forward_declarations.h" 20 #import "base/mac/sdk_forward_declarations.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/process/process_metrics.h"
23 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
24 23
25 namespace base { 24 namespace base {
26 25
27 // static 26 // static
28 std::string SysInfo::OperatingSystemName() { 27 std::string SysInfo::OperatingSystemName() {
29 return "Mac OS X"; 28 return "Mac OS X";
30 } 29 }
31 30
32 // static 31 // static
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (result != KERN_SUCCESS) { 76 if (result != KERN_SUCCESS) {
78 NOTREACHED(); 77 NOTREACHED();
79 return 0; 78 return 0;
80 } 79 }
81 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); 80 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
82 return static_cast<int64_t>(hostinfo.max_mem); 81 return static_cast<int64_t>(hostinfo.max_mem);
83 } 82 }
84 83
85 // static 84 // static
86 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { 85 int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
87 SystemMemoryInfoKB info; 86 base::mac::ScopedMachSendRight host(mach_host_self());
88 if (!GetSystemMemoryInfo(&info)) 87 vm_statistics_data_t vm_info;
88 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
89
90 if (host_statistics(host.get(),
91 HOST_VM_INFO,
92 reinterpret_cast<host_info_t>(&vm_info),
93 &count) != KERN_SUCCESS) {
94 NOTREACHED();
89 return 0; 95 return 0;
90 // We should add inactive file-backed memory also but there is no such 96 }
91 // information from Mac OS unfortunately. 97
92 return static_cast<int64_t>(info.free + info.speculative) * 1024; 98 return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) *
99 PAGE_SIZE;
93 } 100 }
94 101
95 // static 102 // static
96 std::string SysInfo::CPUModelName() { 103 std::string SysInfo::CPUModelName() {
97 char name[256]; 104 char name[256];
98 size_t len = arraysize(name); 105 size_t len = arraysize(name);
99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) 106 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
100 return name; 107 return name;
101 return std::string(); 108 return std::string();
102 } 109 }
103 110
104 std::string SysInfo::HardwareModelName() { 111 std::string SysInfo::HardwareModelName() {
105 char model[256]; 112 char model[256];
106 size_t len = sizeof(model); 113 size_t len = sizeof(model);
107 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) 114 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0)
108 return std::string(model, 0, len); 115 return std::string(model, 0, len);
109 return std::string(); 116 return std::string();
110 } 117 }
111 118
112 } // namespace base 119 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_linux.cc ('k') | base/sys_info_openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698