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

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: Remove ProfilerExtension::Scope 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
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('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 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 std::unique_ptr<i::CpuProfiler> iprofiler(
523 new i::CpuProfiler(CcTest::i_isolate()));
524 i::ProfilerExtension::set_profiler(iprofiler.get());
519 525
520 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
521 CHECK_EQ(0, profiler->GetProfilesCount());
522 CompileRun( 526 CompileRun(
523 "function c() { startProfiling(); }\n" 527 "function c() { startProfiling(); }\n"
524 "function b() { c(); }\n" 528 "function b() { c(); }\n"
525 "function a() { b(); }\n" 529 "function a() { b(); }\n"
526 "a();\n" 530 "a();\n"
527 "stopProfiling();"); 531 "stopProfiling();");
528 CHECK_EQ(1, profiler->GetProfilesCount()); 532 CHECK_EQ(1, iprofiler->GetProfilesCount());
529 CpuProfile* profile = profiler->GetProfile(0); 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 std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate()));
602 i::ProfilerExtension::set_profiler(iprofiler.get());
596 603
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 = 604 v8::Local<v8::Script> script_a =
601 v8_compile(v8_str("function a() { startProfiling(); }\n")); 605 v8_compile(v8_str("function a() { startProfiling(); }\n"));
602 script_a->Run(v8::Isolate::GetCurrent()->GetCurrentContext()) 606 script_a->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
603 .ToLocalChecked(); 607 .ToLocalChecked();
604 v8::Local<v8::Script> script_b = 608 v8::Local<v8::Script> script_b =
605 v8_compile(v8_str("function b() { a(); }\n" 609 v8_compile(v8_str("function b() { a(); }\n"
606 "b();\n" 610 "b();\n"
607 "stopProfiling();\n")); 611 "stopProfiling();\n"));
608 script_b->Run(v8::Isolate::GetCurrent()->GetCurrentContext()) 612 script_b->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
609 .ToLocalChecked(); 613 .ToLocalChecked();
(...skipping 29 matching lines...) Expand all
639 "function lazy_func_at_forth_line() {}\n"; 643 "function lazy_func_at_forth_line() {}\n";
640 644
641 static const char* line_number_test_source_profile_time_functions = 645 static const char* line_number_test_source_profile_time_functions =
642 "// Empty first line\n" 646 "// Empty first line\n"
643 "function bar_at_the_second_line() {\n" 647 "function bar_at_the_second_line() {\n"
644 " foo_at_the_first_line();\n" 648 " foo_at_the_first_line();\n"
645 "}\n" 649 "}\n"
646 "bar_at_the_second_line();\n" 650 "bar_at_the_second_line();\n"
647 "function lazy_func_at_6th_line() {}"; 651 "function lazy_func_at_6th_line() {}";
648 652
649 int GetFunctionLineNumber(LocalContext* env, const char* name) { 653 int GetFunctionLineNumber(CpuProfiler& profiler, LocalContext& env,
650 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 654 const char* name) {
651 CodeMap* code_map = profiler->generator()->code_map(); 655 CodeMap* code_map = profiler.generator()->code_map();
652 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( 656 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(
653 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 657 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
654 (*(*env)) 658 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()); 659 CodeEntry* func_entry = code_map->FindEntry(func->abstract_code()->address());
660 if (!func_entry) 660 if (!func_entry)
661 FATAL(name); 661 FATAL(name);
662 return func_entry->line_number(); 662 return func_entry->line_number();
663 } 663 }
664 664
665 TEST(LineNumber) { 665 TEST(LineNumber) {
666 i::FLAG_use_inlining = false; 666 i::FLAG_use_inlining = false;
667 667
668 CcTest::InitializeVM(); 668 CcTest::InitializeVM();
669 LocalContext env; 669 LocalContext env;
670 i::Isolate* isolate = CcTest::i_isolate(); 670 i::Isolate* isolate = CcTest::i_isolate();
671 TestSetup test_setup; 671 TestSetup test_setup;
672 672
673 i::HandleScope scope(isolate); 673 i::HandleScope scope(isolate);
674 674
675 CompileRun(line_number_test_source_existing_functions); 675 CompileRun(line_number_test_source_existing_functions);
676 676
677 CpuProfiler* profiler = isolate->cpu_profiler(); 677 CpuProfiler profiler(isolate);
678 profiler->StartProfiling("LineNumber"); 678 profiler.StartProfiling("LineNumber");
679 679
680 CompileRun(line_number_test_source_profile_time_functions); 680 CompileRun(line_number_test_source_profile_time_functions);
681 681
682 profiler->processor()->StopSynchronously(); 682 profiler.processor()->StopSynchronously();
683 683
684 bool is_lazy = i::FLAG_lazy && !(i::FLAG_ignition && i::FLAG_ignition_eager); 684 bool is_lazy = i::FLAG_lazy && !(i::FLAG_ignition && i::FLAG_ignition_eager);
685 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); 685 CHECK_EQ(1, GetFunctionLineNumber(profiler, env, "foo_at_the_first_line"));
686 CHECK_EQ(is_lazy ? 0 : 4, 686 CHECK_EQ(is_lazy ? 0 : 4,
687 GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); 687 GetFunctionLineNumber(profiler, env, "lazy_func_at_forth_line"));
688 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); 688 CHECK_EQ(2, GetFunctionLineNumber(profiler, env, "bar_at_the_second_line"));
689 CHECK_EQ(is_lazy ? 0 : 6, 689 CHECK_EQ(is_lazy ? 0 : 6,
690 GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); 690 GetFunctionLineNumber(profiler, env, "lazy_func_at_6th_line"));
691 691
692 profiler->StopProfiling("LineNumber"); 692 profiler.StopProfiling("LineNumber");
693 } 693 }
694 694
695 TEST(BailoutReason) { 695 TEST(BailoutReason) {
696 v8::HandleScope scope(CcTest::isolate()); 696 v8::HandleScope scope(CcTest::isolate());
697 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 697 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
698 v8::Context::Scope context_scope(env); 698 v8::Context::Scope context_scope(env);
699 std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate()));
700 i::ProfilerExtension::set_profiler(iprofiler.get());
699 701
700 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
701 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
702 CHECK_EQ(0, iprofiler->GetProfilesCount()); 702 CHECK_EQ(0, iprofiler->GetProfilesCount());
703 v8::Local<v8::Script> script = 703 v8::Local<v8::Script> script =
704 v8_compile(v8_str("function Debugger() {\n" 704 v8_compile(v8_str("function Debugger() {\n"
705 " debugger;\n" 705 " debugger;\n"
706 " startProfiling();\n" 706 " startProfiling();\n"
707 "}\n" 707 "}\n"
708 "Debugger();\n" 708 "Debugger();\n"
709 "stopProfiling();")); 709 "stopProfiling();"));
710 script->Run(v8::Isolate::GetCurrent()->GetCurrentContext()).ToLocalChecked(); 710 script->Run(v8::Isolate::GetCurrent()->GetCurrentContext()).ToLocalChecked();
711 CHECK_EQ(1, iprofiler->GetProfilesCount()); 711 CHECK_EQ(1, iprofiler->GetProfilesCount());
712 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile; 712 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
713 CHECK(profile); 713 CHECK(profile);
714 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 714 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
715 reinterpret_cast<ProfileNode*>( 715 reinterpret_cast<ProfileNode*>(
716 const_cast<v8::CpuProfileNode*>(current))->Print(0); 716 const_cast<v8::CpuProfileNode*>(current))->Print(0);
717 // The tree should look like this: 717 // The tree should look like this:
718 // (root) 718 // (root)
719 // "" 719 // ""
720 // kDebuggerStatement 720 // kDebuggerStatement
721 current = PickChild(current, ""); 721 current = PickChild(current, "");
722 CHECK(const_cast<v8::CpuProfileNode*>(current)); 722 CHECK(const_cast<v8::CpuProfileNode*>(current));
723 723
724 current = PickChild(current, "Debugger"); 724 current = PickChild(current, "Debugger");
725 CHECK(const_cast<v8::CpuProfileNode*>(current)); 725 CHECK(const_cast<v8::CpuProfileNode*>(current));
726 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 726 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
727 } 727 }
OLDNEW
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698