Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: base/sys_info_linux.cc

Issue 1050233002: If sysconfig fails, fallback to sysinfo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to HEAD Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698