summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authorsgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 06:57:28 +0000
committersgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 06:57:28 +0000
commited26d948be84443236a8a165ac2a3ccf63c2e02a (patch)
treea41de5ad3954557cbf9a7b0e1bc61c923fc05269 /base/process_util_linux.cc
parentad33fd4bdd8b7117e2644b34f553a2f14faea653 (diff)
downloadchromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.zip
chromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.tar.gz
chromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.tar.bz2
More memory stats code cleanup:
Move GetSystemCommitCharge() into bsae\process_util*. Kill PrintChromeMemoryUsageInfo(), which was only used by reliability_tests.exe on Windows and whose stats are obsolete. Delete the now-unnecessary chrome\test\perf\mem_usage* files. BUG=none TEST=none Review URL: http://codereview.chromium.org/371025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 7c78f6f..455af3e 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -450,4 +450,50 @@ int ProcessMetrics::GetCPUUsage() {
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.";
+ 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