Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/test/page_cycler/page_cycler_test.cc

Issue 402052: Prep for printing common memory stats from page_cycler_tests and memory_test:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove commented-out code from previous upload Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/ui/ui_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/eintr_wrapper.h" 7 #include "base/eintr_wrapper.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 std::string cookie; 220 std::string cookie;
221 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_pages", &cookie)); 221 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_pages", &cookie));
222 pages->assign(UTF8ToWide(cookie)); 222 pages->assign(UTF8ToWide(cookie));
223 ASSERT_FALSE(pages->empty()); 223 ASSERT_FALSE(pages->empty());
224 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_timings", &cookie)); 224 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_timings", &cookie));
225 timings->assign(cookie); 225 timings->assign(cookie);
226 ASSERT_FALSE(timings->empty()); 226 ASSERT_FALSE(timings->empty());
227 } 227 }
228 228
229 void PrintIOPerfInfo(const char* test_name) {
230 FilePath data_dir;
231 PathService::Get(chrome::DIR_USER_DATA, &data_dir);
232 int browser_process_pid = ChromeBrowserProcessId(data_dir);
233 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir));
234
235 ChromeProcessList::const_iterator it;
236 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
237 base::ProcessHandle process_handle;
238 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
239 NOTREACHED();
240 }
241
242 scoped_ptr<base::ProcessMetrics> process_metrics;
243 process_metrics.reset(
244 base::ProcessMetrics::CreateProcessMetrics(process_handle));
245 IoCounters io_counters;
246 memset(&io_counters, 0, sizeof(io_counters));
247
248 if (process_metrics.get()->GetIOCounters(&io_counters)) {
249 // Print out IO performance. We assume that the values can be
250 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers).
251 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r";
252
253 PrintResult("read_op", chrome_name,
254 "r_op" + chrome_name + test_name,
255 static_cast<size_t>(io_counters.ReadOperationCount), "",
256 false /* not important */);
257 PrintResult("write_op", chrome_name,
258 "w_op" + chrome_name + test_name,
259 static_cast<size_t>(io_counters.WriteOperationCount), "",
260 false /* not important */);
261 PrintResult("other_op", chrome_name,
262 "o_op" + chrome_name + test_name,
263 static_cast<size_t>(io_counters.OtherOperationCount), "",
264 false /* not important */);
265
266 size_t total = static_cast<size_t>(io_counters.ReadOperationCount +
267 io_counters.WriteOperationCount +
268 io_counters.OtherOperationCount);
269 PrintResult("total_op", chrome_name,
270 "IO_op" + chrome_name + test_name,
271 total, "", true /* important */);
272
273 PrintResult("read_byte", chrome_name,
274 "r_b" + chrome_name + test_name,
275 static_cast<size_t>(io_counters.ReadTransferCount / 1024),
276 "kb", false /* not important */);
277 PrintResult("write_byte", chrome_name,
278 "w_b" + chrome_name + test_name,
279 static_cast<size_t>(io_counters.WriteTransferCount / 1024),
280 "kb", false /* not important */);
281 PrintResult("other_byte", chrome_name,
282 "o_b" + chrome_name + test_name,
283 static_cast<size_t>(io_counters.OtherTransferCount / 1024),
284 "kb", false /* not important */);
285
286 total = static_cast<size_t>((io_counters.ReadTransferCount +
287 io_counters.WriteTransferCount +
288 io_counters.OtherTransferCount) / 1024);
289 PrintResult("total_byte", chrome_name,
290 "IO_b" + chrome_name + test_name,
291 total, "kb", true /* important */);
292 }
293
294 base::CloseProcessHandle(process_handle);
295 }
296 }
297
298 void PrintMemoryUsageInfo(const char* test_name) {
299 FilePath data_dir;
300 PathService::Get(chrome::DIR_USER_DATA, &data_dir);
301 int browser_process_pid = ChromeBrowserProcessId(data_dir);
302 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir));
303
304 #if !defined(OS_MACOSX)
305 ChromeProcessList::const_iterator it;
306 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
307 base::ProcessHandle process_handle;
308 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
309 NOTREACHED();
310 }
311
312 scoped_ptr<base::ProcessMetrics> process_metrics;
313 process_metrics.reset(
314 base::ProcessMetrics::CreateProcessMetrics(process_handle));
315
316 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r";
317
318 std::string trace_name(test_name);
319 #if defined(OS_WIN)
320 PrintResult("vm_peak", chrome_name,
321 "vm_pk" + chrome_name + trace_name,
322 process_metrics->GetPeakPagefileUsage(), "bytes",
323 true /* important */);
324 PrintResult("vm_final", chrome_name,
325 "vm_f" + chrome_name + trace_name,
326 process_metrics->GetPagefileUsage(), "bytes",
327 false /* not important */);
328 PrintResult("ws_peak", chrome_name,
329 "ws_pk" + chrome_name + trace_name,
330 process_metrics->GetPeakWorkingSetSize(), "bytes",
331 true /* important */);
332 PrintResult("ws_final", chrome_name,
333 "ws_f" + chrome_name + trace_name,
334 process_metrics->GetWorkingSetSize(), "bytes",
335 false /* not important */);
336 #elif defined(OS_LINUX)
337 PrintResult("vm_size_final", chrome_name,
338 "vm_size_f" + chrome_name + trace_name,
339 process_metrics->GetPagefileUsage(), "bytes",
340 true /* important */);
341 PrintResult("vm_rss_final", chrome_name,
342 "vm_rss_f" + chrome_name + trace_name,
343 process_metrics->GetWorkingSetSize(), "bytes",
344 true /* important */);
345 #else
346 NOTIMPLEMENTED();
347 #endif
348 base::CloseProcessHandle(process_handle);
349 }
350
351 #else // !defined(OS_MACOSX)
352
353 // There is no way to get memory info from one process on another process
354 // without privileges, this means the base methods for doing this can't be
355 // made to work. Instead we use a helper that invokes ps to collect the
356 // data so we have it for the unittest.
357
358 MacChromeProcessInfoList process_infos(
359 GetRunningMacProcessInfo(chrome_processes));
360 MacChromeProcessInfoList::const_iterator it;
361 for (it = process_infos.begin(); it != process_infos.end(); ++it) {
362 const MacChromeProcessInfo &process_info = *it;
363
364 std::string chrome_name =
365 (process_info.pid == browser_process_pid) ? "_b" : "_r";
366 std::string trace_name(test_name);
367
368 PrintResult("vm_size_final", chrome_name,
369 "vm_size_f" + chrome_name + trace_name,
370 static_cast<size_t>(process_info.vsz_in_kb) * 1024, "bytes",
371 true /* important */);
372 PrintResult("vm_rss_final", chrome_name,
373 "vm_rss_f" + chrome_name + trace_name,
374 static_cast<size_t>(process_info.rsz_in_kb) * 1024, "bytes",
375 true /* important */);
376 }
377
378 #endif // !defined(OS_MACOSX)
379 }
380
381 void PrintSystemCommitCharge(const char* test_name, size_t charge) {
382 std::string trace_name(test_name);
383 PrintResult("commit_charge", "", "cc" + trace_name, charge, "kb",
384 true /* important */);
385 }
386
387 // When use_http is true, the test name passed here will be used directly in 229 // When use_http is true, the test name passed here will be used directly in
388 // the path to the test data, so it must be safe for use in a URL without 230 // the path to the test data, so it must be safe for use in a URL without
389 // escaping. (No pound (#), question mark (?), semicolon (;), non-ASCII, or 231 // escaping. (No pound (#), question mark (?), semicolon (;), non-ASCII, or
390 // other funny stuff.) 232 // other funny stuff.)
391 void RunTestWithSuffix(const char* name, bool use_http, const char* suffix) { 233 void RunTestWithSuffix(const char* name, bool use_http, const char* suffix) {
392 std::wstring pages; 234 std::wstring pages;
393 std::string timings; 235 std::string timings;
394 size_t start_size = base::GetSystemCommitCharge(); 236 size_t start_size = base::GetSystemCommitCharge();
395 RunPageCycler(name, &pages, &timings, use_http); 237 RunPageCycler(name, &pages, &timings, use_http);
396 if (timings.empty()) 238 if (timings.empty())
397 return; 239 return;
398 size_t stop_size = base::GetSystemCommitCharge(); 240 size_t stop_size = base::GetSystemCommitCharge();
399 241
400 PrintMemoryUsageInfo(suffix); 242 FilePath data_dir;
401 PrintIOPerfInfo(suffix); 243 PathService::Get(chrome::DIR_USER_DATA, &data_dir);
244
245 PrintMemoryUsageInfo(suffix, data_dir);
246 PrintIOPerfInfo(suffix, data_dir);
402 PrintSystemCommitCharge(suffix, stop_size - start_size); 247 PrintSystemCommitCharge(suffix, stop_size - start_size);
403 248
404 std::string trace_name = "t" + std::string(suffix); 249 std::string trace_name = "t" + std::string(suffix);
405 wprintf(L"\nPages: [%ls]\n", pages.c_str()); 250 wprintf(L"\nPages: [%ls]\n", pages.c_str());
406 PrintResultList("times", "", trace_name, timings, "ms", 251 PrintResultList("times", "", trace_name, timings, "ms",
407 true /* important */); 252 true /* important */);
408 } 253 }
409 254
410 void RunTest(const char* name, bool use_http) { 255 void RunTest(const char* name, bool use_http) {
411 RunTestWithSuffix(name, use_http, ""); 256 RunTestWithSuffix(name, use_http, "");
(...skipping 25 matching lines...) Expand all
437 282
438 void RunTest(const char* name, bool use_http) { 283 void RunTest(const char* name, bool use_http) {
439 std::wstring pages; 284 std::wstring pages;
440 std::string timings; 285 std::string timings;
441 size_t start_size = base::GetSystemCommitCharge(); 286 size_t start_size = base::GetSystemCommitCharge();
442 RunPageCycler(name, &pages, &timings, use_http); 287 RunPageCycler(name, &pages, &timings, use_http);
443 if (timings.empty()) 288 if (timings.empty())
444 return; 289 return;
445 size_t stop_size = base::GetSystemCommitCharge(); 290 size_t stop_size = base::GetSystemCommitCharge();
446 291
447 PrintMemoryUsageInfo("_ref"); 292 FilePath data_dir;
448 PrintIOPerfInfo("_ref"); 293 PathService::Get(chrome::DIR_USER_DATA, &data_dir);
294
295 PrintMemoryUsageInfo("_ref", data_dir);
296 PrintIOPerfInfo("_ref", data_dir);
449 PrintSystemCommitCharge("_ref", stop_size - start_size); 297 PrintSystemCommitCharge("_ref", stop_size - start_size);
450 298
451 PrintResultList("times", "", "t_ref", timings, "ms", 299 PrintResultList("times", "", "t_ref", timings, "ms",
452 true /* important */); 300 true /* important */);
453 } 301 }
454 }; 302 };
455 303
456 class PageCyclerExtensionTest : public PageCyclerTest { 304 class PageCyclerExtensionTest : public PageCyclerTest {
457 public: 305 public:
458 void SetUp() {} 306 void SetUp() {}
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 359
512 // http (localhost) tests 360 // http (localhost) tests
513 PAGE_CYCLER_HTTP_TESTS("moz", MozHttp); 361 PAGE_CYCLER_HTTP_TESTS("moz", MozHttp);
514 PAGE_CYCLER_HTTP_TESTS("intl1", Intl1Http); 362 PAGE_CYCLER_HTTP_TESTS("intl1", Intl1Http);
515 PAGE_CYCLER_HTTP_TESTS("intl2", Intl2Http); 363 PAGE_CYCLER_HTTP_TESTS("intl2", Intl2Http);
516 PAGE_CYCLER_HTTP_TESTS("dom", DomHttp); 364 PAGE_CYCLER_HTTP_TESTS("dom", DomHttp);
517 PAGE_CYCLER_HTTP_TESTS("bloat", BloatHttp); 365 PAGE_CYCLER_HTTP_TESTS("bloat", BloatHttp);
518 366
519 367
520 } // namespace 368 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/ui/ui_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698