blob: 2911c7c4ce38a15adf9a6ebc5b4f839ac27d8c5a [file] [log] [blame]
[email protected]c6d5f8c2012-07-11 12:15:081// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]71aa16c2009-02-24 16:37:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/sys_info.h"
6
[email protected]c8587632009-11-12 02:17:197#include <ApplicationServices/ApplicationServices.h>
[email protected]71aa16c2009-02-24 16:37:138#include <CoreServices/CoreServices.h>
[email protected]c8587632009-11-12 02:17:199#include <mach/mach_host.h>
10#include <mach/mach_init.h>
[email protected]d5df0c8c2012-09-08 09:53:0111#include <sys/sysctl.h>
12#include <sys/types.h>
[email protected]c8587632009-11-12 02:17:1913
14#include "base/logging.h"
[email protected]431d0a12012-10-16 20:17:5815#include "base/mac/scoped_mach_port.h"
[email protected]c851cfd2013-06-10 20:11:1416#include "base/strings/stringprintf.h"
[email protected]71aa16c2009-02-24 16:37:1317
18namespace base {
19
20// static
[email protected]6e001bb2011-05-25 20:53:1821std::string SysInfo::OperatingSystemName() {
22 return "Mac OS X";
23}
24
25// static
26std::string SysInfo::OperatingSystemVersion() {
27 int32 major, minor, bugfix;
28 OperatingSystemVersionNumbers(&major, &minor, &bugfix);
29 return base::StringPrintf("%d.%d.%d", major, minor, bugfix);
30}
31
32// static
[email protected]f481221192011-04-07 22:15:3433void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
34 int32* minor_version,
35 int32* bugfix_version) {
[email protected]0203ed72009-07-02 13:59:0836 Gestalt(gestaltSystemVersionMajor,
[email protected]3a3e5b32009-08-21 22:30:4737 reinterpret_cast<SInt32*>(major_version));
[email protected]0203ed72009-07-02 13:59:0838 Gestalt(gestaltSystemVersionMinor,
[email protected]3a3e5b32009-08-21 22:30:4739 reinterpret_cast<SInt32*>(minor_version));
[email protected]0203ed72009-07-02 13:59:0840 Gestalt(gestaltSystemVersionBugFix,
[email protected]3a3e5b32009-08-21 22:30:4741 reinterpret_cast<SInt32*>(bugfix_version));
[email protected]71aa16c2009-02-24 16:37:1342}
43
[email protected]c8587632009-11-12 02:17:1944// static
45int64 SysInfo::AmountOfPhysicalMemory() {
46 struct host_basic_info hostinfo;
47 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
[email protected]431d0a12012-10-16 20:17:5848 base::mac::ScopedMachPort host(mach_host_self());
49 int result = host_info(host,
[email protected]c8587632009-11-12 02:17:1950 HOST_BASIC_INFO,
51 reinterpret_cast<host_info_t>(&hostinfo),
52 &count);
[email protected]c8587632009-11-12 02:17:1953 if (result != KERN_SUCCESS) {
54 NOTREACHED();
55 return 0;
56 }
[email protected]c6d5f8c2012-07-11 12:15:0857 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
[email protected]c8587632009-11-12 02:17:1958 return static_cast<int64>(hostinfo.max_mem);
59}
60
[email protected]d5df0c8c2012-09-08 09:53:0161// static
[email protected]52bdcda2012-10-27 06:10:3762int64 SysInfo::AmountOfAvailablePhysicalMemory() {
[email protected]e6085c32012-11-07 06:58:1463 base::mac::ScopedMachPort host(mach_host_self());
64 vm_statistics_data_t vm_info;
65 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
66
67 if (host_statistics(host.get(),
68 HOST_VM_INFO,
69 reinterpret_cast<host_info_t>(&vm_info),
70 &count) != KERN_SUCCESS) {
71 NOTREACHED();
72 return 0;
73 }
74
[email protected]14b67a52012-11-12 16:23:5875 return static_cast<int64>(
76 vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE;
[email protected]52bdcda2012-10-27 06:10:3777}
78
79// static
[email protected]d5df0c8c2012-09-08 09:53:0180std::string SysInfo::CPUModelName() {
81 char name[256];
82 size_t len = arraysize(name);
83 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
84 return name;
85 return std::string();
86}
87
[email protected]71aa16c2009-02-24 16:37:1388} // namespace base