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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_linux.cc
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index c698f911db516fdb3a178ecb9e1c15ac18e0ce35..5af8c270357b84b1e6da9279d5b3e6d1e2670049 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -5,6 +5,7 @@
#include "base/sys_info.h"
#include <limits>
+#include <sys/sysinfo.h>
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
@@ -15,11 +16,19 @@
namespace {
int64 AmountOfMemory(int pages_name) {
+ DCHECK(pages_name == _SC_PHYS_PAGES || pages_name == _SC_AVPHYS_PAGES);
long pages = sysconf(pages_name);
long page_size = sysconf(_SC_PAGESIZE);
if (pages == -1 || page_size == -1) {
- NOTREACHED();
- return 0;
+ struct sysinfo si;
+ int ret = sysinfo(&si);
+ DCHECK_EQ(ret, 0);
+ if (pages_name == _SC_PHYS_PAGES) {
+ return static_cast<int64>(si.totalram) * si.mem_unit;
+ } else {
+ // _SC_ACPHYS_PAGES
+ return static_cast<int64>(si.freeram) * si.mem_unit;
+ }
}
return static_cast<int64>(pages) * page_size;
}
« 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