| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 } | 392 } |
| 393 | 393 |
| 394 private: | 394 private: |
| 395 bool old_flag_prof_browser_mode_; | 395 bool old_flag_prof_browser_mode_; |
| 396 }; | 396 }; |
| 397 | 397 |
| 398 } // namespace | 398 } // namespace |
| 399 | 399 |
| 400 TEST(RecordTickSample) { | 400 TEST(RecordTickSample) { |
| 401 TestSetup test_setup; | 401 TestSetup test_setup; |
| 402 CpuProfilesCollection profiles(CcTest::i_isolate()->heap()); | 402 CpuProfilesCollection profiles(CcTest::heap()); |
| 403 profiles.StartProfiling("", 1, false); | 403 profiles.StartProfiling("", 1, false); |
| 404 ProfileGenerator generator(&profiles); | 404 ProfileGenerator generator(&profiles); |
| 405 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 405 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
| 406 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); | 406 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); |
| 407 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); | 407 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); |
| 408 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 408 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
| 409 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); | 409 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); |
| 410 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); | 410 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); |
| 411 | 411 |
| 412 // We are building the following calls tree: | 412 // We are building the following calls tree: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 static void CheckNodeIds(ProfileNode* node, int* expectedId) { | 458 static void CheckNodeIds(ProfileNode* node, int* expectedId) { |
| 459 CHECK_EQ((*expectedId)++, node->id()); | 459 CHECK_EQ((*expectedId)++, node->id()); |
| 460 for (int i = 0; i < node->children()->length(); i++) { | 460 for (int i = 0; i < node->children()->length(); i++) { |
| 461 CheckNodeIds(node->children()->at(i), expectedId); | 461 CheckNodeIds(node->children()->at(i), expectedId); |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 | 465 |
| 466 TEST(SampleIds) { | 466 TEST(SampleIds) { |
| 467 TestSetup test_setup; | 467 TestSetup test_setup; |
| 468 CpuProfilesCollection profiles(CcTest::i_isolate()->heap()); | 468 CpuProfilesCollection profiles(CcTest::heap()); |
| 469 profiles.StartProfiling("", 1, true); | 469 profiles.StartProfiling("", 1, true); |
| 470 ProfileGenerator generator(&profiles); | 470 ProfileGenerator generator(&profiles); |
| 471 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 471 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
| 472 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); | 472 CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb"); |
| 473 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); | 473 CodeEntry* entry3 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc"); |
| 474 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 474 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
| 475 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); | 475 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); |
| 476 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); | 476 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); |
| 477 | 477 |
| 478 // We are building the following calls tree: | 478 // We are building the following calls tree: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 506 CHECK_EQ(3, profile->samples_count()); | 506 CHECK_EQ(3, profile->samples_count()); |
| 507 int expected_id[] = {3, 5, 7}; | 507 int expected_id[] = {3, 5, 7}; |
| 508 for (int i = 0; i < 3; i++) { | 508 for (int i = 0; i < 3; i++) { |
| 509 CHECK_EQ(expected_id[i], profile->sample(i)->id()); | 509 CHECK_EQ(expected_id[i], profile->sample(i)->id()); |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 | 512 |
| 513 | 513 |
| 514 TEST(NoSamples) { | 514 TEST(NoSamples) { |
| 515 TestSetup test_setup; | 515 TestSetup test_setup; |
| 516 CpuProfilesCollection profiles(CcTest::i_isolate()->heap()); | 516 CpuProfilesCollection profiles(CcTest::heap()); |
| 517 profiles.StartProfiling("", 1, false); | 517 profiles.StartProfiling("", 1, false); |
| 518 ProfileGenerator generator(&profiles); | 518 ProfileGenerator generator(&profiles); |
| 519 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 519 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
| 520 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 520 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
| 521 | 521 |
| 522 // We are building the following calls tree: | 522 // We are building the following calls tree: |
| 523 // (root)#1 -> aaa #2 -> aaa #3 - sample1 | 523 // (root)#1 -> aaa #2 -> aaa #3 - sample1 |
| 524 TickSample sample1; | 524 TickSample sample1; |
| 525 sample1.pc = ToAddress(0x1600); | 525 sample1.pc = ToAddress(0x1600); |
| 526 sample1.stack[0] = ToAddress(0x1510); | 526 sample1.stack[0] = ToAddress(0x1510); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 598 } |
| 599 return NULL; | 599 return NULL; |
| 600 } | 600 } |
| 601 | 601 |
| 602 | 602 |
| 603 TEST(RecordStackTraceAtStartProfiling) { | 603 TEST(RecordStackTraceAtStartProfiling) { |
| 604 // This test does not pass with inlining enabled since inlined functions | 604 // This test does not pass with inlining enabled since inlined functions |
| 605 // don't appear in the stack trace. | 605 // don't appear in the stack trace. |
| 606 i::FLAG_use_inlining = false; | 606 i::FLAG_use_inlining = false; |
| 607 | 607 |
| 608 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 608 v8::Isolate* isolate = CcTest::isolate(); |
| 609 v8::HandleScope scope(isolate); | 609 v8::HandleScope scope(isolate); |
| 610 const char* extensions[] = { "v8/profiler" }; | 610 const char* extensions[] = { "v8/profiler" }; |
| 611 v8::ExtensionConfiguration config(1, extensions); | 611 v8::ExtensionConfiguration config(1, extensions); |
| 612 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); | 612 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); |
| 613 context->Enter(); | 613 context->Enter(); |
| 614 | 614 |
| 615 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); | 615 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); |
| 616 CHECK_EQ(0, profiler->GetProfilesCount()); | 616 CHECK_EQ(0, profiler->GetProfilesCount()); |
| 617 CompileRun( | 617 CompileRun( |
| 618 "function c() { startProfiling(); }\n" | 618 "function c() { startProfiling(); }\n" |
| 619 "function b() { c(); }\n" | 619 "function b() { c(); }\n" |
| 620 "function a() { b(); }\n" | 620 "function a() { b(); }\n" |
| 621 "a();\n" | 621 "a();\n" |
| 622 "stopProfiling();"); | 622 "stopProfiling();"); |
| 623 CHECK_EQ(1, profiler->GetProfilesCount()); | 623 CHECK_EQ(1, profiler->GetProfilesCount()); |
| 624 CpuProfile* profile = profiler->GetProfile(0); | 624 CpuProfile* profile = profiler->GetProfile(0); |
| 625 const ProfileTree* topDown = profile->top_down(); | 625 const ProfileTree* topDown = profile->top_down(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 645 CHECK(current->children()->length() == 0 || | 645 CHECK(current->children()->length() == 0 || |
| 646 current->children()->length() == 1); | 646 current->children()->length() == 1); |
| 647 if (current->children()->length() == 1) { | 647 if (current->children()->length() == 1) { |
| 648 current = PickChild(current, "startProfiling"); | 648 current = PickChild(current, "startProfiling"); |
| 649 CHECK_EQ(0, current->children()->length()); | 649 CHECK_EQ(0, current->children()->length()); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 | 653 |
| 654 TEST(Issue51919) { | 654 TEST(Issue51919) { |
| 655 CpuProfilesCollection collection(CcTest::i_isolate()->heap()); | 655 CpuProfilesCollection collection(CcTest::heap()); |
| 656 i::EmbeddedVector<char*, | 656 i::EmbeddedVector<char*, |
| 657 CpuProfilesCollection::kMaxSimultaneousProfiles> titles; | 657 CpuProfilesCollection::kMaxSimultaneousProfiles> titles; |
| 658 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { | 658 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { |
| 659 i::Vector<char> title = i::Vector<char>::New(16); | 659 i::Vector<char> title = i::Vector<char>::New(16); |
| 660 i::OS::SNPrintF(title, "%d", i); | 660 i::OS::SNPrintF(title, "%d", i); |
| 661 // UID must be > 0. | 661 // UID must be > 0. |
| 662 CHECK(collection.StartProfiling(title.start(), i + 1, false)); | 662 CHECK(collection.StartProfiling(title.start(), i + 1, false)); |
| 663 titles[i] = title.start(); | 663 titles[i] = title.start(); |
| 664 } | 664 } |
| 665 CHECK(!collection.StartProfiling( | 665 CHECK(!collection.StartProfiling( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 737 |
| 738 static const char* line_number_test_source_profile_time_functions = | 738 static const char* line_number_test_source_profile_time_functions = |
| 739 "// Empty first line\n" | 739 "// Empty first line\n" |
| 740 "function bar_at_the_second_line() {\n" | 740 "function bar_at_the_second_line() {\n" |
| 741 " foo_at_the_first_line();\n" | 741 " foo_at_the_first_line();\n" |
| 742 "}\n" | 742 "}\n" |
| 743 "bar_at_the_second_line();\n" | 743 "bar_at_the_second_line();\n" |
| 744 "function lazy_func_at_6th_line() {}"; | 744 "function lazy_func_at_6th_line() {}"; |
| 745 | 745 |
| 746 int GetFunctionLineNumber(LocalContext* env, const char* name) { | 746 int GetFunctionLineNumber(LocalContext* env, const char* name) { |
| 747 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); | 747 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); |
| 748 CodeMap* code_map = profiler->generator()->code_map(); | 748 CodeMap* code_map = profiler->generator()->code_map(); |
| 749 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle( | 749 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle( |
| 750 *v8::Local<v8::Function>::Cast( | 750 *v8::Local<v8::Function>::Cast( |
| 751 (*(*env))->Global()->Get(v8_str(name)))); | 751 (*(*env))->Global()->Get(v8_str(name)))); |
| 752 CodeEntry* func_entry = code_map->FindEntry(func->code()->address()); | 752 CodeEntry* func_entry = code_map->FindEntry(func->code()->address()); |
| 753 if (!func_entry) | 753 if (!func_entry) |
| 754 FATAL(name); | 754 FATAL(name); |
| 755 return func_entry->line_number(); | 755 return func_entry->line_number(); |
| 756 } | 756 } |
| 757 | 757 |
| 758 | 758 |
| 759 TEST(LineNumber) { | 759 TEST(LineNumber) { |
| 760 i::FLAG_use_inlining = false; | 760 i::FLAG_use_inlining = false; |
| 761 | 761 |
| 762 CcTest::InitializeVM(); | 762 CcTest::InitializeVM(); |
| 763 LocalContext env; | 763 LocalContext env; |
| 764 i::Isolate* isolate = i::Isolate::Current(); | 764 i::Isolate* isolate = CcTest::i_isolate(); |
| 765 TestSetup test_setup; | 765 TestSetup test_setup; |
| 766 | 766 |
| 767 i::HandleScope scope(isolate); | 767 i::HandleScope scope(isolate); |
| 768 | 768 |
| 769 CompileRun(line_number_test_source_existing_functions); | 769 CompileRun(line_number_test_source_existing_functions); |
| 770 | 770 |
| 771 CpuProfiler* profiler = isolate->cpu_profiler(); | 771 CpuProfiler* profiler = isolate->cpu_profiler(); |
| 772 profiler->StartProfiling("LineNumber"); | 772 profiler->StartProfiling("LineNumber"); |
| 773 | 773 |
| 774 CompileRun(line_number_test_source_profile_time_functions); | 774 CompileRun(line_number_test_source_profile_time_functions); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); | 821 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 822 | 822 |
| 823 current = PickChild(current, "TryFinally"); | 823 current = PickChild(current, "TryFinally"); |
| 824 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); | 824 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 825 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason())); | 825 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason())); |
| 826 | 826 |
| 827 current = PickChild(current, "TryCatch"); | 827 current = PickChild(current, "TryCatch"); |
| 828 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); | 828 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 829 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason())); | 829 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason())); |
| 830 } | 830 } |
| OLD | NEW |