summaryrefslogtreecommitdiffstats
path: root/chrome/test/chrome_process_util_mac.cc
diff options
context:
space:
mode:
authorsgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-05 22:31:12 +0000
committersgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-05 22:31:12 +0000
commitb429982e9e25eafd853036f210c299a0ea56585a (patch)
tree24a3fd58ffc47e7db870d08723ce0244aebe15c0 /chrome/test/chrome_process_util_mac.cc
parent157d547807a2b9d0e42f17636ffc39336a9a62f6 (diff)
downloadchromium_src-b429982e9e25eafd853036f210c299a0ea56585a.zip
chromium_src-b429982e9e25eafd853036f210c299a0ea56585a.tar.gz
chromium_src-b429982e9e25eafd853036f210c299a0ea56585a.tar.bz2
Get rid of GetMemoryInfo() in favor of using base::ProcessMetrics.
Use a test-specific subclass to isolate the stopgap use of 'ps' to collect memory stats on Mac. BUG=none TEST=none Review URL: http://codereview.chromium.org/342070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/chrome_process_util_mac.cc')
-rw-r--r--chrome/test/chrome_process_util_mac.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/chrome/test/chrome_process_util_mac.cc b/chrome/test/chrome_process_util_mac.cc
index 9b12e9c..4c60ad3 100644
--- a/chrome/test/chrome_process_util_mac.cc
+++ b/chrome/test/chrome_process_util_mac.cc
@@ -100,3 +100,50 @@ MacChromeProcessInfoList GetRunningMacProcessInfo(
return result;
}
+
+// Common interface for fetching memory values from parsed ps output.
+// We fill in both values we may get called for, even though our
+// callers typically only care about one, just to keep the code
+// simple and because this is a test.
+static bool GetMemoryValuesHack(uint32 process_id,
+ size_t* virtual_size,
+ size_t* working_set_size) {
+ DCHECK(virtual_size && working_set_size);
+
+ std::vector<base::ProcessId> processes;
+ processes.push_back(process_id);
+
+ MacChromeProcessInfoList process_info = GetRunningMacProcessInfo(processes);
+ if (process_info.empty())
+ return false;
+
+ bool found_process = false;
+ *virtual_size = 0;
+ *working_set_size = 0;
+
+ MacChromeProcessInfoList::iterator it = process_info.begin();
+ for (; it != process_info.end(); ++it) {
+ if (it->pid != static_cast<base::ProcessId>(process_id))
+ continue;
+ found_process = true;
+ *virtual_size = it->vsz_in_kb * 1024;
+ *working_set_size = it->rsz_in_kb * 1024;
+ break;
+ }
+
+ return found_process;
+}
+
+size_t ChromeTestProcessMetrics::GetPagefileUsage() {
+ size_t virtual_size;
+ size_t working_set_size;
+ GetMemoryValuesHack(process_handle_, &virtual_size, &working_set_size);
+ return virtual_size;
+}
+
+size_t ChromeTestProcessMetrics::GetWorkingSetSize() {
+ size_t virtual_size;
+ size_t working_set_size;
+ GetMemoryValuesHack(process_handle_, &virtual_size, &working_set_size);
+ return working_set_size;
+}