| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 NOTREACHED(); | 26 NOTREACHED(); |
| 27 return 0; | 27 return 0; |
| 28 } | 28 } |
| 29 return static_cast<int64_t>(pages) * page_size; | 29 return static_cast<int64_t>(pages) * page_size; |
| 30 } | 30 } |
| 31 | 31 |
| 32 int64_t AmountOfPhysicalMemory() { | 32 int64_t AmountOfPhysicalMemory() { |
| 33 return AmountOfMemory(_SC_PHYS_PAGES); | 33 return AmountOfMemory(_SC_PHYS_PAGES); |
| 34 } | 34 } |
| 35 | 35 |
| 36 uint64_t MaxSharedMemorySize() { | |
| 37 std::string contents; | |
| 38 base::ReadFileToString(base::FilePath("/proc/sys/kernel/shmmax"), &contents); | |
| 39 DCHECK(!contents.empty()); | |
| 40 if (!contents.empty() && contents.back() == '\n') { | |
| 41 contents.erase(contents.length() - 1); | |
| 42 } | |
| 43 | |
| 44 uint64_t limit; | |
| 45 if (!base::StringToUint64(contents, &limit)) { | |
| 46 limit = 0; | |
| 47 } | |
| 48 DCHECK_GT(limit, 0u); | |
| 49 return limit; | |
| 50 } | |
| 51 | |
| 52 base::LazyInstance< | 36 base::LazyInstance< |
| 53 base::internal::LazySysInfoValue<int64_t, AmountOfPhysicalMemory>>::Leaky | 37 base::internal::LazySysInfoValue<int64_t, AmountOfPhysicalMemory>>::Leaky |
| 54 g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER; | 38 g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER; |
| 55 base::LazyInstance< | |
| 56 base::internal::LazySysInfoValue<uint64_t, MaxSharedMemorySize>>::Leaky | |
| 57 g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER; | |
| 58 | 39 |
| 59 } // namespace | 40 } // namespace |
| 60 | 41 |
| 61 namespace base { | 42 namespace base { |
| 62 | 43 |
| 63 // static | 44 // static |
| 64 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { | 45 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { |
| 65 return AmountOfMemory(_SC_AVPHYS_PAGES); | 46 return AmountOfMemory(_SC_AVPHYS_PAGES); |
| 66 } | 47 } |
| 67 | 48 |
| 68 // static | 49 // static |
| 69 int64_t SysInfo::AmountOfPhysicalMemory() { | 50 int64_t SysInfo::AmountOfPhysicalMemory() { |
| 70 return g_lazy_physical_memory.Get().value(); | 51 return g_lazy_physical_memory.Get().value(); |
| 71 } | 52 } |
| 72 | 53 |
| 73 // static | 54 // static |
| 74 uint64_t SysInfo::MaxSharedMemorySize() { | |
| 75 return g_lazy_max_shared_memory.Get().value(); | |
| 76 } | |
| 77 | |
| 78 // static | |
| 79 std::string SysInfo::CPUModelName() { | 55 std::string SysInfo::CPUModelName() { |
| 80 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 56 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 81 const char kCpuModelPrefix[] = "Hardware"; | 57 const char kCpuModelPrefix[] = "Hardware"; |
| 82 #else | 58 #else |
| 83 const char kCpuModelPrefix[] = "model name"; | 59 const char kCpuModelPrefix[] = "model name"; |
| 84 #endif | 60 #endif |
| 85 std::string contents; | 61 std::string contents; |
| 86 ReadFileToString(FilePath("/proc/cpuinfo"), &contents); | 62 ReadFileToString(FilePath("/proc/cpuinfo"), &contents); |
| 87 DCHECK(!contents.empty()); | 63 DCHECK(!contents.empty()); |
| 88 if (!contents.empty()) { | 64 if (!contents.empty()) { |
| 89 std::istringstream iss(contents); | 65 std::istringstream iss(contents); |
| 90 std::string line; | 66 std::string line; |
| 91 while (std::getline(iss, line)) { | 67 while (std::getline(iss, line)) { |
| 92 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { | 68 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { |
| 93 size_t pos = line.find(": "); | 69 size_t pos = line.find(": "); |
| 94 return line.substr(pos + 2); | 70 return line.substr(pos + 2); |
| 95 } | 71 } |
| 96 } | 72 } |
| 97 } | 73 } |
| 98 return std::string(); | 74 return std::string(); |
| 99 } | 75 } |
| 100 | 76 |
| 101 } // namespace base | 77 } // namespace base |
| OLD | NEW |