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

Side by Side Diff: chrome/test/memory_test/memory_test.cc

Issue 125124: Start to get memory test compiling on mac & linux.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months 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 | « chrome/chrome.gyp ('k') | no next file » | 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/file_path.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
8 #include "base/path_service.h" 9 #include "base/path_service.h"
9 #include "base/process_util.h" 10 #include "base/process_util.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "chrome/browser/net/url_fixer_upper.h" 12 #include "chrome/browser/net/url_fixer_upper.h"
12 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/automation/browser_proxy.h" 16 #include "chrome/test/automation/browser_proxy.h"
16 #include "chrome/test/automation/tab_proxy.h" 17 #include "chrome/test/automation/tab_proxy.h"
17 #include "chrome/test/automation/window_proxy.h" 18 #include "chrome/test/automation/window_proxy.h"
18 #include "chrome/test/chrome_process_util.h" 19 #include "chrome/test/chrome_process_util.h"
19 #include "chrome/test/ui/ui_test.h" 20 #include "chrome/test/ui/ui_test.h"
21 #if defined(OS_WIN)
20 #include "chrome/test/perf/mem_usage.h" 22 #include "chrome/test/perf/mem_usage.h"
23 #endif
21 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
22 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
23 26
24 namespace { 27 namespace {
25 28
26 static const wchar_t kTempDirName[] = L"memory_test_profile"; 29 static const FilePath::CharType kTempDirName[] =
30 FILE_PATH_LITERAL("memory_test_profile");
27 31
28 class MemoryTest : public UITest { 32 class MemoryTest : public UITest {
29 public: 33 public:
30 MemoryTest() : cleanup_temp_dir_on_exit_(false) { 34 MemoryTest() : cleanup_temp_dir_on_exit_(false) {
31 show_window_ = true; 35 show_window_ = true;
32 36
33 // For now, turn off plugins because they crash like crazy. 37 // For now, turn off plugins because they crash like crazy.
34 // TODO(mbelshe): Fix Chrome to not crash with plugins. 38 // TODO(mbelshe): Fix Chrome to not crash with plugins.
35 launch_arguments_.AppendSwitch(switches::kDisablePlugins); 39 launch_arguments_.AppendSwitch(switches::kDisablePlugins);
36 40
37 launch_arguments_.AppendSwitch(switches::kEnableLogging); 41 launch_arguments_.AppendSwitch(switches::kEnableLogging);
38 42
39 // Use the playback cache, but don't use playback events. 43 // Use the playback cache, but don't use playback events.
40 launch_arguments_.AppendSwitch(switches::kPlaybackMode); 44 launch_arguments_.AppendSwitch(switches::kPlaybackMode);
41 launch_arguments_.AppendSwitch(switches::kNoEvents); 45 launch_arguments_.AppendSwitch(switches::kNoEvents);
42 46
43 // Get the specified user data dir (optional) 47 // Get the specified user data dir (optional)
44 std::wstring profile_dir = 48 FilePath profile_dir = FilePath::FromWStringHack(
45 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kUserDataDir); 49 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kUserDataDir));
46 50
47 if (profile_dir.length() == 0) { 51 if (profile_dir.empty()) {
48 // Compute the user-data-dir which contains our test cache. 52 // Compute the user-data-dir which contains our test cache.
49 PathService::Get(base::DIR_EXE, &profile_dir); 53 PathService::Get(base::DIR_EXE, &profile_dir);
50 file_util::UpOneDirectory(&profile_dir); 54 profile_dir = profile_dir.DirName();
51 file_util::UpOneDirectory(&profile_dir); 55 profile_dir = profile_dir.DirName();
52 file_util::AppendToPath(&profile_dir, L"data"); 56 profile_dir = profile_dir.AppendASCII("data");
53 file_util::AppendToPath(&profile_dir, L"memory_test"); 57 profile_dir = profile_dir.AppendASCII("memory_test");
54 file_util::AppendToPath(&profile_dir, L"general_mix"); 58 profile_dir = profile_dir.AppendASCII("general_mix");
55 59
56 if (!SetupTempDirectory(profile_dir)) { 60 if (!SetupTempDirectory(profile_dir)) {
57 // There isn't really a way to fail gracefully here. 61 // There isn't really a way to fail gracefully here.
58 // Neither this constuctor nor the SetUp() method return 62 // Neither this constuctor nor the SetUp() method return
59 // status to the caller. So, just fall through using the 63 // status to the caller. So, just fall through using the
60 // default profile and log this. The failure will be 64 // default profile and log this. The failure will be
61 // obvious. 65 // obvious.
62 LOG(ERROR) << "Error preparing temp directory for test"; 66 LOG(ERROR) << "Error preparing temp directory for test";
63 } 67 }
64 } 68 }
65 69
66 launch_arguments_.AppendSwitchWithValue(switches::kUserDataDir, 70 launch_arguments_.AppendSwitchWithValue(switches::kUserDataDir,
67 user_data_dir_); 71 user_data_dir_.ToWStringHack());
68 } 72 }
69 73
70 ~MemoryTest() { 74 ~MemoryTest() {
71 // Cleanup our temporary directory. 75 // Cleanup our temporary directory.
72 if (cleanup_temp_dir_on_exit_) 76 if (cleanup_temp_dir_on_exit_)
73 file_util::Delete(user_data_dir_, true); 77 file_util::Delete(user_data_dir_, true);
74 } 78 }
75 79
76 // TODO(mbelshe): Separate this data to an external file. 80 // TODO(mbelshe): Separate this data to an external file.
77 // This memory test loads a set of URLs across a set of tabs, maintaining the 81 // This memory test loads a set of URLs across a set of tabs, maintaining the
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 "http://pt.wikipedia.org/wiki/P%C3%A1gina_principal", 207 "http://pt.wikipedia.org/wiki/P%C3%A1gina_principal",
204 "http://es.wikipedia.org/wiki/Portada", 208 "http://es.wikipedia.org/wiki/Portada",
205 "http://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D 0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0", 209 "http://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D 0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0",
206 "<NEWTAB>", 210 "<NEWTAB>",
207 "http://www.google.com/translate_t?hl=en&text=This%20Is%20A%20Test%20Of%20 missspellingsdfdf&sl=en&tl=ja", 211 "http://www.google.com/translate_t?hl=en&text=This%20Is%20A%20Test%20Of%20 missspellingsdfdf&sl=en&tl=ja",
208 }; 212 };
209 213
210 // Record the initial CommitCharge. This is a system-wide measurement, 214 // Record the initial CommitCharge. This is a system-wide measurement,
211 // so if other applications are running, they can create variance in this 215 // so if other applications are running, they can create variance in this
212 // test. 216 // test.
217 #if defined(OS_WIN)
213 size_t start_size = GetSystemCommitCharge(); 218 size_t start_size = GetSystemCommitCharge();
219 #endif
214 220
215 // Cycle through the URLs. 221 // Cycle through the URLs.
216 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); 222 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
217 scoped_refptr<TabProxy> tab(window->GetActiveTab()); 223 scoped_refptr<TabProxy> tab(window->GetActiveTab());
218 int expected_tab_count = 1; 224 int expected_tab_count = 1;
219 for (unsigned counter = 0; counter < arraysize(urls); ++counter) { 225 for (unsigned counter = 0; counter < arraysize(urls); ++counter) {
220 std::string url = urls[counter]; 226 std::string url = urls[counter];
221 227
222 if (url == "<PAUSE>") { // Special command to delay on this page 228 if (url == "<PAUSE>") { // Special command to delay on this page
223 PlatformThread::Sleep(2000); 229 PlatformThread::Sleep(2000);
(...skipping 22 matching lines...) Expand all
246 tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime, 252 tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime,
247 &timed_out); 253 &timed_out);
248 if (timed_out) 254 if (timed_out)
249 printf("warning: %s timed out!\n", urls[counter].c_str()); 255 printf("warning: %s timed out!\n", urls[counter].c_str());
250 256
251 // TODO(mbelshe): Bug 2953 257 // TODO(mbelshe): Bug 2953
252 // The automation crashes periodically if we cycle too quickly. 258 // The automation crashes periodically if we cycle too quickly.
253 // To make these tests more reliable, slowing them down a bit. 259 // To make these tests more reliable, slowing them down a bit.
254 PlatformThread::Sleep(100); 260 PlatformThread::Sleep(100);
255 } 261 }
262 #if defined(OS_WIN)
256 size_t stop_size = GetSystemCommitCharge(); 263 size_t stop_size = GetSystemCommitCharge();
257 264
258 PrintResults(test_name, stop_size - start_size); 265 PrintResults(test_name, stop_size - start_size);
266 #else
267 NOTIMPLEMENTED() << "need to map SystemCommitCharge";
268 PrintResults(test_name, 0);
269 #endif
259 } 270 }
260 271
261 void PrintResults(const char* test_name, size_t commit_size) { 272 void PrintResults(const char* test_name, size_t commit_size) {
262 PrintMemoryUsageInfo(test_name); 273 PrintMemoryUsageInfo(test_name);
263 std::string trace_name(test_name); 274 std::string trace_name(test_name);
264 trace_name.append("_cc"); 275 trace_name.append("_cc");
265 276
266 PrintResult("commit_charge", "", trace_name, 277 PrintResult("commit_charge", "", trace_name,
267 commit_size / 1024, "kb", true /* important */); 278 commit_size / 1024, "kb", true /* important */);
268 } 279 }
269 280
270 void PrintIOPerfInfo(const char* test_name) { 281 void PrintIOPerfInfo(const char* test_name) {
271 printf("\n"); 282 printf("\n");
272 283
273 FilePath data_dir(user_data_dir()); 284 FilePath data_dir(user_data_dir());
274 int browser_process_pid = ChromeBrowserProcessId(data_dir); 285 int browser_process_pid = ChromeBrowserProcessId(data_dir);
275 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); 286 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir));
276 287
277 ChromeProcessList::const_iterator it; 288 ChromeProcessList::const_iterator it;
278 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { 289 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
279 scoped_ptr<base::ProcessMetrics> process_metrics; 290 scoped_ptr<base::ProcessMetrics> process_metrics;
280 IO_COUNTERS io_counters; 291 IoCounters io_counters;
281 base::ProcessHandle process_handle; 292 base::ProcessHandle process_handle;
282 if (!base::OpenProcessHandle(*it, &process_handle)) { 293 if (!base::OpenProcessHandle(*it, &process_handle)) {
283 NOTREACHED(); 294 NOTREACHED();
284 } 295 }
285 process_metrics.reset( 296 process_metrics.reset(
286 base::ProcessMetrics::CreateProcessMetrics(process_handle)); 297 base::ProcessMetrics::CreateProcessMetrics(process_handle));
287 ZeroMemory(&io_counters, sizeof(io_counters)); 298 bzero(&io_counters, sizeof(io_counters));
288 299
289 if (process_metrics.get()->GetIOCounters(&io_counters)) { 300 if (process_metrics.get()->GetIOCounters(&io_counters)) {
290 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; 301 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r";
291 302
292 // Print out IO performance. We assume that the values can be 303 // Print out IO performance. We assume that the values can be
293 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). 304 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers).
294 PrintResult("read_op", chrome_name, test_name + chrome_name, 305 PrintResult("read_op", chrome_name, test_name + chrome_name,
295 static_cast<size_t>(io_counters.ReadOperationCount), "", 306 static_cast<size_t>(io_counters.ReadOperationCount), "",
296 false /* not important */); 307 false /* not important */);
297 PrintResult("write_op", chrome_name, test_name + chrome_name, 308 PrintResult("write_op", chrome_name, test_name + chrome_name,
(...skipping 14 matching lines...) Expand all
312 } 323 }
313 324
314 base::CloseProcessHandle(process_handle); 325 base::CloseProcessHandle(process_handle);
315 } 326 }
316 } 327 }
317 328
318 void PrintMemoryUsageInfo(const char* test_name) { 329 void PrintMemoryUsageInfo(const char* test_name) {
319 printf("\n"); 330 printf("\n");
320 331
321 FilePath data_dir(user_data_dir()); 332 FilePath data_dir(user_data_dir());
333 #if defined(OS_WIN)
322 int browser_process_pid = ChromeBrowserProcessId(data_dir); 334 int browser_process_pid = ChromeBrowserProcessId(data_dir);
335 #endif
323 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); 336 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir));
324 337
325 size_t browser_virtual_size = 0; 338 size_t browser_virtual_size = 0;
326 size_t browser_working_set_size = 0; 339 size_t browser_working_set_size = 0;
327 size_t virtual_size = 0; 340 size_t virtual_size = 0;
328 size_t working_set_size = 0; 341 size_t working_set_size = 0;
329 size_t num_chrome_processes = 0; 342 size_t num_chrome_processes = 0;
330 ChromeProcessList::const_iterator it; 343 ChromeProcessList::const_iterator it;
331 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { 344 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
345 #if defined(OS_WIN)
332 size_t peak_virtual_size; 346 size_t peak_virtual_size;
333 size_t current_virtual_size; 347 size_t current_virtual_size;
334 size_t peak_working_set_size; 348 size_t peak_working_set_size;
335 size_t current_working_set_size; 349 size_t current_working_set_size;
336 if (GetMemoryInfo(*it, &peak_virtual_size, &current_virtual_size, 350 if (GetMemoryInfo(*it, &peak_virtual_size, &current_virtual_size,
337 &peak_working_set_size, &current_working_set_size)) { 351 &peak_working_set_size, &current_working_set_size)) {
338 if (*it == browser_process_pid) { 352 if (*it == browser_process_pid) {
339 browser_virtual_size = current_virtual_size; 353 browser_virtual_size = current_virtual_size;
340 browser_working_set_size = current_working_set_size; 354 browser_working_set_size = current_working_set_size;
341 } 355 }
342 virtual_size += current_virtual_size; 356 virtual_size += current_virtual_size;
343 working_set_size += current_working_set_size; 357 working_set_size += current_working_set_size;
344 num_chrome_processes++; 358 num_chrome_processes++;
345 } 359 }
360 #else
361 // TODO(port)
362 NOTIMPLEMENTED()
363 << "need to port GetMemoryInfo or map it to the existing primitives";
364 #endif
346 } 365 }
347 366
348 std::string trace_name(test_name); 367 std::string trace_name(test_name);
349 PrintResult("vm_final_browser", "", trace_name + "_vm_b", 368 PrintResult("vm_final_browser", "", trace_name + "_vm_b",
350 browser_virtual_size / 1024, "kb", 369 browser_virtual_size / 1024, "kb",
351 false /* not important */); 370 false /* not important */);
352 PrintResult("ws_final_browser", "", trace_name + "_ws_b", 371 PrintResult("ws_final_browser", "", trace_name + "_ws_b",
353 browser_working_set_size / 1024, "kb", 372 browser_working_set_size / 1024, "kb",
354 false /* not important */); 373 false /* not important */);
355 PrintResult("vm_final_total", "", trace_name + "_vm", 374 PrintResult("vm_final_total", "", trace_name + "_vm",
356 virtual_size / 1024, "kb", 375 virtual_size / 1024, "kb",
357 false /* not important */); 376 false /* not important */);
358 PrintResult("ws_final_total", "", trace_name + "_ws", 377 PrintResult("ws_final_total", "", trace_name + "_ws",
359 working_set_size / 1024, "kb", 378 working_set_size / 1024, "kb",
360 true /* important */); 379 true /* important */);
361 PrintResult("processes", "", trace_name + "_proc", 380 PrintResult("processes", "", trace_name + "_proc",
362 num_chrome_processes, "", 381 num_chrome_processes, "",
363 false /* not important */); 382 false /* not important */);
364 } 383 }
365 384
366 private: 385 private:
367 // Setup a temporary directory to store the profile to use 386 // Setup a temporary directory to store the profile to use
368 // with these tests. 387 // with these tests.
369 // Input: 388 // Input:
370 // src_dir is set to the source directory 389 // src_dir is set to the source directory
371 // Output: 390 // Output:
372 // On success, modifies user_data_dir_ to be a new profile directory 391 // On success, modifies user_data_dir_ to be a new profile directory
373 // and sets cleanup_temp_dir_on_exit_ to true. 392 // and sets cleanup_temp_dir_on_exit_ to true.
374 bool SetupTempDirectory(std::wstring src_dir) { 393 bool SetupTempDirectory(const FilePath &src_dir) {
375 LOG(INFO) << "Setting up temp directory in " << src_dir.c_str(); 394 LOG(INFO) << "Setting up temp directory in " << src_dir.value();
376 // We create a copy of the test dir and use it so that each 395 // We create a copy of the test dir and use it so that each
377 // run of this test starts with the same data. Running this 396 // run of this test starts with the same data. Running this
378 // test has the side effect that it will change the profile. 397 // test has the side effect that it will change the profile.
379 std::wstring temp_dir; 398 FilePath temp_dir;
380 if (!file_util::CreateNewTempDirectory(kTempDirName, &temp_dir)) { 399 if (!file_util::CreateNewTempDirectory(kTempDirName, &temp_dir)) {
381 LOG(ERROR) << "Could not create temp directory:" << kTempDirName; 400 LOG(ERROR) << "Could not create temp directory:" << kTempDirName;
382 return false; 401 return false;
383 } 402 }
384 403
385 src_dir.append(L"\\*");
386
387 if (!file_util::CopyDirectory(src_dir, temp_dir, true)) { 404 if (!file_util::CopyDirectory(src_dir, temp_dir, true)) {
388 LOG(ERROR) << "Could not copy temp directory"; 405 LOG(ERROR) << "Could not copy temp directory";
389 return false; 406 return false;
390 } 407 }
391 408
392 user_data_dir_ = temp_dir; 409 user_data_dir_ = temp_dir;
393 cleanup_temp_dir_on_exit_ = true; 410 cleanup_temp_dir_on_exit_ = true;
394 LOG(INFO) << "Finished temp directory setup."; 411 LOG(INFO) << "Finished temp directory setup.";
395 return true; 412 return true;
396 } 413 }
397 414
398 bool cleanup_temp_dir_on_exit_; 415 bool cleanup_temp_dir_on_exit_;
399 std::wstring user_data_dir_; 416 FilePath user_data_dir_;
400 }; 417 };
401 418
402 class MemoryReferenceTest : public MemoryTest { 419 class MemoryReferenceTest : public MemoryTest {
403 public: 420 public:
404 // override the browser directory that is used by UITest::SetUp to cause it 421 // override the browser directory that is used by UITest::SetUp to cause it
405 // to use the reference build instead. 422 // to use the reference build instead.
406 void SetUp() { 423 void SetUp() {
407 FilePath dir; 424 FilePath dir;
408 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); 425 PathService::Get(chrome::DIR_TEST_TOOLS, &dir);
409 dir = dir.AppendASCII("reference_build"); 426 dir = dir.AppendASCII("reference_build");
427 #if defined(OS_WIN)
410 dir = dir.AppendASCII("chrome"); 428 dir = dir.AppendASCII("chrome");
429 #elif defined(OS_LINUX)
430 dir = dir.AppendASCII("chrome_linux");
431 #elif defined(OS_MACOSX)
432 dir = dir.AppendASCII("chrome_mac");
433 #endif
411 browser_directory_ = dir; 434 browser_directory_ = dir;
412 UITest::SetUp(); 435 UITest::SetUp();
413 } 436 }
414 437
415 void RunTest(const char* test_name, int num_target_tabs) { 438 void RunTest(const char* test_name, int num_target_tabs) {
416 std::wstring pages, timings; 439 std::wstring pages, timings;
417 MemoryTest::RunTest(test_name, num_target_tabs); 440 MemoryTest::RunTest(test_name, num_target_tabs);
418 } 441 }
419 }; 442 };
420 443
421 } // namespace
422
423 TEST_F(MemoryTest, SingleTabTest) { 444 TEST_F(MemoryTest, SingleTabTest) {
424 RunTest("1t", 1); 445 RunTest("1t", 1);
425 } 446 }
426 447
427 TEST_F(MemoryTest, FiveTabTest) { 448 TEST_F(MemoryTest, FiveTabTest) {
428 RunTest("5t", 5); 449 RunTest("5t", 5);
429 } 450 }
430 451
431 TEST_F(MemoryTest, TwelveTabTest) { 452 TEST_F(MemoryTest, TwelveTabTest) {
432 RunTest("12t", 12); 453 RunTest("12t", 12);
433 } 454 }
455
456 } // namespace
OLDNEW
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698