diff options
author | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 22:37:41 +0000 |
---|---|---|
committer | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 22:37:41 +0000 |
commit | 4c31562ae80bddc4c2f9358e9dac69202157188f (patch) | |
tree | d64ca90e20fdf549c9b9cd07028fa1fd389d964a /chrome | |
parent | ac01d9228f3d4d7c78eac683c02ba5c494974b59 (diff) | |
download | chromium_src-4c31562ae80bddc4c2f9358e9dac69202157188f.zip chromium_src-4c31562ae80bddc4c2f9358e9dac69202157188f.tar.gz chromium_src-4c31562ae80bddc4c2f9358e9dac69202157188f.tar.bz2 |
Second part of memory_test for Mac.
This CL implements the actual memory measurements.
BUG=16434 (http://crbug.com/16434)
TEST=memory_test should now run and report accurate memory numbers on Mac.
Review URL: http://codereview.chromium.org/173454
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/test/memory_test/memory_test.cc | 7 | ||||
-rw-r--r-- | chrome/test/perf/mem_usage_mac.cc | 54 |
2 files changed, 52 insertions, 9 deletions
diff --git a/chrome/test/memory_test/memory_test.cc b/chrome/test/memory_test/memory_test.cc index 42f66f4..014d601 100644 --- a/chrome/test/memory_test/memory_test.cc +++ b/chrome/test/memory_test/memory_test.cc @@ -321,10 +321,7 @@ class MemoryTest : public UITest { printf("\n"); FilePath data_dir(user_data_dir()); - int browser_process_pid = 0; -#if defined(OS_WIN) - browser_process_pid = ChromeBrowserProcessId(data_dir); -#endif + int browser_process_pid = ChromeBrowserProcessId(data_dir); ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); size_t browser_virtual_size = 0; @@ -376,7 +373,7 @@ class MemoryTest : public UITest { // Output: // On success, modifies user_data_dir_ to be a new profile directory // and sets cleanup_temp_dir_on_exit_ to true. - bool SetupTempDirectory(const FilePath &src_dir) { + bool SetupTempDirectory(const FilePath& src_dir) { LOG(INFO) << "Setting up temp directory in " << src_dir.value(); // We create a copy of the test dir and use it so that each // run of this test starts with the same data. Running this diff --git a/chrome/test/perf/mem_usage_mac.cc b/chrome/test/perf/mem_usage_mac.cc index 671c989..4cc9ef6 100644 --- a/chrome/test/perf/mem_usage_mac.cc +++ b/chrome/test/perf/mem_usage_mac.cc @@ -6,20 +6,66 @@ #include <mach/mach.h> +#include <vector> + #include "base/logging.h" +#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) { - NOTIMPLEMENTED(); - return false; + 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() { - NOTIMPLEMENTED(); - return 0; + host_name_port_t host = mach_host_self(); + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_statistics_data_t data; + kern_return_t kr = host_statistics(host, HOST_VM_INFO, + reinterpret_cast<host_info_t>(&data), + &count); + if (kr) + return 0; + + vm_size_t page_size; + kr = host_page_size(host, &page_size); + if (kr) + return 0; + + return data.active_count * page_size; } void PrintChromeMemoryUsageInfo() { |