diff options
author | sgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 20:48:04 +0000 |
---|---|---|
committer | sgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 20:48:04 +0000 |
commit | 08f0a19132581e09be48b13933ec2a90813fd052 (patch) | |
tree | 0e799425dfa581866b0e6514b6cfecc4172c8be8 /chrome/test/ui | |
parent | 2775cce1a62be565e13d85b49d5fa110c02f0e78 (diff) | |
download | chromium_src-08f0a19132581e09be48b13933ec2a90813fd052.zip chromium_src-08f0a19132581e09be48b13933ec2a90813fd052.tar.gz chromium_src-08f0a19132581e09be48b13933ec2a90813fd052.tar.bz2 |
Prep for printing common memory stats from page_cycler_tests and memory_test:
Move PrintIOPerfInfo(), PrintMemoryUsageInfo() and PrintSystemCommitCharge()
into the UITest base class so both page_cycler and memory_test will be
able to use them. Make the user data dir a parameter so that memory_test
will be able to point to its temporary copy.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/402052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui')
-rw-r--r-- | chrome/test/ui/ui_test.cc | 154 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.h | 9 |
2 files changed, 163 insertions, 0 deletions
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index f2cbd37..8a8efb0 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -1178,3 +1178,157 @@ void UITest::UpdateHistoryDates() { db.Close(); file_util::EvictFileFromSystemCache(history); } + +void UITest::PrintIOPerfInfo(const char* test_name, FilePath data_dir) { + int browser_process_pid = ChromeBrowserProcessId(data_dir); + ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); + + ChromeProcessList::const_iterator it; + for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { + base::ProcessHandle process_handle; + if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) { + NOTREACHED(); + return; + } + + scoped_ptr<base::ProcessMetrics> process_metrics( + base::ProcessMetrics::CreateProcessMetrics(process_handle)); + IoCounters io_counters; + memset(&io_counters, 0, sizeof(io_counters)); + + if (process_metrics.get()->GetIOCounters(&io_counters)) { + // Print out IO performance. We assume that the values can be + // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). + std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; + + PrintResult("read_op", chrome_name, + "r_op" + chrome_name + test_name, + static_cast<size_t>(io_counters.ReadOperationCount), "", + false /* not important */); + PrintResult("write_op", chrome_name, + "w_op" + chrome_name + test_name, + static_cast<size_t>(io_counters.WriteOperationCount), "", + false /* not important */); + PrintResult("other_op", chrome_name, + "o_op" + chrome_name + test_name, + static_cast<size_t>(io_counters.OtherOperationCount), "", + false /* not important */); + + size_t total = static_cast<size_t>(io_counters.ReadOperationCount + + io_counters.WriteOperationCount + + io_counters.OtherOperationCount); + PrintResult("total_op", chrome_name, + "IO_op" + chrome_name + test_name, + total, "", true /* important */); + + PrintResult("read_byte", chrome_name, + "r_b" + chrome_name + test_name, + static_cast<size_t>(io_counters.ReadTransferCount / 1024), + "kb", false /* not important */); + PrintResult("write_byte", chrome_name, + "w_b" + chrome_name + test_name, + static_cast<size_t>(io_counters.WriteTransferCount / 1024), + "kb", false /* not important */); + PrintResult("other_byte", chrome_name, + "o_b" + chrome_name + test_name, + static_cast<size_t>(io_counters.OtherTransferCount / 1024), + "kb", false /* not important */); + + total = static_cast<size_t>((io_counters.ReadTransferCount + + io_counters.WriteTransferCount + + io_counters.OtherTransferCount) / 1024); + PrintResult("total_byte", chrome_name, + "IO_b" + chrome_name + test_name, + total, "kb", true /* important */); + } + + base::CloseProcessHandle(process_handle); + } +} + +void UITest::PrintMemoryUsageInfo(const char* test_name, FilePath data_dir) { + int browser_process_pid = ChromeBrowserProcessId(data_dir); + ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); + +#if !defined(OS_MACOSX) + ChromeProcessList::const_iterator it; + for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { + base::ProcessHandle process_handle; + if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) { + NOTREACHED(); + return; + } + + scoped_ptr<base::ProcessMetrics> process_metrics( + base::ProcessMetrics::CreateProcessMetrics(process_handle)); + + std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; + + std::string trace_name(test_name); +#if defined(OS_WIN) + PrintResult("vm_peak", chrome_name, + "vm_pk" + chrome_name + trace_name, + process_metrics->GetPeakPagefileUsage(), "bytes", + true /* important */); + PrintResult("vm_final", chrome_name, + "vm_f" + chrome_name + trace_name, + process_metrics->GetPagefileUsage(), "bytes", + false /* not important */); + PrintResult("ws_peak", chrome_name, + "ws_pk" + chrome_name + trace_name, + process_metrics->GetPeakWorkingSetSize(), "bytes", + true /* important */); + PrintResult("ws_final", chrome_name, + "ws_f" + chrome_name + trace_name, + process_metrics->GetWorkingSetSize(), "bytes", + false /* not important */); +#elif defined(OS_LINUX) + PrintResult("vm_size_final", chrome_name, + "vm_size_f" + chrome_name + trace_name, + process_metrics->GetPagefileUsage(), "bytes", + true /* important */); + PrintResult("vm_rss_final", chrome_name, + "vm_rss_f" + chrome_name + trace_name, + process_metrics->GetWorkingSetSize(), "bytes", + true /* important */); +#else + NOTIMPLEMENTED(); +#endif + base::CloseProcessHandle(process_handle); + } + +#else // !defined(OS_MACOSX) + + // There is no way to get memory info from one process on another process + // without privileges, this means the base methods for doing this can't be + // made to work. Instead we use a helper that invokes ps to collect the + // data so we have it for the unittest. + + MacChromeProcessInfoList process_infos( + GetRunningMacProcessInfo(chrome_processes)); + MacChromeProcessInfoList::const_iterator it; + for (it = process_infos.begin(); it != process_infos.end(); ++it) { + const MacChromeProcessInfo &process_info = *it; + + std::string chrome_name = + (process_info.pid == browser_process_pid) ? "_b" : "_r"; + std::string trace_name(test_name); + + PrintResult("vm_size_final", chrome_name, + "vm_size_f" + chrome_name + trace_name, + static_cast<size_t>(process_info.vsz_in_kb) * 1024, "bytes", + true /* important */); + PrintResult("vm_rss_final", chrome_name, + "vm_rss_f" + chrome_name + trace_name, + static_cast<size_t>(process_info.rsz_in_kb) * 1024, "bytes", + true /* important */); + } + +#endif // !defined(OS_MACOSX) +} + +void UITest::PrintSystemCommitCharge(const char* test_name, size_t charge) { + std::string trace_name(test_name); + PrintResult("commit_charge", "", "cc" + trace_name, charge, "kb", + true /* important */); +} diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 6a14359..81db9e1 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -452,6 +452,15 @@ class UITest : public testing::Test { const std::wstring& port); void StopHttpServer(); + // Prints IO performance data for use by perf graphs. + void PrintIOPerfInfo(const char* test_name, FilePath data_dir); + + // Prints memory usage data for use by perf graphs. + void PrintMemoryUsageInfo(const char* test_name, FilePath data_dir); + + // Prints memory commit charge stats for use by perf graphs. + void PrintSystemCommitCharge(const char* test_name, size_t charge); + private: // Check that no processes related to Chrome exist, displaying // the given message if any do. |