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
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #import <UIKit/UIKit.h>
9 #include <sys/sysctl.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/mac/scoped_mach_port.h"
14 #include "base/mac/scoped_nsautorelease_pool.h"
15 #include "base/strings/sys_string_conversions.h"
19 bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) {
20 // Find a case where this is incorrect and dbeam@ will buy you a beer.
21 *has_seek_penalty = false;
26 std::string SysInfo::OperatingSystemName() {
27 static dispatch_once_t get_system_name_once;
28 static std::string* system_name;
29 dispatch_once(&get_system_name_once, ^{
30 base::mac::ScopedNSAutoreleasePool pool;
31 system_name = new std::string(
32 SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
34 // Examples of returned value: 'iPhone OS' on iPad 5.1.1
40 std::string SysInfo::OperatingSystemVersion() {
41 static dispatch_once_t get_system_version_once;
42 static std::string* system_version;
43 dispatch_once(&get_system_version_once, ^{
44 base::mac::ScopedNSAutoreleasePool pool;
45 system_version = new std::string(
46 SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
48 return *system_version;
52 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
54 int32* bugfix_version) {
55 base::mac::ScopedNSAutoreleasePool pool;
56 std::string system_version = OperatingSystemVersion();
57 if (!system_version.empty()) {
58 // Try to parse out the version numbers from the string.
59 int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
60 minor_version, bugfix_version);
71 int64 SysInfo::AmountOfPhysicalMemory() {
72 struct host_basic_info hostinfo;
73 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
74 base::mac::ScopedMachSendRight host(mach_host_self());
75 int result = host_info(host,
77 reinterpret_cast<host_info_t>(&hostinfo),
79 if (result != KERN_SUCCESS) {
83 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
84 return static_cast<int64>(hostinfo.max_mem);
88 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
89 base::mac::ScopedMachSendRight host(mach_host_self());
90 vm_statistics_data_t vm_info;
91 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
92 if (host_statistics(host.get(),
94 reinterpret_cast<host_info_t>(&vm_info),
95 &count) != KERN_SUCCESS) {
100 return static_cast<int64>(
101 vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE;
105 std::string SysInfo::CPUModelName() {
107 size_t len = arraysize(name);
108 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
110 return std::string();