diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 23:50:43 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 23:50:43 +0000 |
commit | b4d8f2090d0b2909c4929fbac253ad93376218f6 (patch) | |
tree | 889039eea401bc13981a1c066046b832a315ad1c /chrome/test/perf | |
parent | b0b96d8fb1904e3e1c95fc031a9947524b9803ce (diff) | |
download | chromium_src-b4d8f2090d0b2909c4929fbac253ad93376218f6.zip chromium_src-b4d8f2090d0b2909c4929fbac253ad93376218f6.tar.gz chromium_src-b4d8f2090d0b2909c4929fbac253ad93376218f6.tar.bz2 |
Implement the missing memory information functions that memory_test uses.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/266009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/perf')
-rw-r--r-- | chrome/test/perf/mem_usage_linux.cc | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/chrome/test/perf/mem_usage_linux.cc b/chrome/test/perf/mem_usage_linux.cc index 0d3b825..ec18d01 100644 --- a/chrome/test/perf/mem_usage_linux.cc +++ b/chrome/test/perf/mem_usage_linux.cc @@ -4,20 +4,73 @@ #include "chrome/test/perf/mem_usage.h" +#include "base/file_util.h" #include "base/logging.h" +#include "base/process_util.h" +#include "base/string_util.h" + +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 bool GetMemoryInfo(uint32 process_id, size_t* peak_virtual_size, size_t* current_virtual_size, size_t* peak_working_set_size, size_t* current_working_set_size) { - NOTIMPLEMENTED(); - return false; + if (!peak_virtual_size || !current_virtual_size) + return false; + + base::ProcessMetrics* metrics = + base::ProcessMetrics::CreateProcessMetrics(process_id); + *peak_virtual_size = metrics->GetPeakPagefileUsage(); + *current_virtual_size = metrics->GetPagefileUsage(); + *peak_working_set_size = metrics->GetPeakWorkingSetSize(); + *current_working_set_size = metrics->GetWorkingSetSize(); + delete metrics; + + return true; } size_t GetSystemCommitCharge() { - NOTIMPLEMENTED(); - return 0; + // Used memory is: total - free - buffers - caches + FilePath meminfo_file("/proc/meminfo"); + std::string meminfo_data; + if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) + 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:"); + + int 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 * 1024; } void PrintChromeMemoryUsageInfo() { |