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

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

Issue 2117343006: Introduce v8::CpuProfiler::New and v8::CpuProfiler::Dispose API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 private: 339 private:
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::i_isolate()); 347 CpuProfilesCollection profiles(CcTest::i_isolate());
348 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 348 CpuProfiler profiler(CcTest::i_isolate());
349 profiles.set_cpu_profiler(&profiler);
349 profiles.StartProfiling("", false); 350 profiles.StartProfiling("", false);
350 ProfileGenerator generator(&profiles); 351 ProfileGenerator generator(&profiles);
351 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 352 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
352 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 353 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
353 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 354 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
354 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 355 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
355 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 356 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
356 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 357 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
357 358
358 // We are building the following calls tree: 359 // We are building the following calls tree:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 CHECK_EQ((*expectedId)++, node->id()); 410 CHECK_EQ((*expectedId)++, node->id());
410 for (int i = 0; i < node->children()->length(); i++) { 411 for (int i = 0; i < node->children()->length(); i++) {
411 CheckNodeIds(node->children()->at(i), expectedId); 412 CheckNodeIds(node->children()->at(i), expectedId);
412 } 413 }
413 } 414 }
414 415
415 416
416 TEST(SampleIds) { 417 TEST(SampleIds) {
417 TestSetup test_setup; 418 TestSetup test_setup;
418 CpuProfilesCollection profiles(CcTest::i_isolate()); 419 CpuProfilesCollection profiles(CcTest::i_isolate());
419 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 420 CpuProfiler profiler(CcTest::i_isolate());
421 profiles.set_cpu_profiler(&profiler);
420 profiles.StartProfiling("", true); 422 profiles.StartProfiling("", true);
421 ProfileGenerator generator(&profiles); 423 ProfileGenerator generator(&profiles);
422 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 424 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
423 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 425 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
424 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 426 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
425 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 427 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
426 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 428 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
427 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 429 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
428 430
429 // We are building the following calls tree: 431 // We are building the following calls tree:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 467
466 delete entry1; 468 delete entry1;
467 delete entry2; 469 delete entry2;
468 delete entry3; 470 delete entry3;
469 } 471 }
470 472
471 473
472 TEST(NoSamples) { 474 TEST(NoSamples) {
473 TestSetup test_setup; 475 TestSetup test_setup;
474 CpuProfilesCollection profiles(CcTest::i_isolate()); 476 CpuProfilesCollection profiles(CcTest::i_isolate());
475 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 477 CpuProfiler profiler(CcTest::i_isolate());
478 profiles.set_cpu_profiler(&profiler);
476 profiles.StartProfiling("", false); 479 profiles.StartProfiling("", false);
477 ProfileGenerator generator(&profiles); 480 ProfileGenerator generator(&profiles);
478 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 481 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
479 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 482 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
480 483
481 // We are building the following calls tree: 484 // We are building the following calls tree:
482 // (root)#1 -> aaa #2 -> aaa #3 - sample1 485 // (root)#1 -> aaa #2 -> aaa #3 - sample1
483 TickSample sample1; 486 TickSample sample1;
484 sample1.pc = ToAddress(0x1600); 487 sample1.pc = ToAddress(0x1600);
485 sample1.stack[0] = ToAddress(0x1510); 488 sample1.stack[0] = ToAddress(0x1510);
(...skipping 23 matching lines...) Expand all
509 512
510 TEST(RecordStackTraceAtStartProfiling) { 513 TEST(RecordStackTraceAtStartProfiling) {
511 // This test does not pass with inlining enabled since inlined functions 514 // This test does not pass with inlining enabled since inlined functions
512 // don't appear in the stack trace. 515 // don't appear in the stack trace.
513 i::FLAG_turbo_inlining = false; 516 i::FLAG_turbo_inlining = false;
514 i::FLAG_use_inlining = false; 517 i::FLAG_use_inlining = false;
515 518
516 v8::HandleScope scope(CcTest::isolate()); 519 v8::HandleScope scope(CcTest::isolate());
517 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 520 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
518 v8::Context::Scope context_scope(env); 521 v8::Context::Scope context_scope(env);
522 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
519 523
520 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
521 CHECK_EQ(0, profiler->GetProfilesCount());
522 CompileRun( 524 CompileRun(
523 "function c() { startProfiling(); }\n" 525 "function c() { startProfiling(); }\n"
524 "function b() { c(); }\n" 526 "function b() { c(); }\n"
525 "function a() { b(); }\n" 527 "function a() { b(); }\n"
526 "a();\n" 528 "a();\n"
527 "stopProfiling();"); 529 "stopProfiling();");
528 CHECK_EQ(1, profiler->GetProfilesCount()); 530 i::CpuProfiler* iprofiler =
529 CpuProfile* profile = profiler->GetProfile(0); 531 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
532 CHECK_EQ(1, iprofiler->GetProfilesCount());
533 CpuProfile* profile = iprofiler->GetProfile(0);
530 const ProfileTree* topDown = profile->top_down(); 534 const ProfileTree* topDown = profile->top_down();
531 const ProfileNode* current = topDown->root(); 535 const ProfileNode* current = topDown->root();
532 const_cast<ProfileNode*>(current)->Print(0); 536 const_cast<ProfileNode*>(current)->Print(0);
533 // The tree should look like this: 537 // The tree should look like this:
534 // (root) 538 // (root)
535 // "" 539 // ""
536 // a 540 // a
537 // b 541 // b
538 // c 542 // c
539 // There can also be: 543 // There can also be:
(...skipping 11 matching lines...) Expand all
551 current->children()->length() == 1); 555 current->children()->length() == 1);
552 if (current->children()->length() == 1) { 556 if (current->children()->length() == 1) {
553 current = PickChild(current, "startProfiling"); 557 current = PickChild(current, "startProfiling");
554 CHECK_EQ(0, current->children()->length()); 558 CHECK_EQ(0, current->children()->length());
555 } 559 }
556 } 560 }
557 561
558 562
559 TEST(Issue51919) { 563 TEST(Issue51919) {
560 CpuProfilesCollection collection(CcTest::i_isolate()); 564 CpuProfilesCollection collection(CcTest::i_isolate());
561 collection.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 565 CpuProfiler profiler(CcTest::i_isolate());
566 collection.set_cpu_profiler(&profiler);
562 i::EmbeddedVector<char*, 567 i::EmbeddedVector<char*,
563 CpuProfilesCollection::kMaxSimultaneousProfiles> titles; 568 CpuProfilesCollection::kMaxSimultaneousProfiles> titles;
564 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { 569 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
565 i::Vector<char> title = i::Vector<char>::New(16); 570 i::Vector<char> title = i::Vector<char>::New(16);
566 i::SNPrintF(title, "%d", i); 571 i::SNPrintF(title, "%d", i);
567 CHECK(collection.StartProfiling(title.start(), false)); 572 CHECK(collection.StartProfiling(title.start(), false));
568 titles[i] = title.start(); 573 titles[i] = title.start();
569 } 574 }
570 CHECK(!collection.StartProfiling("maximum", false)); 575 CHECK(!collection.StartProfiling("maximum", false));
571 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) 576 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i)
(...skipping 14 matching lines...) Expand all
586 591
587 TEST(ProfileNodeScriptId) { 592 TEST(ProfileNodeScriptId) {
588 // This test does not pass with inlining enabled since inlined functions 593 // This test does not pass with inlining enabled since inlined functions
589 // don't appear in the stack trace. 594 // don't appear in the stack trace.
590 i::FLAG_turbo_inlining = false; 595 i::FLAG_turbo_inlining = false;
591 i::FLAG_use_inlining = false; 596 i::FLAG_use_inlining = false;
592 597
593 v8::HandleScope scope(CcTest::isolate()); 598 v8::HandleScope scope(CcTest::isolate());
594 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 599 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
595 v8::Context::Scope context_scope(env); 600 v8::Context::Scope context_scope(env);
601 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
596 602
597 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
598 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
599 CHECK_EQ(0, iprofiler->GetProfilesCount());
600 v8::Local<v8::Script> script_a = 603 v8::Local<v8::Script> script_a =
601 v8_compile(v8_str("function a() { startProfiling(); }\n")); 604 v8_compile(v8_str("function a() { startProfiling(); }\n"));
602 script_a->Run(v8::Isolate::GetCurrent()->GetCurrentContext()) 605 script_a->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
603 .ToLocalChecked(); 606 .ToLocalChecked();
604 v8::Local<v8::Script> script_b = 607 v8::Local<v8::Script> script_b =
605 v8_compile(v8_str("function b() { a(); }\n" 608 v8_compile(v8_str("function b() { a(); }\n"
606 "b();\n" 609 "b();\n"
607 "stopProfiling();\n")); 610 "stopProfiling();\n"));
608 script_b->Run(v8::Isolate::GetCurrent()->GetCurrentContext()) 611 script_b->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
609 .ToLocalChecked(); 612 .ToLocalChecked();
613 v8::CpuProfiler* profiler = profiler_scope.profiler();
614 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
610 CHECK_EQ(1, iprofiler->GetProfilesCount()); 615 CHECK_EQ(1, iprofiler->GetProfilesCount());
611 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile; 616 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
612 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 617 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
613 reinterpret_cast<ProfileNode*>( 618 reinterpret_cast<ProfileNode*>(
614 const_cast<v8::CpuProfileNode*>(current))->Print(0); 619 const_cast<v8::CpuProfileNode*>(current))->Print(0);
615 // The tree should look like this: 620 // The tree should look like this:
616 // (root) 621 // (root)
617 // "" 622 // ""
618 // b 623 // b
619 // a 624 // a
(...skipping 19 matching lines...) Expand all
639 "function lazy_func_at_forth_line() {}\n"; 644 "function lazy_func_at_forth_line() {}\n";
640 645
641 static const char* line_number_test_source_profile_time_functions = 646 static const char* line_number_test_source_profile_time_functions =
642 "// Empty first line\n" 647 "// Empty first line\n"
643 "function bar_at_the_second_line() {\n" 648 "function bar_at_the_second_line() {\n"
644 " foo_at_the_first_line();\n" 649 " foo_at_the_first_line();\n"
645 "}\n" 650 "}\n"
646 "bar_at_the_second_line();\n" 651 "bar_at_the_second_line();\n"
647 "function lazy_func_at_6th_line() {}"; 652 "function lazy_func_at_6th_line() {}";
648 653
649 int GetFunctionLineNumber(LocalContext* env, const char* name) { 654 int GetFunctionLineNumber(CpuProfiler& profiler, LocalContext& env,
650 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 655 const char* name) {
651 CodeMap* code_map = profiler->generator()->code_map(); 656 CodeMap* code_map = profiler.generator()->code_map();
652 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( 657 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(
653 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 658 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
654 (*(*env)) 659 env->Global()->Get(env.local(), v8_str(name)).ToLocalChecked())));
655 ->Global()
656 ->Get(v8::Isolate::GetCurrent()->GetCurrentContext(),
657 v8_str(name))
658 .ToLocalChecked())));
659 CodeEntry* func_entry = code_map->FindEntry(func->abstract_code()->address()); 660 CodeEntry* func_entry = code_map->FindEntry(func->abstract_code()->address());
660 if (!func_entry) 661 if (!func_entry)
661 FATAL(name); 662 FATAL(name);
662 return func_entry->line_number(); 663 return func_entry->line_number();
663 } 664 }
664 665
665 TEST(LineNumber) { 666 TEST(LineNumber) {
666 i::FLAG_use_inlining = false; 667 i::FLAG_use_inlining = false;
667 668
668 CcTest::InitializeVM(); 669 CcTest::InitializeVM();
669 LocalContext env; 670 LocalContext env;
670 i::Isolate* isolate = CcTest::i_isolate(); 671 i::Isolate* isolate = CcTest::i_isolate();
671 TestSetup test_setup; 672 TestSetup test_setup;
672 673
673 i::HandleScope scope(isolate); 674 i::HandleScope scope(isolate);
674 675
675 CompileRun(line_number_test_source_existing_functions); 676 CompileRun(line_number_test_source_existing_functions);
676 677
677 CpuProfiler* profiler = isolate->cpu_profiler(); 678 CpuProfiler profiler(isolate);
678 profiler->StartProfiling("LineNumber"); 679 profiler.StartProfiling("LineNumber");
679 680
680 CompileRun(line_number_test_source_profile_time_functions); 681 CompileRun(line_number_test_source_profile_time_functions);
681 682
682 profiler->processor()->StopSynchronously(); 683 profiler.processor()->StopSynchronously();
683 684
684 bool is_lazy = i::FLAG_lazy && !(i::FLAG_ignition && i::FLAG_ignition_eager); 685 bool is_lazy = i::FLAG_lazy && !(i::FLAG_ignition && i::FLAG_ignition_eager);
685 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); 686 CHECK_EQ(1, GetFunctionLineNumber(profiler, env, "foo_at_the_first_line"));
686 CHECK_EQ(is_lazy ? 0 : 4, 687 CHECK_EQ(is_lazy ? 0 : 4,
687 GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); 688 GetFunctionLineNumber(profiler, env, "lazy_func_at_forth_line"));
688 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); 689 CHECK_EQ(2, GetFunctionLineNumber(profiler, env, "bar_at_the_second_line"));
689 CHECK_EQ(is_lazy ? 0 : 6, 690 CHECK_EQ(is_lazy ? 0 : 6,
690 GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); 691 GetFunctionLineNumber(profiler, env, "lazy_func_at_6th_line"));
691 692
692 profiler->StopProfiling("LineNumber"); 693 profiler.StopProfiling("LineNumber");
693 } 694 }
694 695
695 TEST(BailoutReason) { 696 TEST(BailoutReason) {
696 v8::HandleScope scope(CcTest::isolate()); 697 v8::HandleScope scope(CcTest::isolate());
697 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 698 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
698 v8::Context::Scope context_scope(env); 699 v8::Context::Scope context_scope(env);
700 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
699 701
700 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 702 i::CpuProfiler* iprofiler =
701 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 703 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
702 CHECK_EQ(0, iprofiler->GetProfilesCount()); 704 CHECK_EQ(0, iprofiler->GetProfilesCount());
703 v8::Local<v8::Script> script = 705 v8::Local<v8::Script> script =
704 v8_compile(v8_str("function Debugger() {\n" 706 v8_compile(v8_str("function Debugger() {\n"
705 " debugger;\n" 707 " debugger;\n"
706 " startProfiling();\n" 708 " startProfiling();\n"
707 "}\n" 709 "}\n"
708 "Debugger();\n" 710 "Debugger();\n"
709 "stopProfiling();")); 711 "stopProfiling();"));
710 script->Run(v8::Isolate::GetCurrent()->GetCurrentContext()).ToLocalChecked(); 712 script->Run(v8::Isolate::GetCurrent()->GetCurrentContext()).ToLocalChecked();
711 CHECK_EQ(1, iprofiler->GetProfilesCount()); 713 CHECK_EQ(1, iprofiler->GetProfilesCount());
712 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile; 714 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
713 CHECK(profile); 715 CHECK(profile);
714 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 716 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
715 reinterpret_cast<ProfileNode*>( 717 reinterpret_cast<ProfileNode*>(
716 const_cast<v8::CpuProfileNode*>(current))->Print(0); 718 const_cast<v8::CpuProfileNode*>(current))->Print(0);
717 // The tree should look like this: 719 // The tree should look like this:
718 // (root) 720 // (root)
719 // "" 721 // ""
720 // kDebuggerStatement 722 // kDebuggerStatement
721 current = PickChild(current, ""); 723 current = PickChild(current, "");
722 CHECK(const_cast<v8::CpuProfileNode*>(current)); 724 CHECK(const_cast<v8::CpuProfileNode*>(current));
723 725
724 current = PickChild(current, "Debugger"); 726 current = PickChild(current, "Debugger");
725 CHECK(const_cast<v8::CpuProfileNode*>(current)); 727 CHECK(const_cast<v8::CpuProfileNode*>(current));
726 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 728 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
727 } 729 }
OLDNEW
« test/cctest/test-cpu-profiler.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