OLD | NEW |
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 337 } |
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::heap()); | 347 CpuProfilesCollection profiles(CcTest::i_isolate()); |
| 348 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); |
348 profiles.StartProfiling("", false); | 349 profiles.StartProfiling("", false); |
349 ProfileGenerator generator(&profiles); | 350 ProfileGenerator generator(&profiles); |
350 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 351 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
351 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); | 352 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); |
352 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); | 353 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); |
353 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 354 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
354 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); | 355 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); |
355 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); | 356 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); |
356 | 357 |
357 // We are building the following calls tree: | 358 // We are building the following calls tree: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { | 404 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { |
404 CHECK_EQ((*expectedId)++, node->id()); | 405 CHECK_EQ((*expectedId)++, node->id()); |
405 for (int i = 0; i < node->children()->length(); i++) { | 406 for (int i = 0; i < node->children()->length(); i++) { |
406 CheckNodeIds(node->children()->at(i), expectedId); | 407 CheckNodeIds(node->children()->at(i), expectedId); |
407 } | 408 } |
408 } | 409 } |
409 | 410 |
410 | 411 |
411 TEST(SampleIds) { | 412 TEST(SampleIds) { |
412 TestSetup test_setup; | 413 TestSetup test_setup; |
413 CpuProfilesCollection profiles(CcTest::heap()); | 414 CpuProfilesCollection profiles(CcTest::i_isolate()); |
| 415 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); |
414 profiles.StartProfiling("", true); | 416 profiles.StartProfiling("", true); |
415 ProfileGenerator generator(&profiles); | 417 ProfileGenerator generator(&profiles); |
416 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 418 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
417 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); | 419 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); |
418 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); | 420 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); |
419 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 421 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
420 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); | 422 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); |
421 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); | 423 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); |
422 | 424 |
423 // We are building the following calls tree: | 425 // We are building the following calls tree: |
(...skipping 30 matching lines...) Expand all Loading... |
454 CHECK_EQ(3, profile->samples_count()); | 456 CHECK_EQ(3, profile->samples_count()); |
455 unsigned expected_id[] = {3, 5, 7}; | 457 unsigned expected_id[] = {3, 5, 7}; |
456 for (int i = 0; i < 3; i++) { | 458 for (int i = 0; i < 3; i++) { |
457 CHECK_EQ(expected_id[i], profile->sample(i)->id()); | 459 CHECK_EQ(expected_id[i], profile->sample(i)->id()); |
458 } | 460 } |
459 } | 461 } |
460 | 462 |
461 | 463 |
462 TEST(NoSamples) { | 464 TEST(NoSamples) { |
463 TestSetup test_setup; | 465 TestSetup test_setup; |
464 CpuProfilesCollection profiles(CcTest::heap()); | 466 CpuProfilesCollection profiles(CcTest::i_isolate()); |
| 467 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); |
465 profiles.StartProfiling("", false); | 468 profiles.StartProfiling("", false); |
466 ProfileGenerator generator(&profiles); | 469 ProfileGenerator generator(&profiles); |
467 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 470 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
468 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 471 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
469 | 472 |
470 // We are building the following calls tree: | 473 // We are building the following calls tree: |
471 // (root)#1 -> aaa #2 -> aaa #3 - sample1 | 474 // (root)#1 -> aaa #2 -> aaa #3 - sample1 |
472 TickSample sample1; | 475 TickSample sample1; |
473 sample1.pc = ToAddress(0x1600); | 476 sample1.pc = ToAddress(0x1600); |
474 sample1.stack[0] = ToAddress(0x1510); | 477 sample1.stack[0] = ToAddress(0x1510); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 CHECK(current->children()->length() == 0 || | 540 CHECK(current->children()->length() == 0 || |
538 current->children()->length() == 1); | 541 current->children()->length() == 1); |
539 if (current->children()->length() == 1) { | 542 if (current->children()->length() == 1) { |
540 current = PickChild(current, "startProfiling"); | 543 current = PickChild(current, "startProfiling"); |
541 CHECK_EQ(0, current->children()->length()); | 544 CHECK_EQ(0, current->children()->length()); |
542 } | 545 } |
543 } | 546 } |
544 | 547 |
545 | 548 |
546 TEST(Issue51919) { | 549 TEST(Issue51919) { |
547 CpuProfilesCollection collection(CcTest::heap()); | 550 CpuProfilesCollection collection(CcTest::i_isolate()); |
| 551 collection.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); |
548 i::EmbeddedVector<char*, | 552 i::EmbeddedVector<char*, |
549 CpuProfilesCollection::kMaxSimultaneousProfiles> titles; | 553 CpuProfilesCollection::kMaxSimultaneousProfiles> titles; |
550 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { | 554 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { |
551 i::Vector<char> title = i::Vector<char>::New(16); | 555 i::Vector<char> title = i::Vector<char>::New(16); |
552 i::SNPrintF(title, "%d", i); | 556 i::SNPrintF(title, "%d", i); |
553 CHECK(collection.StartProfiling(title.start(), false)); | 557 CHECK(collection.StartProfiling(title.start(), false)); |
554 titles[i] = title.start(); | 558 titles[i] = title.start(); |
555 } | 559 } |
556 CHECK(!collection.StartProfiling("maximum", false)); | 560 CHECK(!collection.StartProfiling("maximum", false)); |
557 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) | 561 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 615 |
612 current = PickChild(current, "b"); | 616 current = PickChild(current, "b"); |
613 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 617 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
614 CHECK_EQ(script_b->GetUnboundScript()->GetId(), current->GetScriptId()); | 618 CHECK_EQ(script_b->GetUnboundScript()->GetId(), current->GetScriptId()); |
615 | 619 |
616 current = PickChild(current, "a"); | 620 current = PickChild(current, "a"); |
617 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 621 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
618 CHECK_EQ(script_a->GetUnboundScript()->GetId(), current->GetScriptId()); | 622 CHECK_EQ(script_a->GetUnboundScript()->GetId(), current->GetScriptId()); |
619 } | 623 } |
620 | 624 |
621 | |
622 | |
623 | |
624 static const char* line_number_test_source_existing_functions = | 625 static const char* line_number_test_source_existing_functions = |
625 "function foo_at_the_first_line() {\n" | 626 "function foo_at_the_first_line() {\n" |
626 "}\n" | 627 "}\n" |
627 "foo_at_the_first_line();\n" | 628 "foo_at_the_first_line();\n" |
628 "function lazy_func_at_forth_line() {}\n"; | 629 "function lazy_func_at_forth_line() {}\n"; |
629 | 630 |
630 | |
631 static const char* line_number_test_source_profile_time_functions = | 631 static const char* line_number_test_source_profile_time_functions = |
632 "// Empty first line\n" | 632 "// Empty first line\n" |
633 "function bar_at_the_second_line() {\n" | 633 "function bar_at_the_second_line() {\n" |
634 " foo_at_the_first_line();\n" | 634 " foo_at_the_first_line();\n" |
635 "}\n" | 635 "}\n" |
636 "bar_at_the_second_line();\n" | 636 "bar_at_the_second_line();\n" |
637 "function lazy_func_at_6th_line() {}"; | 637 "function lazy_func_at_6th_line() {}"; |
638 | 638 |
639 int GetFunctionLineNumber(LocalContext* env, const char* name) { | 639 int GetFunctionLineNumber(LocalContext* env, const char* name) { |
640 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); | 640 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); |
641 CodeMap* code_map = profiler->generator()->code_map(); | 641 CodeMap* code_map = profiler->generator()->code_map(); |
642 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( | 642 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( |
643 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 643 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
644 (*(*env)) | 644 (*(*env)) |
645 ->Global() | 645 ->Global() |
646 ->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), | 646 ->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), |
647 v8_str(name)) | 647 v8_str(name)) |
648 .ToLocalChecked()))); | 648 .ToLocalChecked()))); |
649 CodeEntry* func_entry = code_map->FindEntry(func->abstract_code()->address()); | 649 CodeEntry* func_entry = code_map->FindEntry(func->abstract_code()->address()); |
650 if (!func_entry) | 650 if (!func_entry) |
651 FATAL(name); | 651 FATAL(name); |
652 return func_entry->line_number(); | 652 return func_entry->line_number(); |
653 } | 653 } |
654 | 654 |
655 | |
656 TEST(LineNumber) { | 655 TEST(LineNumber) { |
657 i::FLAG_use_inlining = false; | 656 i::FLAG_use_inlining = false; |
658 | 657 |
659 CcTest::InitializeVM(); | 658 CcTest::InitializeVM(); |
660 LocalContext env; | 659 LocalContext env; |
661 i::Isolate* isolate = CcTest::i_isolate(); | 660 i::Isolate* isolate = CcTest::i_isolate(); |
662 TestSetup test_setup; | 661 TestSetup test_setup; |
663 | 662 |
664 i::HandleScope scope(isolate); | 663 i::HandleScope scope(isolate); |
665 | 664 |
(...skipping 10 matching lines...) Expand all Loading... |
676 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); | 675 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); |
677 CHECK_EQ(is_lazy ? 0 : 4, | 676 CHECK_EQ(is_lazy ? 0 : 4, |
678 GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); | 677 GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); |
679 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); | 678 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); |
680 CHECK_EQ(is_lazy ? 0 : 6, | 679 CHECK_EQ(is_lazy ? 0 : 6, |
681 GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); | 680 GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); |
682 | 681 |
683 profiler->StopProfiling("LineNumber"); | 682 profiler->StopProfiling("LineNumber"); |
684 } | 683 } |
685 | 684 |
686 | |
687 | |
688 TEST(BailoutReason) { | 685 TEST(BailoutReason) { |
689 v8::HandleScope scope(CcTest::isolate()); | 686 v8::HandleScope scope(CcTest::isolate()); |
690 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 687 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
691 v8::Context::Scope context_scope(env); | 688 v8::Context::Scope context_scope(env); |
692 | 689 |
693 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); | 690 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
694 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); | 691 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
695 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 692 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
696 v8::Local<v8::Script> script = | 693 v8::Local<v8::Script> script = |
697 v8_compile(v8_str("function Debugger() {\n" | 694 v8_compile(v8_str("function Debugger() {\n" |
(...skipping 13 matching lines...) Expand all Loading... |
711 // (root) | 708 // (root) |
712 // "" | 709 // "" |
713 // kDebuggerStatement | 710 // kDebuggerStatement |
714 current = PickChild(current, ""); | 711 current = PickChild(current, ""); |
715 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 712 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
716 | 713 |
717 current = PickChild(current, "Debugger"); | 714 current = PickChild(current, "Debugger"); |
718 CHECK(const_cast<v8::CpuProfileNode*>(current)); | 715 CHECK(const_cast<v8::CpuProfileNode*>(current)); |
719 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); | 716 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); |
720 } | 717 } |
OLD | NEW |