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

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: 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) {
18 long pages = sysconf(pages_name); 19 long pages = sysconf(pages_name);
danakj 2015/04/02 19:05:47 can you DCHECK up here that pages_name is _SC_PHYS
smcgruer2 2015/04/07 21:25:43 Done.
19 long page_size = sysconf(_SC_PAGESIZE); 20 long page_size = sysconf(_SC_PAGESIZE);
20 if (pages == -1 || page_size == -1) { 21 if (pages == -1 || page_size == -1) {
22 struct sysinfo si;
23 if (sysinfo(&si)) {
danakj 2015/04/02 19:05:47 on success 0 is returned. so this won't work right
smcgruer2 2015/04/07 21:25:43 Whoops! Good eye, the original code was checking '
24 if (pages_name == _SC_PHYS_PAGES) {
25 return si.totalram * si.mem_unit;
danakj 2015/04/02 19:05:47 can you cast the totalram to an int64 before multi
smcgruer2 2015/04/07 21:25:43 Done.
26 } else if (pages_name == _SC_AVPHYS_PAGES) {
danakj 2015/04/02 19:05:47 just else should be sufficient? (can leave ..AVPHY
smcgruer2 2015/04/07 21:25:43 Done.
27 return si.freeram * si.mem_unit;
danakj 2015/04/02 19:05:47 dittos
smcgruer2 2015/04/07 21:25:43 Done.
28 }
29 }
21 NOTREACHED(); 30 NOTREACHED();
danakj 2015/04/02 19:05:47 can you restructure this code so we don't have NOT
smcgruer2 2015/04/07 21:25:43 Done.
22 return 0; 31 return 0;
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() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { 106 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) {
98 size_t pos = line.find(": "); 107 size_t pos = line.find(": ");
99 return line.substr(pos + 2); 108 return line.substr(pos + 2);
100 } 109 }
101 } 110 }
102 } 111 }
103 return std::string(); 112 return std::string();
104 } 113 }
105 114
106 } // namespace base 115 } // 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