| 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 22 matching lines...) Expand all Loading... |
| 33 #include "cctest.h" | 33 #include "cctest.h" |
| 34 #include "platform.h" | 34 #include "platform.h" |
| 35 #include "utils.h" | 35 #include "utils.h" |
| 36 #include "../include/v8-profiler.h" | 36 #include "../include/v8-profiler.h" |
| 37 #undef V8_DISABLE_DEPRECATIONS | 37 #undef V8_DISABLE_DEPRECATIONS |
| 38 | 38 |
| 39 using i::CodeEntry; | 39 using i::CodeEntry; |
| 40 using i::CpuProfile; | 40 using i::CpuProfile; |
| 41 using i::CpuProfiler; | 41 using i::CpuProfiler; |
| 42 using i::CpuProfilesCollection; | 42 using i::CpuProfilesCollection; |
| 43 using i::Heap; |
| 43 using i::ProfileGenerator; | 44 using i::ProfileGenerator; |
| 44 using i::ProfileNode; | 45 using i::ProfileNode; |
| 45 using i::ProfilerEventsProcessor; | 46 using i::ProfilerEventsProcessor; |
| 46 using i::ScopedVector; | 47 using i::ScopedVector; |
| 47 using i::Vector; | 48 using i::Vector; |
| 48 | 49 |
| 49 | 50 |
| 50 TEST(StartStop) { | 51 TEST(StartStop) { |
| 51 CpuProfilesCollection profiles; | 52 CpuProfilesCollection profiles; |
| 52 ProfileGenerator generator(&profiles); | 53 ProfileGenerator generator(&profiles); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test")); | 406 isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test")); |
| 406 isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test")); | 407 isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test")); |
| 407 } | 408 } |
| 408 CHECK(i::Isolate::Current()->IsInitialized()); | 409 CHECK(i::Isolate::Current()->IsInitialized()); |
| 409 CHECK_NE(NULL, isolate->GetCpuProfiler()); | 410 CHECK_NE(NULL, isolate->GetCpuProfiler()); |
| 410 isolate->Dispose(); | 411 isolate->Dispose(); |
| 411 CHECK_EQ(NULL, isolate->GetCpuProfiler()); | 412 CHECK_EQ(NULL, isolate->GetCpuProfiler()); |
| 412 } | 413 } |
| 413 | 414 |
| 414 | 415 |
| 416 static const v8::CpuProfile* RunProfiler( |
| 417 LocalContext& env, v8::Handle<v8::Function> function, |
| 418 v8::Handle<v8::Value> argv[], int argc, |
| 419 unsigned min_js_samples) { |
| 420 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 421 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 422 |
| 423 cpu_profiler->StartCpuProfiling(profile_name); |
| 424 |
| 425 i::Sampler* sampler = |
| 426 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
| 427 sampler->StartCountingSamples(); |
| 428 do { |
| 429 function->Call(env->Global(), argc, argv); |
| 430 } while (sampler->js_and_external_sample_count() < min_js_samples); |
| 431 |
| 432 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 433 |
| 434 CHECK_NE(NULL, profile); |
| 435 // Dump collected profile to have a better diagnostic in case of failure. |
| 436 reinterpret_cast<i::CpuProfile*>( |
| 437 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 438 |
| 439 return profile; |
| 440 } |
| 441 |
| 442 |
| 415 static bool ContainsString(v8::Handle<v8::String> string, | 443 static bool ContainsString(v8::Handle<v8::String> string, |
| 416 const Vector<v8::Handle<v8::String> >& vector) { | 444 const Vector<v8::Handle<v8::String> >& vector) { |
| 417 for (int i = 0; i < vector.length(); i++) { | 445 for (int i = 0; i < vector.length(); i++) { |
| 418 if (string->Equals(vector[i])) | 446 if (string->Equals(vector[i])) |
| 419 return true; | 447 return true; |
| 420 } | 448 } |
| 421 return false; | 449 return false; |
| 422 } | 450 } |
| 423 | 451 |
| 424 | 452 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // 2 2 (program) [-1] | 546 // 2 2 (program) [-1] |
| 519 // 6 6 (garbage collector) [-1] | 547 // 6 6 (garbage collector) [-1] |
| 520 TEST(CollectCpuProfile) { | 548 TEST(CollectCpuProfile) { |
| 521 LocalContext env; | 549 LocalContext env; |
| 522 v8::HandleScope scope(env->GetIsolate()); | 550 v8::HandleScope scope(env->GetIsolate()); |
| 523 | 551 |
| 524 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); | 552 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); |
| 525 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 553 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 526 env->Global()->Get(v8::String::New("start"))); | 554 env->Global()->Get(v8::String::New("start"))); |
| 527 | 555 |
| 528 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 529 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 530 | |
| 531 cpu_profiler->StartCpuProfiling(profile_name); | |
| 532 int32_t profiling_interval_ms = 200; | 556 int32_t profiling_interval_ms = 200; |
| 533 #if defined(_WIN32) || defined(_WIN64) | |
| 534 // 200ms is not enough on Windows. See | |
| 535 // https://code.google.com/p/v8/issues/detail?id=2628 | |
| 536 profiling_interval_ms = 500; | |
| 537 #endif | |
| 538 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 557 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 558 const v8::CpuProfile* profile = |
| 559 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
| 539 function->Call(env->Global(), ARRAY_SIZE(args), args); | 560 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 540 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 541 | |
| 542 CHECK_NE(NULL, profile); | |
| 543 // Dump collected profile to have a better diagnostic in case of failure. | |
| 544 reinterpret_cast<i::CpuProfile*>( | |
| 545 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 546 | 561 |
| 547 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 562 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 548 | 563 |
| 549 ScopedVector<v8::Handle<v8::String> > names(3); | 564 ScopedVector<v8::Handle<v8::String> > names(3); |
| 550 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 565 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 551 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 566 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 552 names[2] = v8::String::New("start"); | 567 names[2] = v8::String::New("start"); |
| 553 CheckChildrenNames(root, names); | 568 CheckChildrenNames(root, names); |
| 554 | 569 |
| 555 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 570 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 556 CHECK_EQ(1, startNode->GetChildrenCount()); | 571 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 557 | 572 |
| 558 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); | 573 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); |
| 559 CHECK_EQ(3, fooNode->GetChildrenCount()); | 574 CHECK_EQ(3, fooNode->GetChildrenCount()); |
| 560 | 575 |
| 561 const char* barBranch[] = { "bar", "delay", "loop" }; | 576 const char* barBranch[] = { "bar", "delay", "loop" }; |
| 562 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 577 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); |
| 563 const char* bazBranch[] = { "baz", "delay", "loop" }; | 578 const char* bazBranch[] = { "baz", "delay", "loop" }; |
| 564 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 579 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); |
| 565 const char* delayBranch[] = { "delay", "loop" }; | 580 const char* delayBranch[] = { "delay", "loop" }; |
| 566 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); | 581 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); |
| 567 | 582 |
| 583 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 568 cpu_profiler->DeleteAllCpuProfiles(); | 584 cpu_profiler->DeleteAllCpuProfiles(); |
| 569 } | 585 } |
| 570 | 586 |
| 571 | 587 |
| 572 | 588 |
| 573 static const char* cpu_profiler_test_source2 = "function loop() {}\n" | 589 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
| 574 "function delay() { loop(); }\n" | 590 "function delay() { loop(); }\n" |
| 575 "function start(count) {\n" | 591 "function start(count) {\n" |
| 576 " var k = 0;\n" | 592 " var k = 0;\n" |
| 577 " do {\n" | 593 " do {\n" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 591 // 16 16 loop [-1] #5 | 607 // 16 16 loop [-1] #5 |
| 592 // 14 14 (program) [-1] #2 | 608 // 14 14 (program) [-1] #2 |
| 593 TEST(SampleWhenFrameIsNotSetup) { | 609 TEST(SampleWhenFrameIsNotSetup) { |
| 594 LocalContext env; | 610 LocalContext env; |
| 595 v8::HandleScope scope(env->GetIsolate()); | 611 v8::HandleScope scope(env->GetIsolate()); |
| 596 | 612 |
| 597 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run(); | 613 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run(); |
| 598 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 614 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 599 env->Global()->Get(v8::String::New("start"))); | 615 env->Global()->Get(v8::String::New("start"))); |
| 600 | 616 |
| 601 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 602 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 603 | |
| 604 cpu_profiler->StartCpuProfiling(profile_name); | |
| 605 int32_t repeat_count = 100; | 617 int32_t repeat_count = 100; |
| 606 #if defined(USE_SIMULATOR) | 618 #if defined(USE_SIMULATOR) |
| 607 // Simulators are much slower. | 619 // Simulators are much slower. |
| 608 repeat_count = 1; | 620 repeat_count = 1; |
| 609 #endif | 621 #endif |
| 610 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 622 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 611 function->Call(env->Global(), ARRAY_SIZE(args), args); | 623 const v8::CpuProfile* profile = |
| 612 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 624 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 613 | |
| 614 CHECK_NE(NULL, profile); | |
| 615 // Dump collected profile to have a better diagnostic in case of failure. | |
| 616 reinterpret_cast<i::CpuProfile*>( | |
| 617 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 618 | 625 |
| 619 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 626 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 620 | 627 |
| 621 ScopedVector<v8::Handle<v8::String> > names(3); | 628 ScopedVector<v8::Handle<v8::String> > names(3); |
| 622 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 629 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 623 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 630 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 624 names[2] = v8::String::New("start"); | 631 names[2] = v8::String::New("start"); |
| 625 CheckChildrenNames(root, names); | 632 CheckChildrenNames(root, names); |
| 626 | 633 |
| 627 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 634 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
| 628 // On slow machines there may be no meaningfull samples at all, skip the | 635 // On slow machines there may be no meaningfull samples at all, skip the |
| 629 // check there. | 636 // check there. |
| 630 if (startNode && startNode->GetChildrenCount() > 0) { | 637 if (startNode && startNode->GetChildrenCount() > 0) { |
| 631 CHECK_EQ(1, startNode->GetChildrenCount()); | 638 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 632 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); | 639 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); |
| 633 if (delayNode->GetChildrenCount() > 0) { | 640 if (delayNode->GetChildrenCount() > 0) { |
| 634 CHECK_EQ(1, delayNode->GetChildrenCount()); | 641 CHECK_EQ(1, delayNode->GetChildrenCount()); |
| 635 GetChild(delayNode, "loop"); | 642 GetChild(delayNode, "loop"); |
| 636 } | 643 } |
| 637 } | 644 } |
| 638 | 645 |
| 646 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 639 cpu_profiler->DeleteAllCpuProfiles(); | 647 cpu_profiler->DeleteAllCpuProfiles(); |
| 640 } | 648 } |
| 641 | 649 |
| 642 | 650 |
| 643 static const char* native_accessor_test_source = "function start(count) {\n" | 651 static const char* native_accessor_test_source = "function start(count) {\n" |
| 644 " for (var i = 0; i < count; i++) {\n" | 652 " for (var i = 0; i < count; i++) {\n" |
| 645 " var o = instance.foo;\n" | 653 " var o = instance.foo;\n" |
| 646 " instance.foo = o + 1;\n" | 654 " instance.foo = o + 1;\n" |
| 647 " }\n" | 655 " }\n" |
| 648 "}\n"; | 656 "}\n"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 v8::String::New("foo"), &TestApiCallbacks::Getter, | 729 v8::String::New("foo"), &TestApiCallbacks::Getter, |
| 722 &TestApiCallbacks::Setter, data); | 730 &TestApiCallbacks::Setter, data); |
| 723 v8::Local<v8::Function> func = func_template->GetFunction(); | 731 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 724 v8::Local<v8::Object> instance = func->NewInstance(); | 732 v8::Local<v8::Object> instance = func->NewInstance(); |
| 725 env->Global()->Set(v8::String::New("instance"), instance); | 733 env->Global()->Set(v8::String::New("instance"), instance); |
| 726 | 734 |
| 727 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run(); | 735 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run(); |
| 728 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 736 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 729 env->Global()->Get(v8::String::New("start"))); | 737 env->Global()->Get(v8::String::New("start"))); |
| 730 | 738 |
| 731 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 732 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 733 | |
| 734 cpu_profiler->StartCpuProfiling(profile_name); | |
| 735 int32_t repeat_count = 1; | 739 int32_t repeat_count = 1; |
| 736 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 740 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 737 function->Call(env->Global(), ARRAY_SIZE(args), args); | 741 const v8::CpuProfile* profile = |
| 738 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 742 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); |
| 739 | |
| 740 CHECK_NE(NULL, profile); | |
| 741 // Dump collected profile to have a better diagnostic in case of failure. | |
| 742 reinterpret_cast<i::CpuProfile*>( | |
| 743 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 744 | 743 |
| 745 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 744 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 746 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 745 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 747 GetChild(startNode, "get foo"); | 746 GetChild(startNode, "get foo"); |
| 748 GetChild(startNode, "set foo"); | 747 GetChild(startNode, "set foo"); |
| 749 | 748 |
| 749 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 750 cpu_profiler->DeleteAllCpuProfiles(); | 750 cpu_profiler->DeleteAllCpuProfiles(); |
| 751 } | 751 } |
| 752 | 752 |
| 753 | 753 |
| 754 // Test that native accessors are properly reported in the CPU profile. | 754 // Test that native accessors are properly reported in the CPU profile. |
| 755 // This test makes sure that the accessors are called enough times to become | 755 // This test makes sure that the accessors are called enough times to become |
| 756 // hot and to trigger optimizations. | 756 // hot and to trigger optimizations. |
| 757 TEST(NativeAccessorMonomorphicIC) { | 757 TEST(NativeAccessorMonomorphicIC) { |
| 758 LocalContext env; | 758 LocalContext env; |
| 759 v8::HandleScope scope(env->GetIsolate()); | 759 v8::HandleScope scope(env->GetIsolate()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 779 { | 779 { |
| 780 // Make sure accessors ICs are in monomorphic state before starting | 780 // Make sure accessors ICs are in monomorphic state before starting |
| 781 // profiling. | 781 // profiling. |
| 782 accessors.set_warming_up(true); | 782 accessors.set_warming_up(true); |
| 783 int32_t warm_up_iterations = 3; | 783 int32_t warm_up_iterations = 3; |
| 784 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 784 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
| 785 function->Call(env->Global(), ARRAY_SIZE(args), args); | 785 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 786 accessors.set_warming_up(false); | 786 accessors.set_warming_up(false); |
| 787 } | 787 } |
| 788 | 788 |
| 789 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 790 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 791 | |
| 792 cpu_profiler->StartCpuProfiling(profile_name); | |
| 793 int32_t repeat_count = 100; | 789 int32_t repeat_count = 100; |
| 794 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 790 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 795 function->Call(env->Global(), ARRAY_SIZE(args), args); | 791 const v8::CpuProfile* profile = |
| 796 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 792 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
| 797 | |
| 798 CHECK_NE(NULL, profile); | |
| 799 // Dump collected profile to have a better diagnostic in case of failure. | |
| 800 reinterpret_cast<i::CpuProfile*>( | |
| 801 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 802 | 793 |
| 803 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 794 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 804 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 795 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 805 GetChild(startNode, "get foo"); | 796 GetChild(startNode, "get foo"); |
| 806 GetChild(startNode, "set foo"); | 797 GetChild(startNode, "set foo"); |
| 807 | 798 |
| 799 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 808 cpu_profiler->DeleteAllCpuProfiles(); | 800 cpu_profiler->DeleteAllCpuProfiles(); |
| 809 } | 801 } |
| 810 | 802 |
| 811 | 803 |
| 812 static const char* native_method_test_source = "function start(count) {\n" | 804 static const char* native_method_test_source = "function start(count) {\n" |
| 813 " for (var i = 0; i < count; i++) {\n" | 805 " for (var i = 0; i < count; i++) {\n" |
| 814 " instance.fooMethod();\n" | 806 " instance.fooMethod();\n" |
| 815 " }\n" | 807 " }\n" |
| 816 "}\n"; | 808 "}\n"; |
| 817 | 809 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 832 &TestApiCallbacks::Callback, data, signature, 0)); | 824 &TestApiCallbacks::Callback, data, signature, 0)); |
| 833 | 825 |
| 834 v8::Local<v8::Function> func = func_template->GetFunction(); | 826 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 835 v8::Local<v8::Object> instance = func->NewInstance(); | 827 v8::Local<v8::Object> instance = func->NewInstance(); |
| 836 env->Global()->Set(v8::String::New("instance"), instance); | 828 env->Global()->Set(v8::String::New("instance"), instance); |
| 837 | 829 |
| 838 v8::Script::Compile(v8::String::New(native_method_test_source))->Run(); | 830 v8::Script::Compile(v8::String::New(native_method_test_source))->Run(); |
| 839 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 831 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 840 env->Global()->Get(v8::String::New("start"))); | 832 env->Global()->Get(v8::String::New("start"))); |
| 841 | 833 |
| 842 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 843 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 844 | |
| 845 cpu_profiler->StartCpuProfiling(profile_name); | |
| 846 int32_t repeat_count = 1; | 834 int32_t repeat_count = 1; |
| 847 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 835 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 848 function->Call(env->Global(), ARRAY_SIZE(args), args); | 836 const v8::CpuProfile* profile = |
| 849 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 837 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 850 | |
| 851 CHECK_NE(NULL, profile); | |
| 852 // Dump collected profile to have a better diagnostic in case of failure. | |
| 853 reinterpret_cast<i::CpuProfile*>( | |
| 854 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 855 | 838 |
| 856 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 839 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 857 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 840 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 858 GetChild(startNode, "fooMethod"); | 841 GetChild(startNode, "fooMethod"); |
| 859 | 842 |
| 843 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 860 cpu_profiler->DeleteAllCpuProfiles(); | 844 cpu_profiler->DeleteAllCpuProfiles(); |
| 861 } | 845 } |
| 862 | 846 |
| 863 | 847 |
| 864 TEST(NativeMethodMonomorphicIC) { | 848 TEST(NativeMethodMonomorphicIC) { |
| 865 LocalContext env; | 849 LocalContext env; |
| 866 v8::HandleScope scope(env->GetIsolate()); | 850 v8::HandleScope scope(env->GetIsolate()); |
| 867 | 851 |
| 868 TestApiCallbacks callbacks(1); | 852 TestApiCallbacks callbacks(1); |
| 869 v8::Local<v8::External> data = v8::External::New(&callbacks); | 853 v8::Local<v8::External> data = v8::External::New(&callbacks); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 886 { | 870 { |
| 887 // Make sure method ICs are in monomorphic state before starting | 871 // Make sure method ICs are in monomorphic state before starting |
| 888 // profiling. | 872 // profiling. |
| 889 callbacks.set_warming_up(true); | 873 callbacks.set_warming_up(true); |
| 890 int32_t warm_up_iterations = 3; | 874 int32_t warm_up_iterations = 3; |
| 891 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 875 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
| 892 function->Call(env->Global(), ARRAY_SIZE(args), args); | 876 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 893 callbacks.set_warming_up(false); | 877 callbacks.set_warming_up(false); |
| 894 } | 878 } |
| 895 | 879 |
| 896 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 897 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 898 | |
| 899 cpu_profiler->StartCpuProfiling(profile_name); | |
| 900 int32_t repeat_count = 100; | 880 int32_t repeat_count = 100; |
| 901 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 881 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 902 function->Call(env->Global(), ARRAY_SIZE(args), args); | 882 const v8::CpuProfile* profile = |
| 903 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 883 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 904 | |
| 905 CHECK_NE(NULL, profile); | |
| 906 // Dump collected profile to have a better diagnostic in case of failure. | |
| 907 reinterpret_cast<i::CpuProfile*>( | |
| 908 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 909 | 884 |
| 910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 885 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 911 GetChild(root, "start"); | 886 GetChild(root, "start"); |
| 912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 887 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 913 GetChild(startNode, "fooMethod"); | 888 GetChild(startNode, "fooMethod"); |
| 914 | 889 |
| 890 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 915 cpu_profiler->DeleteAllCpuProfiles(); | 891 cpu_profiler->DeleteAllCpuProfiles(); |
| 916 } | 892 } |
| 917 | 893 |
| 918 | 894 |
| 919 static const char* bound_function_test_source = "function foo(iterations) {\n" | 895 static const char* bound_function_test_source = "function foo(iterations) {\n" |
| 920 " var r = 0;\n" | 896 " var r = 0;\n" |
| 921 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 897 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 922 " return r;\n" | 898 " return r;\n" |
| 923 "}\n" | 899 "}\n" |
| 924 "function start(duration) {\n" | 900 "function start(duration) {\n" |
| 925 " var callback = foo.bind(this);\n" | 901 " var callback = foo.bind(this);\n" |
| 926 " var start = Date.now();\n" | 902 " var start = Date.now();\n" |
| 927 " while (Date.now() - start < duration) {\n" | 903 " while (Date.now() - start < duration) {\n" |
| 928 " callback(10 * 1000);\n" | 904 " callback(10 * 1000);\n" |
| 929 " }\n" | 905 " }\n" |
| 930 "}"; | 906 "}"; |
| 931 | 907 |
| 932 | 908 |
| 933 TEST(BoundFunctionCall) { | 909 TEST(BoundFunctionCall) { |
| 934 LocalContext env; | 910 LocalContext env; |
| 935 v8::HandleScope scope(env->GetIsolate()); | 911 v8::HandleScope scope(env->GetIsolate()); |
| 936 | 912 |
| 937 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); | 913 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); |
| 938 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 914 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 939 env->Global()->Get(v8::String::New("start"))); | 915 env->Global()->Get(v8::String::New("start"))); |
| 940 | 916 |
| 941 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 942 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 943 | |
| 944 cpu_profiler->StartCpuProfiling(profile_name); | |
| 945 int32_t duration_ms = 100; | 917 int32_t duration_ms = 100; |
| 946 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 918 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 947 function->Call(env->Global(), ARRAY_SIZE(args), args); | 919 const v8::CpuProfile* profile = |
| 948 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 920 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 949 | |
| 950 CHECK_NE(NULL, profile); | |
| 951 // Dump collected profile to have a better diagnostic in case of failure. | |
| 952 reinterpret_cast<i::CpuProfile*>( | |
| 953 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 954 | 921 |
| 955 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 922 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 956 ScopedVector<v8::Handle<v8::String> > names(3); | 923 ScopedVector<v8::Handle<v8::String> > names(3); |
| 957 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 924 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 958 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 925 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 959 names[2] = v8::String::New("start"); | 926 names[2] = v8::String::New("start"); |
| 960 // Don't allow |foo| node to be at the top level. | 927 // Don't allow |foo| node to be at the top level. |
| 961 CheckChildrenNames(root, names); | 928 CheckChildrenNames(root, names); |
| 962 | 929 |
| 963 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 930 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 964 GetChild(startNode, "foo"); | 931 GetChild(startNode, "foo"); |
| 965 | 932 |
| 933 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 966 cpu_profiler->DeleteAllCpuProfiles(); | 934 cpu_profiler->DeleteAllCpuProfiles(); |
| 967 } | 935 } |
| 968 | 936 |
| 969 | 937 |
| 970 static const char* call_function_test_source = "function bar(iterations) {\n" | 938 static const char* call_function_test_source = "function bar(iterations) {\n" |
| 971 "}\n" | 939 "}\n" |
| 972 "function start(duration) {\n" | 940 "function start(duration) {\n" |
| 973 " var start = Date.now();\n" | 941 " var start = Date.now();\n" |
| 974 " while (Date.now() - start < duration) {\n" | 942 " while (Date.now() - start < duration) {\n" |
| 975 " try {\n" | 943 " try {\n" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 988 // 1 1 (garbage collector) [-1] #4 | 956 // 1 1 (garbage collector) [-1] #4 |
| 989 // 5 0 (unresolved function) [-1] #5 | 957 // 5 0 (unresolved function) [-1] #5 |
| 990 // 5 5 call [-1] #6 | 958 // 5 5 call [-1] #6 |
| 991 // 71 70 start [-1] #3 | 959 // 71 70 start [-1] #3 |
| 992 // 1 1 bar [-1] #7 | 960 // 1 1 bar [-1] #7 |
| 993 // 19 19 (program) [-1] #2 | 961 // 19 19 (program) [-1] #2 |
| 994 TEST(FunctionCallSample) { | 962 TEST(FunctionCallSample) { |
| 995 LocalContext env; | 963 LocalContext env; |
| 996 v8::HandleScope scope(env->GetIsolate()); | 964 v8::HandleScope scope(env->GetIsolate()); |
| 997 | 965 |
| 966 // Collect garbage that might have be generated while installing extensions. |
| 967 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 968 |
| 998 v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); | 969 v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); |
| 999 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 970 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1000 env->Global()->Get(v8::String::New("start"))); | 971 env->Global()->Get(v8::String::New("start"))); |
| 1001 | 972 |
| 1002 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 1003 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 1004 | |
| 1005 cpu_profiler->StartCpuProfiling(profile_name); | |
| 1006 int32_t duration_ms = 100; | 973 int32_t duration_ms = 100; |
| 1007 #if defined(_WIN32) || defined(_WIN64) | |
| 1008 // 100ms is not enough on Windows. See | |
| 1009 // https://code.google.com/p/v8/issues/detail?id=2628 | |
| 1010 duration_ms = 400; | |
| 1011 #endif | |
| 1012 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 974 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1013 function->Call(env->Global(), ARRAY_SIZE(args), args); | 975 const v8::CpuProfile* profile = |
| 1014 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 976 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 1015 | |
| 1016 CHECK_NE(NULL, profile); | |
| 1017 // Dump collected profile to have a better diagnostic in case of failure. | |
| 1018 reinterpret_cast<i::CpuProfile*>( | |
| 1019 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 1020 | 977 |
| 1021 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 978 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1022 { | 979 { |
| 1023 ScopedVector<v8::Handle<v8::String> > names(4); | 980 ScopedVector<v8::Handle<v8::String> > names(4); |
| 1024 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 981 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1025 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 982 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1026 names[2] = v8::String::New("start"); | 983 names[2] = v8::String::New("start"); |
| 1027 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName); | 984 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName); |
| 1028 // Don't allow |bar| and |call| nodes to be at the top level. | 985 // Don't allow |bar| and |call| nodes to be at the top level. |
| 1029 CheckChildrenNames(root, names); | 986 CheckChildrenNames(root, names); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1043 } | 1000 } |
| 1044 | 1001 |
| 1045 const v8::CpuProfileNode* unresolvedNode = | 1002 const v8::CpuProfileNode* unresolvedNode = |
| 1046 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); | 1003 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); |
| 1047 if (unresolvedNode) { | 1004 if (unresolvedNode) { |
| 1048 ScopedVector<v8::Handle<v8::String> > names(1); | 1005 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1049 names[0] = v8::String::New("call"); | 1006 names[0] = v8::String::New("call"); |
| 1050 CheckChildrenNames(unresolvedNode, names); | 1007 CheckChildrenNames(unresolvedNode, names); |
| 1051 } | 1008 } |
| 1052 | 1009 |
| 1010 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1053 cpu_profiler->DeleteAllCpuProfiles(); | 1011 cpu_profiler->DeleteAllCpuProfiles(); |
| 1054 } | 1012 } |
| 1055 | 1013 |
| 1056 | 1014 |
| 1057 static const char* function_apply_test_source = "function bar(iterations) {\n" | 1015 static const char* function_apply_test_source = "function bar(iterations) {\n" |
| 1058 "}\n" | 1016 "}\n" |
| 1059 "function test() {\n" | 1017 "function test() {\n" |
| 1060 " bar.apply(this, [10 * 1000]);\n" | 1018 " bar.apply(this, [10 * 1000]);\n" |
| 1061 "}\n" | 1019 "}\n" |
| 1062 "function start(duration) {\n" | 1020 "function start(duration) {\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1080 // 9 9 apply [-1] #0 5 | 1038 // 9 9 apply [-1] #0 5 |
| 1081 // 10 10 (program) [-1] #0 2 | 1039 // 10 10 (program) [-1] #0 2 |
| 1082 TEST(FunctionApplySample) { | 1040 TEST(FunctionApplySample) { |
| 1083 LocalContext env; | 1041 LocalContext env; |
| 1084 v8::HandleScope scope(env->GetIsolate()); | 1042 v8::HandleScope scope(env->GetIsolate()); |
| 1085 | 1043 |
| 1086 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run(); | 1044 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run(); |
| 1087 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1045 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1088 env->Global()->Get(v8::String::New("start"))); | 1046 env->Global()->Get(v8::String::New("start"))); |
| 1089 | 1047 |
| 1090 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1048 int32_t duration_ms = 100; |
| 1091 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 1049 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1092 | 1050 |
| 1093 cpu_profiler->StartCpuProfiling(profile_name); | 1051 const v8::CpuProfile* profile = |
| 1094 int32_t duration_ms = 100; | 1052 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 1095 #if defined(_WIN32) || defined(_WIN64) | |
| 1096 // 100ms is not enough on Windows. See | |
| 1097 // https://code.google.com/p/v8/issues/detail?id=2628 | |
| 1098 duration_ms = 400; | |
| 1099 #endif | |
| 1100 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | |
| 1101 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 1102 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 1103 | |
| 1104 CHECK_NE(NULL, profile); | |
| 1105 // Dump collected profile to have a better diagnostic in case of failure. | |
| 1106 reinterpret_cast<i::CpuProfile*>( | |
| 1107 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 1108 | 1053 |
| 1109 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1054 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1110 { | 1055 { |
| 1111 ScopedVector<v8::Handle<v8::String> > names(3); | 1056 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1112 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1057 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1113 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1058 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1114 names[2] = v8::String::New("start"); | 1059 names[2] = v8::String::New("start"); |
| 1115 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. | 1060 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. |
| 1116 CheckChildrenNames(root, names); | 1061 CheckChildrenNames(root, names); |
| 1117 } | 1062 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1135 | 1080 |
| 1136 if (const v8::CpuProfileNode* unresolvedNode = | 1081 if (const v8::CpuProfileNode* unresolvedNode = |
| 1137 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { | 1082 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { |
| 1138 ScopedVector<v8::Handle<v8::String> > names(1); | 1083 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1139 names[0] = v8::String::New("apply"); | 1084 names[0] = v8::String::New("apply"); |
| 1140 CheckChildrenNames(unresolvedNode, names); | 1085 CheckChildrenNames(unresolvedNode, names); |
| 1141 GetChild(unresolvedNode, "apply"); | 1086 GetChild(unresolvedNode, "apply"); |
| 1142 } | 1087 } |
| 1143 } | 1088 } |
| 1144 | 1089 |
| 1090 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1145 cpu_profiler->DeleteAllCpuProfiles(); | 1091 cpu_profiler->DeleteAllCpuProfiles(); |
| 1146 } | 1092 } |
| OLD | NEW |