OLD | NEW |
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" |
22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 | 26 |
26 // static | 27 // static |
27 std::string SysInfo::OperatingSystemName() { | 28 std::string SysInfo::OperatingSystemName() { |
28 return "Mac OS X"; | 29 return "Mac OS X"; |
29 } | 30 } |
30 | 31 |
31 // static | 32 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (result != KERN_SUCCESS) { | 77 if (result != KERN_SUCCESS) { |
77 NOTREACHED(); | 78 NOTREACHED(); |
78 return 0; | 79 return 0; |
79 } | 80 } |
80 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 81 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
81 return static_cast<int64_t>(hostinfo.max_mem); | 82 return static_cast<int64_t>(hostinfo.max_mem); |
82 } | 83 } |
83 | 84 |
84 // static | 85 // static |
85 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { | 86 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { |
86 base::mac::ScopedMachSendRight host(mach_host_self()); | 87 SystemMemoryInfoKB info; |
87 vm_statistics_data_t vm_info; | 88 if (!GetSystemMemoryInfo(&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 NOTREACHED(); |
95 return 0; | 90 return 0; |
96 } | 91 } |
97 | 92 // We should add inactive file-backed memory also but there is no such |
98 return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) * | 93 // information from Mac OS unfortunately. |
99 PAGE_SIZE; | 94 return static_cast<int64_t>(info.free + info.speculative) * 1024; |
100 } | 95 } |
101 | 96 |
102 // static | 97 // static |
103 std::string SysInfo::CPUModelName() { | 98 std::string SysInfo::CPUModelName() { |
104 char name[256]; | 99 char name[256]; |
105 size_t len = arraysize(name); | 100 size_t len = arraysize(name); |
106 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) | 101 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) |
107 return name; | 102 return name; |
108 return std::string(); | 103 return std::string(); |
109 } | 104 } |
110 | 105 |
111 std::string SysInfo::HardwareModelName() { | 106 std::string SysInfo::HardwareModelName() { |
112 char model[256]; | 107 char model[256]; |
113 size_t len = sizeof(model); | 108 size_t len = sizeof(model); |
114 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) | 109 if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) |
115 return std::string(model, 0, len); | 110 return std::string(model, 0, len); |
116 return std::string(); | 111 return std::string(); |
117 } | 112 } |
118 | 113 |
119 } // namespace base | 114 } // namespace base |
OLD | NEW |