OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/net/url_fixer_upper.h" | 11 #include "chrome/browser/net/url_fixer_upper.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/chrome_process_filter.h" | |
15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/automation/browser_proxy.h" | 15 #include "chrome/test/automation/browser_proxy.h" |
17 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
18 #include "chrome/test/automation/window_proxy.h" | 17 #include "chrome/test/automation/window_proxy.h" |
| 18 #include "chrome/test/chrome_process_util.h" |
19 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
20 #include "chrome/test/perf/mem_usage.h" | 20 #include "chrome/test/perf/mem_usage.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 static const wchar_t kTempDirName[] = L"memory_test_profile"; | 26 static const wchar_t kTempDirName[] = L"memory_test_profile"; |
27 | 27 |
28 class MemoryTest : public UITest { | 28 class MemoryTest : public UITest { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 PrintMemoryUsageInfo(test_name); | 262 PrintMemoryUsageInfo(test_name); |
263 std::string trace_name(test_name); | 263 std::string trace_name(test_name); |
264 trace_name.append("_cc"); | 264 trace_name.append("_cc"); |
265 | 265 |
266 PrintResult("commit_charge", "", trace_name, | 266 PrintResult("commit_charge", "", trace_name, |
267 commit_size / 1024, "kb", true /* important */); | 267 commit_size / 1024, "kb", true /* important */); |
268 } | 268 } |
269 | 269 |
270 void PrintIOPerfInfo(const char* test_name) { | 270 void PrintIOPerfInfo(const char* test_name) { |
271 printf("\n"); | 271 printf("\n"); |
272 BrowserProcessFilter chrome_filter(user_data_dir_); | |
273 base::NamedProcessIterator | |
274 chrome_process_itr(chrome::kBrowserProcessExecutableName, | |
275 &chrome_filter); | |
276 | 272 |
277 const PROCESSENTRY32* chrome_entry; | 273 FilePath data_dir(FilePath::FromWStringHack(user_data_dir())); |
278 while (chrome_entry = chrome_process_itr.NextProcessEntry()) { | 274 int browser_process_pid = ChromeBrowserProcessId(data_dir); |
279 uint32 pid = chrome_entry->th32ProcessID; | 275 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); |
280 HANDLE process_handle = OpenProcess(PROCESS_QUERY_INFORMATION, | |
281 false, | |
282 pid); | |
283 if (process_handle == NULL) { | |
284 wprintf(L"Error opening process %d: %d\n", pid, GetLastError()); | |
285 continue; | |
286 } | |
287 | 276 |
| 277 ChromeProcessList::const_iterator it; |
| 278 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { |
288 scoped_ptr<base::ProcessMetrics> process_metrics; | 279 scoped_ptr<base::ProcessMetrics> process_metrics; |
289 IO_COUNTERS io_counters; | 280 IO_COUNTERS io_counters; |
| 281 base::ProcessHandle process_handle; |
| 282 if (!base::OpenProcessHandle(*it, &process_handle)) { |
| 283 NOTREACHED(); |
| 284 } |
290 process_metrics.reset( | 285 process_metrics.reset( |
291 base::ProcessMetrics::CreateProcessMetrics(process_handle)); | 286 base::ProcessMetrics::CreateProcessMetrics(process_handle)); |
292 ZeroMemory(&io_counters, sizeof(io_counters)); | 287 ZeroMemory(&io_counters, sizeof(io_counters)); |
293 | 288 |
294 if (process_metrics.get()->GetIOCounters(&io_counters)) { | 289 if (process_metrics.get()->GetIOCounters(&io_counters)) { |
295 std::string chrome_name = | 290 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; |
296 (pid == chrome_filter.browser_process_id()) ? "_b" : "_r"; | |
297 | 291 |
298 // Print out IO performance. We assume that the values can be | 292 // Print out IO performance. We assume that the values can be |
299 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). | 293 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). |
300 PrintResult("read_op", chrome_name, test_name + chrome_name, | 294 PrintResult("read_op", chrome_name, test_name + chrome_name, |
301 static_cast<size_t>(io_counters.ReadOperationCount), "", | 295 static_cast<size_t>(io_counters.ReadOperationCount), "", |
302 false /* not important */); | 296 false /* not important */); |
303 PrintResult("write_op", chrome_name, test_name + chrome_name, | 297 PrintResult("write_op", chrome_name, test_name + chrome_name, |
304 static_cast<size_t>(io_counters.WriteOperationCount), "", | 298 static_cast<size_t>(io_counters.WriteOperationCount), "", |
305 false /* not important */); | 299 false /* not important */); |
306 PrintResult("other_op", chrome_name, test_name + chrome_name, | 300 PrintResult("other_op", chrome_name, test_name + chrome_name, |
307 static_cast<size_t>(io_counters.OtherOperationCount), "", | 301 static_cast<size_t>(io_counters.OtherOperationCount), "", |
308 false /* not important */); | 302 false /* not important */); |
309 PrintResult("read_byte", chrome_name, test_name + chrome_name, | 303 PrintResult("read_byte", chrome_name, test_name + chrome_name, |
310 static_cast<size_t>(io_counters.ReadTransferCount / 1024), | 304 static_cast<size_t>(io_counters.ReadTransferCount / 1024), |
311 "kb", false /* not important */); | 305 "kb", false /* not important */); |
312 PrintResult("write_byte", chrome_name, test_name + chrome_name, | 306 PrintResult("write_byte", chrome_name, test_name + chrome_name, |
313 static_cast<size_t>(io_counters.WriteTransferCount / 1024), | 307 static_cast<size_t>(io_counters.WriteTransferCount / 1024), |
314 "kb", false /* not important */); | 308 "kb", false /* not important */); |
315 PrintResult("other_byte", chrome_name, test_name + chrome_name, | 309 PrintResult("other_byte", chrome_name, test_name + chrome_name, |
316 static_cast<size_t>(io_counters.OtherTransferCount / 1024), | 310 static_cast<size_t>(io_counters.OtherTransferCount / 1024), |
317 "kb", false /* not important */); | 311 "kb", false /* not important */); |
318 } | 312 } |
| 313 |
| 314 base::CloseProcessHandle(process_handle); |
319 } | 315 } |
320 } | 316 } |
321 | 317 |
322 void PrintMemoryUsageInfo(const char* test_name) { | 318 void PrintMemoryUsageInfo(const char* test_name) { |
323 printf("\n"); | 319 printf("\n"); |
324 BrowserProcessFilter chrome_filter(user_data_dir_); | 320 |
325 base::NamedProcessIterator | 321 FilePath data_dir(FilePath::FromWStringHack(user_data_dir())); |
326 chrome_process_itr(chrome::kBrowserProcessExecutableName, | 322 int browser_process_pid = ChromeBrowserProcessId(data_dir); |
327 &chrome_filter); | 323 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); |
328 | 324 |
329 size_t browser_virtual_size = 0; | 325 size_t browser_virtual_size = 0; |
330 size_t browser_working_set_size = 0; | 326 size_t browser_working_set_size = 0; |
331 size_t virtual_size = 0; | 327 size_t virtual_size = 0; |
332 size_t working_set_size = 0; | 328 size_t working_set_size = 0; |
333 size_t num_chrome_processes = 0; | 329 size_t num_chrome_processes = 0; |
334 const PROCESSENTRY32* chrome_entry; | 330 ChromeProcessList::const_iterator it; |
335 while (chrome_entry = chrome_process_itr.NextProcessEntry()) { | 331 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { |
336 uint32 pid = chrome_entry->th32ProcessID; | |
337 size_t peak_virtual_size; | 332 size_t peak_virtual_size; |
338 size_t current_virtual_size; | 333 size_t current_virtual_size; |
339 size_t peak_working_set_size; | 334 size_t peak_working_set_size; |
340 size_t current_working_set_size; | 335 size_t current_working_set_size; |
341 if (GetMemoryInfo(pid, &peak_virtual_size, ¤t_virtual_size, | 336 if (GetMemoryInfo(*it, &peak_virtual_size, ¤t_virtual_size, |
342 &peak_working_set_size, ¤t_working_set_size)) { | 337 &peak_working_set_size, ¤t_working_set_size)) { |
343 if (pid == chrome_filter.browser_process_id()) { | 338 if (*it == browser_process_pid) { |
344 browser_virtual_size = current_virtual_size; | 339 browser_virtual_size = current_virtual_size; |
345 browser_working_set_size = current_working_set_size; | 340 browser_working_set_size = current_working_set_size; |
346 } | 341 } |
347 virtual_size += current_virtual_size; | 342 virtual_size += current_virtual_size; |
348 working_set_size += current_working_set_size; | 343 working_set_size += current_working_set_size; |
349 num_chrome_processes++; | 344 num_chrome_processes++; |
350 } | 345 } |
351 } | 346 } |
352 | 347 |
353 std::string trace_name(test_name); | 348 std::string trace_name(test_name); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 RunTest("1t", 1); | 424 RunTest("1t", 1); |
430 } | 425 } |
431 | 426 |
432 TEST_F(MemoryTest, FiveTabTest) { | 427 TEST_F(MemoryTest, FiveTabTest) { |
433 RunTest("5t", 5); | 428 RunTest("5t", 5); |
434 } | 429 } |
435 | 430 |
436 TEST_F(MemoryTest, TwelveTabTest) { | 431 TEST_F(MemoryTest, TwelveTabTest) { |
437 RunTest("12t", 12); | 432 RunTest("12t", 12); |
438 } | 433 } |
OLD | NEW |