diff options
author | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 22:31:12 +0000 |
---|---|---|
committer | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 22:31:12 +0000 |
commit | b429982e9e25eafd853036f210c299a0ea56585a (patch) | |
tree | 24a3fd58ffc47e7db870d08723ce0244aebe15c0 /chrome/test/perf | |
parent | 157d547807a2b9d0e42f17636ffc39336a9a62f6 (diff) | |
download | chromium_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/perf')
-rw-r--r-- | chrome/test/perf/mem_usage.h | 29 | ||||
-rw-r--r-- | chrome/test/perf/mem_usage_linux.cc | 19 | ||||
-rw-r--r-- | chrome/test/perf/mem_usage_mac.cc | 37 | ||||
-rw-r--r-- | chrome/test/perf/mem_usage_win.cc | 78 |
4 files changed, 31 insertions, 132 deletions
diff --git a/chrome/test/perf/mem_usage.h b/chrome/test/perf/mem_usage.h index 7d76a65..90a4824 100644 --- a/chrome/test/perf/mem_usage.h +++ b/chrome/test/perf/mem_usage.h @@ -7,35 +7,6 @@ #include "base/basictypes.h" -// Get memory information for the process with given process ID. -// -// The Windows psapi provides memory information of a process through structure -// RPROCESS_MEMORY_COUNTERS_EX. Relevant fields are: -// PagefileUsage: private (not shared) committed virtual space in process. -// This is "VM Size" in task manager processes tab. -// PeakPagefileUsage: peak value of PagefileUsage. -// WorkingSetSize: physical memory allocated to process including shared pages. -// This is "Memory Usage" in task manager processes tab. -// Contrary to its name, this value is not much useful for -// tracking the memory demand of an application. -// PeakWorkingSetSize: peak value of WorkingSetSize. -// This is "Peak Memory Usage" in task manager processes -// tab. -// PrivateUsage: The current amount of memory that cannot be shared with other -// processes. Private bytes include memory that is committed and -// marked MEM_PRIVATE, data that is not mapped, and executable -// pages that have been written to. It usually gives the same -// value as PagefileUsage. No equivalent part in task manager. -// -// The measurements we use are PagefileUsage (returned by current_virtual_size) -// and PeakPagefileUsage (returned by peak_virtual_size), Working Set and -// Peak working Set. -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); - // Get the number of bytes currently committed by the system. // Returns -1 on failure. size_t GetSystemCommitCharge(); diff --git a/chrome/test/perf/mem_usage_linux.cc b/chrome/test/perf/mem_usage_linux.cc index ec18d01..568b4fc 100644 --- a/chrome/test/perf/mem_usage_linux.cc +++ b/chrome/test/perf/mem_usage_linux.cc @@ -25,25 +25,6 @@ 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) { - 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() { // Used memory is: total - free - buffers - caches FilePath meminfo_file("/proc/meminfo"); diff --git a/chrome/test/perf/mem_usage_mac.cc b/chrome/test/perf/mem_usage_mac.cc index 4cc9ef6..90d87e5 100644 --- a/chrome/test/perf/mem_usage_mac.cc +++ b/chrome/test/perf/mem_usage_mac.cc @@ -12,43 +12,6 @@ #include "base/process_util.h" #include "chrome/test/chrome_process_util.h" -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) { - DCHECK(current_virtual_size && current_working_set_size); - - // Mac doesn't support retrieving peak sizes. - if (peak_virtual_size) - *peak_virtual_size = 0; - if (peak_working_set_size) - *peak_working_set_size = 0; - - 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; - *current_virtual_size = 0; - *current_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; - *current_virtual_size = it->vsz_in_kb * 1024; - *current_working_set_size = it->rsz_in_kb * 1024; - break; - } - - return found_process; -} - // Bytes committed by the system. size_t GetSystemCommitCharge() { host_name_port_t host = mach_host_self(); diff --git a/chrome/test/perf/mem_usage_win.cc b/chrome/test/perf/mem_usage_win.cc index 8759c97..465b602 100644 --- a/chrome/test/perf/mem_usage_win.cc +++ b/chrome/test/perf/mem_usage_win.cc @@ -10,40 +10,11 @@ #include "base/file_path.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/scoped_ptr.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/chrome_process_util.h" -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) { - if (!peak_virtual_size || !current_virtual_size) - return false; - - HANDLE process_handle = OpenProcess(PROCESS_QUERY_INFORMATION | - PROCESS_VM_READ, - FALSE, process_id); - if (!process_handle) - return false; - - PROCESS_MEMORY_COUNTERS_EX pmc; - bool result = false; - if (GetProcessMemoryInfo(process_handle, - reinterpret_cast<PPROCESS_MEMORY_COUNTERS>(&pmc), - sizeof(pmc))) { - *peak_virtual_size = pmc.PeakPagefileUsage; - *current_virtual_size = pmc.PagefileUsage; - *peak_working_set_size = pmc.PeakWorkingSetSize; - *current_working_set_size = pmc.WorkingSetSize; - result = true; - } - - CloseHandle(process_handle); - return result; -} - // GetPerformanceInfo is not available on WIN2K. So we'll // load it on-the-fly. const wchar_t kPsapiDllName[] = L"psapi.dll"; @@ -91,23 +62,36 @@ void PrintChromeMemoryUsageInfo() { ChromeProcessList::const_iterator it; for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { - size_t peak_virtual_size; - size_t current_virtual_size; - size_t peak_working_set_size; - size_t current_working_set_size; - if (GetMemoryInfo(*it, &peak_virtual_size, ¤t_virtual_size, - &peak_working_set_size, ¤t_working_set_size)) { - if (*it == browser_process_pid) { - wprintf(L"browser_vm_peak = %d\n", peak_virtual_size); - wprintf(L"browser_vm_current = %d\n", current_virtual_size); - wprintf(L"browser_ws_peak = %d\n", peak_working_set_size); - wprintf(L"browser_ws_final = %d\n", current_working_set_size); - } else { - wprintf(L"render_vm_peak = %d\n", peak_virtual_size); - wprintf(L"render_vm_current = %d\n", current_virtual_size); - wprintf(L"render_ws_peak = %d\n", peak_working_set_size); - wprintf(L"render_ws_final = %d\n", current_working_set_size); - } + base::ProcessHandle process_handle; + if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) { + NOTREACHED(); + } + + // TODO(sgk): if/when base::ProcessMetrics can return real memory + // stats on mac, convert to: + // + // scoped_ptr<base::ProcessMetrics> process_metrics; + // process_metrics.reset( + // base::ProcessMetrics::CreateProcessMetrics(process_handle)); + scoped_ptr<ChromeTestProcessMetrics> process_metrics; + process_metrics.reset( + ChromeTestProcessMetrics::CreateProcessMetrics(process_handle)); + + size_t peak_virtual_size = process_metrics->GetPeakPagefileUsage(); + size_t current_virtual_size = process_metrics->GetPagefileUsage(); + size_t peak_working_set_size = process_metrics->GetPeakWorkingSetSize(); + size_t current_working_set_size = process_metrics->GetWorkingSetSize(); + + if (*it == browser_process_pid) { + wprintf(L"browser_vm_peak = %d\n", peak_virtual_size); + wprintf(L"browser_vm_current = %d\n", current_virtual_size); + wprintf(L"browser_ws_peak = %d\n", peak_working_set_size); + wprintf(L"browser_ws_final = %d\n", current_working_set_size); + } else { + wprintf(L"render_vm_peak = %d\n", peak_virtual_size); + wprintf(L"render_vm_current = %d\n", current_virtual_size); + wprintf(L"render_ws_peak = %d\n", peak_working_set_size); + wprintf(L"render_ws_final = %d\n", current_working_set_size); } }; } |