Chromium Code Reviews| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace { |
| 14 | 14 |
| 15 int64 SysInfo::AmountOfPhysicalMemory() { | 15 int64 AmountOfMemory(int pages_name) { |
| 16 long pages = sysconf(_SC_PHYS_PAGES); | 16 long pages = sysconf(pages_name); |
| 17 long page_size = sysconf(_SC_PAGE_SIZE); | 17 long page_size = sysconf(_SC_PAGESIZE); |
|
mdempsky_google
2013/04/09 21:45:09
I intentionally changed this from _SC_PAGE_SIZE to
| |
| 18 if (pages == -1 || page_size == -1) { | 18 if (pages == -1 || page_size == -1) { |
| 19 NOTREACHED(); | 19 NOTREACHED(); |
| 20 return 0; | 20 return 0; |
| 21 } | 21 } |
| 22 return static_cast<int64>(pages) * page_size; | |
| 23 } | |
| 22 | 24 |
| 23 return static_cast<int64>(pages) * page_size; | 25 } // namespace |
| 26 | |
| 27 namespace base { | |
| 28 | |
| 29 // static | |
| 30 int64 SysInfo::AmountOfPhysicalMemory() { | |
| 31 return AmountOfMemory(_SC_PHYS_PAGES); | |
| 24 } | 32 } |
| 25 | 33 |
| 26 // static | 34 // static |
| 27 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 35 int64 SysInfo::AmountOfAvailablePhysicalMemory() { |
| 28 long available_pages = sysconf(_SC_AVPHYS_PAGES); | 36 return AmountOfMemory(_SC_AVPHYS_PAGES); |
| 29 long page_size = sysconf(_SC_PAGE_SIZE); | |
| 30 if (available_pages == -1 || page_size == -1) { | |
| 31 NOTREACHED(); | |
| 32 return 0; | |
| 33 } | |
| 34 return static_cast<int64>(available_pages) * page_size; | |
| 35 } | 37 } |
| 36 | 38 |
| 37 // static | 39 // static |
| 38 size_t SysInfo::MaxSharedMemorySize() { | 40 size_t SysInfo::MaxSharedMemorySize() { |
| 39 static int64 limit; | 41 static int64 limit; |
| 40 static bool limit_valid = false; | 42 static bool limit_valid = false; |
| 41 if (!limit_valid) { | 43 if (!limit_valid) { |
| 42 std::string contents; | 44 std::string contents; |
| 43 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | 45 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); |
| 44 DCHECK(!contents.empty()); | 46 DCHECK(!contents.empty()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 70 if (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0) { | 72 if (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0) { |
| 71 size_t pos = line.find(": "); | 73 size_t pos = line.find(": "); |
| 72 return line.substr(pos + 2); | 74 return line.substr(pos + 2); |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 return std::string(); | 78 return std::string(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 } // namespace base | 81 } // namespace base |
| OLD | NEW |