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 "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.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 int64
SysInfo::AmountOfPhysicalMemory() {
31 return AmountOfMemory(_SC_PHYS_PAGES
);
35 int64
SysInfo::AmountOfAvailablePhysicalMemory() {
36 return AmountOfMemory(_SC_AVPHYS_PAGES
);
40 size_t SysInfo::MaxSharedMemorySize() {
42 static bool limit_valid
= false;
45 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents
);
46 DCHECK(!contents
.empty());
47 if (!contents
.empty() && contents
[contents
.length() - 1] == '\n') {
48 contents
.erase(contents
.length() - 1);
50 if (base::StringToInt64(contents
, &limit
)) {
52 DCHECK(static_cast<uint64
>(limit
) <= std::numeric_limits
<size_t>::max());
59 return static_cast<size_t>(limit
);
63 std::string
SysInfo::CPUModelName() {
64 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
65 const char kCpuModelPrefix
[] = "Hardware";
67 const char kCpuModelPrefix
[] = "model name";
70 file_util::ReadFileToString(FilePath("/proc/cpuinfo"), &contents
);
71 DCHECK(!contents
.empty());
72 if (!contents
.empty()) {
73 std::istringstream
iss(contents
);
75 while (std::getline(iss
, line
)) {
76 if (line
.compare(0, strlen(kCpuModelPrefix
), kCpuModelPrefix
) == 0) {
77 size_t pos
= line
.find(": ");
78 return line
.substr(pos
+ 2);