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

Unified Diff: base/process_util_linux.cc

Issue 371025: More memory stats code cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: multiply uses by 1024 to keep stats consistent with old runs Created 11 years, 1 month 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
Index: base/process_util_linux.cc
===================================================================
--- base/process_util_linux.cc (revision 31329)
+++ base/process_util_linux.cc (working copy)
@@ -450,4 +450,50 @@
return percentage;
}
+namespace {
+
+// The format of /proc/meminfo is:
+//
+// MemTotal: 8235324 kB
+// MemFree: 1628304 kB
+// Buffers: 429596 kB
+// Cached: 4728232 kB
+// ...
+const size_t kMemTotalIndex = 1;
+const size_t kMemFreeIndex = 4;
+const size_t kMemBuffersIndex = 7;
+const size_t kMemCacheIndex = 10;
+
+} // namespace
+
+size_t GetSystemCommitCharge() {
+ // Used memory is: total - free - buffers - caches
+ FilePath meminfo_file("/proc/meminfo");
+ std::string meminfo_data;
+ if (!file_util::ReadFileToString(meminfo_file, &meminfo_data))
+ LOG(ERROR) << "Failed to open /proc/meminfo.";
vandebo (ex-Chrome) 2009/11/09 19:10:29 Should this be ERROR, or just WARNING? It doesn't
+ return 0;
+ std::vector<std::string> meminfo_fields;
+ SplitStringAlongWhitespace(meminfo_data, &meminfo_fields);
+
+ if (meminfo_fields.size() < kMemCacheIndex) {
+ LOG(ERROR) << "Failed to parse /proc/meminfo. Only found " <<
+ meminfo_fields.size() << " fields.";
+ return 0;
+ }
+
+ DCHECK_EQ(meminfo_fields[kMemTotalIndex-1], "MemTotal:");
+ DCHECK_EQ(meminfo_fields[kMemFreeIndex-1], "MemFree:");
+ DCHECK_EQ(meminfo_fields[kMemBuffersIndex-1], "Buffers:");
+ DCHECK_EQ(meminfo_fields[kMemCacheIndex-1], "Cached:");
+
+ size_t result_in_kb;
+ result_in_kb = StringToInt(meminfo_fields[kMemTotalIndex]);
+ result_in_kb -= StringToInt(meminfo_fields[kMemFreeIndex]);
+ result_in_kb -= StringToInt(meminfo_fields[kMemBuffersIndex]);
+ result_in_kb -= StringToInt(meminfo_fields[kMemCacheIndex]);
+
+ return result_in_kb;
+}
+
} // namespace base
« no previous file with comments | « base/process_util.h ('k') | base/process_util_mac.mm » ('j') | base/process_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698