1 // Copyright (c) 2011 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"
9 #include <sys/sysctl.h>
11 #include "base/logging.h"
15 int64
AmountOfMemory(int pages_name
) {
16 long pages
= sysconf(pages_name
);
17 long page_size
= sysconf(_SC_PAGESIZE
);
18 if (pages
== -1 || page_size
== -1) {
22 return static_cast<int64
>(pages
) * page_size
;
30 int SysInfo::NumberOfProcessors() {
31 int mib
[] = { CTL_HW
, HW_NCPU
};
33 size_t size
= sizeof(ncpu
);
34 if (sysctl(mib
, arraysize(mib
), &ncpu
, &size
, NULL
, 0) < 0) {
42 int64
SysInfo::AmountOfPhysicalMemory() {
43 return AmountOfMemory(_SC_PHYS_PAGES
);
47 int64
SysInfo::AmountOfAvailablePhysicalMemory() {
48 return AmountOfMemory(_SC_AVPHYS_PAGES
);
52 size_t SysInfo::MaxSharedMemorySize() {
53 int mib
[] = { CTL_KERN
, KERN_SHMINFO
, KERN_SHMINFO_SHMMAX
};
55 size_t size
= sizeof(limit
);
56 if (sysctl(mib
, arraysize(mib
), &limit
, &size
, NULL
, 0) < 0) {
64 std::string
SysInfo::CPUModelName() {
65 int mib
[] = { CTL_HW
, HW_MODEL
};
67 size_t len
= arraysize(name
);
68 if (sysctl(mib
, arraysize(mib
), name
, &len
, NULL
, 0) < 0) {