Invoke the iOS hook from TestSuite so each run_all_unittests.cc file does not
[chromium-blink-merge.git] / base / sys_info_linux.cc
blob09ac3d65d6d34adbb6ef9b2e2155c87994d6a4db
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"
7 #include <limits>
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
13 namespace base {
15 int64 SysInfo::AmountOfPhysicalMemory() {
16 long pages = sysconf(_SC_PHYS_PAGES);
17 long page_size = sysconf(_SC_PAGE_SIZE);
18 if (pages == -1 || page_size == -1) {
19 NOTREACHED();
20 return 0;
23 return static_cast<int64>(pages) * page_size;
26 // static
27 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
28 long available_pages = sysconf(_SC_AVPHYS_PAGES);
29 long page_size = sysconf(_SC_PAGE_SIZE);
30 if (available_pages == -1 || page_size == -1) {
31 NOTREACHED();
32 return 0;
34 return static_cast<int64>(available_pages) * page_size;
37 // static
38 size_t SysInfo::MaxSharedMemorySize() {
39 static int64 limit;
40 static bool limit_valid = false;
41 if (!limit_valid) {
42 std::string contents;
43 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
44 DCHECK(!contents.empty());
45 if (!contents.empty() && contents[contents.length() - 1] == '\n') {
46 contents.erase(contents.length() - 1);
48 if (base::StringToInt64(contents, &limit)) {
49 DCHECK(limit >= 0);
50 DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
51 limit_valid = true;
52 } else {
53 NOTREACHED();
54 return 0;
57 return static_cast<size_t>(limit);
60 // static
61 std::string SysInfo::CPUModelName() {
62 const char kModelNamePrefix[] = "model name";
63 std::string contents;
64 file_util::ReadFileToString(FilePath("/proc/cpuinfo"), &contents);
65 DCHECK(!contents.empty());
66 if (!contents.empty()) {
67 std::istringstream iss(contents);
68 std::string line;
69 while (std::getline(iss, line)){
70 if (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0) {
71 size_t pos = line.find(": ");
72 return line.substr(pos + 2);
76 return std::string();
79 } // namespace base