| 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 #include <sys/sysinfo.h> |
| 8 | 9 |
| 9 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/sys_info_internal.h" | 14 #include "base/sys_info_internal.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 int64 AmountOfMemory(int pages_name) { | 18 int64 AmountOfMemory(int pages_name) { |
| 19 DCHECK(pages_name == _SC_PHYS_PAGES || pages_name == _SC_AVPHYS_PAGES); |
| 18 long pages = sysconf(pages_name); | 20 long pages = sysconf(pages_name); |
| 19 long page_size = sysconf(_SC_PAGESIZE); | 21 long page_size = sysconf(_SC_PAGESIZE); |
| 20 if (pages == -1 || page_size == -1) { | 22 if (pages == -1 || page_size == -1) { |
| 21 NOTREACHED(); | 23 struct sysinfo si; |
| 22 return 0; | 24 int ret = sysinfo(&si); |
| 25 DCHECK_EQ(ret, 0); |
| 26 if (pages_name == _SC_PHYS_PAGES) { |
| 27 return static_cast<int64>(si.totalram) * si.mem_unit; |
| 28 } else { |
| 29 // _SC_ACPHYS_PAGES |
| 30 return static_cast<int64>(si.freeram) * si.mem_unit; |
| 31 } |
| 23 } | 32 } |
| 24 return static_cast<int64>(pages) * page_size; | 33 return static_cast<int64>(pages) * page_size; |
| 25 } | 34 } |
| 26 | 35 |
| 27 int64 AmountOfPhysicalMemory() { | 36 int64 AmountOfPhysicalMemory() { |
| 28 return AmountOfMemory(_SC_PHYS_PAGES); | 37 return AmountOfMemory(_SC_PHYS_PAGES); |
| 29 } | 38 } |
| 30 | 39 |
| 31 size_t MaxSharedMemorySize() { | 40 size_t MaxSharedMemorySize() { |
| 32 std::string contents; | 41 std::string contents; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { | 99 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { |
| 91 size_t pos = line.find(": "); | 100 size_t pos = line.find(": "); |
| 92 return line.substr(pos + 2); | 101 return line.substr(pos + 2); |
| 93 } | 102 } |
| 94 } | 103 } |
| 95 } | 104 } |
| 96 return std::string(); | 105 return std::string(); |
| 97 } | 106 } |
| 98 | 107 |
| 99 } // namespace base | 108 } // namespace base |
| OLD | NEW |