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

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 2053523003: Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 bool old_flag_prof_browser_mode_; 340 bool old_flag_prof_browser_mode_;
341 }; 341 };
342 342
343 } // namespace 343 } // namespace
344 344
345 TEST(RecordTickSample) { 345 TEST(RecordTickSample) {
346 TestSetup test_setup; 346 TestSetup test_setup;
347 CpuProfilesCollection profiles(CcTest::heap()); 347 CpuProfilesCollection profiles(CcTest::heap());
348 profiles.StartProfiling("", false); 348 profiles.StartProfiling("", false);
349 ProfileGenerator generator(&profiles); 349 ProfileGenerator generator(&profiles);
350 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 350 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
351 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 351 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
352 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 352 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
353 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 353 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
354 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 354 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
355 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 355 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
356 356
357 // We are building the following calls tree: 357 // We are building the following calls tree:
358 // -> aaa - sample1 358 // -> aaa - sample1
359 // aaa -> bbb -> ccc - sample2 359 // aaa -> bbb -> ccc - sample2
360 // -> ccc -> aaa - sample3 360 // -> ccc -> aaa - sample3
361 TickSample sample1; 361 TickSample sample1;
362 sample1.pc = ToAddress(0x1600); 362 sample1.pc = ToAddress(0x1600);
(...skipping 27 matching lines...) Expand all
390 CHECK_EQ(entry1, node1->entry()); 390 CHECK_EQ(entry1, node1->entry());
391 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); 391 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1);
392 CHECK(node2); 392 CHECK(node2);
393 CHECK_EQ(entry1, node2->entry()); 393 CHECK_EQ(entry1, node2->entry());
394 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); 394 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3);
395 CHECK(node3); 395 CHECK(node3);
396 CHECK_EQ(entry3, node3->entry()); 396 CHECK_EQ(entry3, node3->entry());
397 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); 397 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1);
398 CHECK(node4); 398 CHECK(node4);
399 CHECK_EQ(entry1, node4->entry()); 399 CHECK_EQ(entry1, node4->entry());
400
401 delete entry1;
402 delete entry2;
403 delete entry3;
400 } 404 }
401 405
402 406
403 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { 407 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) {
404 CHECK_EQ((*expectedId)++, node->id()); 408 CHECK_EQ((*expectedId)++, node->id());
405 for (int i = 0; i < node->children()->length(); i++) { 409 for (int i = 0; i < node->children()->length(); i++) {
406 CheckNodeIds(node->children()->at(i), expectedId); 410 CheckNodeIds(node->children()->at(i), expectedId);
407 } 411 }
408 } 412 }
409 413
410 414
411 TEST(SampleIds) { 415 TEST(SampleIds) {
412 TestSetup test_setup; 416 TestSetup test_setup;
413 CpuProfilesCollection profiles(CcTest::heap()); 417 CpuProfilesCollection profiles(CcTest::heap());
414 profiles.StartProfiling("", true); 418 profiles.StartProfiling("", true);
415 ProfileGenerator generator(&profiles); 419 ProfileGenerator generator(&profiles);
416 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 420 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
417 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 421 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
418 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 422 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
419 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 423 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
420 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 424 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
421 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 425 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
422 426
423 // We are building the following calls tree: 427 // We are building the following calls tree:
424 // -> aaa #3 - sample1 428 // -> aaa #3 - sample1
425 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2 429 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
426 // -> ccc #6 -> aaa #7 - sample3 430 // -> ccc #6 -> aaa #7 - sample3
427 TickSample sample1; 431 TickSample sample1;
428 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow(); 432 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
(...skipping 20 matching lines...) Expand all
449 CpuProfile* profile = profiles.StopProfiling(""); 453 CpuProfile* profile = profiles.StopProfiling("");
450 unsigned nodeId = 1; 454 unsigned nodeId = 1;
451 CheckNodeIds(profile->top_down()->root(), &nodeId); 455 CheckNodeIds(profile->top_down()->root(), &nodeId);
452 CHECK_EQ(7u, nodeId - 1); 456 CHECK_EQ(7u, nodeId - 1);
453 457
454 CHECK_EQ(3, profile->samples_count()); 458 CHECK_EQ(3, profile->samples_count());
455 unsigned expected_id[] = {3, 5, 7}; 459 unsigned expected_id[] = {3, 5, 7};
456 for (int i = 0; i < 3; i++) { 460 for (int i = 0; i < 3; i++) {
457 CHECK_EQ(expected_id[i], profile->sample(i)->id()); 461 CHECK_EQ(expected_id[i], profile->sample(i)->id());
458 } 462 }
463
464 delete entry1;
465 delete entry2;
466 delete entry3;
459 } 467 }
460 468
461 469
462 TEST(NoSamples) { 470 TEST(NoSamples) {
463 TestSetup test_setup; 471 TestSetup test_setup;
464 CpuProfilesCollection profiles(CcTest::heap()); 472 CpuProfilesCollection profiles(CcTest::heap());
465 profiles.StartProfiling("", false); 473 profiles.StartProfiling("", false);
466 ProfileGenerator generator(&profiles); 474 ProfileGenerator generator(&profiles);
467 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 475 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
468 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 476 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
469 477
470 // We are building the following calls tree: 478 // We are building the following calls tree:
471 // (root)#1 -> aaa #2 -> aaa #3 - sample1 479 // (root)#1 -> aaa #2 -> aaa #3 - sample1
472 TickSample sample1; 480 TickSample sample1;
473 sample1.pc = ToAddress(0x1600); 481 sample1.pc = ToAddress(0x1600);
474 sample1.stack[0] = ToAddress(0x1510); 482 sample1.stack[0] = ToAddress(0x1510);
475 sample1.frames_count = 1; 483 sample1.frames_count = 1;
476 generator.RecordTickSample(sample1); 484 generator.RecordTickSample(sample1);
477 485
478 CpuProfile* profile = profiles.StopProfiling(""); 486 CpuProfile* profile = profiles.StopProfiling("");
479 unsigned nodeId = 1; 487 unsigned nodeId = 1;
480 CheckNodeIds(profile->top_down()->root(), &nodeId); 488 CheckNodeIds(profile->top_down()->root(), &nodeId);
481 CHECK_EQ(3u, nodeId - 1); 489 CHECK_EQ(3u, nodeId - 1);
482 490
483 CHECK_EQ(0, profile->samples_count()); 491 CHECK_EQ(0, profile->samples_count());
492
493 delete entry1;
484 } 494 }
485 495
486 496
487 static const ProfileNode* PickChild(const ProfileNode* parent, 497 static const ProfileNode* PickChild(const ProfileNode* parent,
488 const char* name) { 498 const char* name) {
489 for (int i = 0; i < parent->children()->length(); ++i) { 499 for (int i = 0; i < parent->children()->length(); ++i) {
490 const ProfileNode* child = parent->children()->at(i); 500 const ProfileNode* child = parent->children()->at(i);
491 if (strcmp(child->entry()->name(), name) == 0) return child; 501 if (strcmp(child->entry()->name(), name) == 0) return child;
492 } 502 }
493 return NULL; 503 return NULL;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // (root) 721 // (root)
712 // "" 722 // ""
713 // kDebuggerStatement 723 // kDebuggerStatement
714 current = PickChild(current, ""); 724 current = PickChild(current, "");
715 CHECK(const_cast<v8::CpuProfileNode*>(current)); 725 CHECK(const_cast<v8::CpuProfileNode*>(current));
716 726
717 current = PickChild(current, "Debugger"); 727 current = PickChild(current, "Debugger");
718 CHECK(const_cast<v8::CpuProfileNode*>(current)); 728 CHECK(const_cast<v8::CpuProfileNode*>(current));
719 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 729 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
720 } 730 }
OLDNEW
« src/profiler/profiler-listener.cc ('K') | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698