| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <mach/mach.h> | 7 #include <mach/mach.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #import <UIKit/UIKit.h> | 12 #import <UIKit/UIKit.h> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/mac/scoped_mach_port.h" | 15 #include "base/mac/scoped_mach_port.h" |
| 16 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/process/process_metrics.h" | |
| 19 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 | 21 |
| 23 // static | 22 // static |
| 24 std::string SysInfo::OperatingSystemName() { | 23 std::string SysInfo::OperatingSystemName() { |
| 25 static dispatch_once_t get_system_name_once; | 24 static dispatch_once_t get_system_name_once; |
| 26 static std::string* system_name; | 25 static std::string* system_name; |
| 27 dispatch_once(&get_system_name_once, ^{ | 26 dispatch_once(&get_system_name_once, ^{ |
| 28 base::mac::ScopedNSAutoreleasePool pool; | 27 base::mac::ScopedNSAutoreleasePool pool; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (host_statistics(host.get(), |
| 90 HOST_VM_INFO, |
| 91 reinterpret_cast<host_info_t>(&vm_info), |
| 92 &count) != KERN_SUCCESS) { |
| 93 NOTREACHED(); |
| 89 return 0; | 94 return 0; |
| 90 // We should add inactive file-backed memory also but there is no such | 95 } |
| 91 // information from iOS unfortunately. | 96 |
| 92 return static_cast<int64_t>(info.free + info.speculative) * 1024; | 97 return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) * |
| 98 PAGE_SIZE; |
| 93 } | 99 } |
| 94 | 100 |
| 95 // static | 101 // static |
| 96 std::string SysInfo::CPUModelName() { | 102 std::string SysInfo::CPUModelName() { |
| 97 char name[256]; | 103 char name[256]; |
| 98 size_t len = arraysize(name); | 104 size_t len = arraysize(name); |
| 99 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) | 105 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) |
| 100 return name; | 106 return name; |
| 101 return std::string(); | 107 return std::string(); |
| 102 } | 108 } |
| 103 | 109 |
| 104 } // namespace base | 110 } // namespace base |
| OLD | NEW |