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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 18418004: Improve test-cpu-profiler.cc tests stability (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/sampler.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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test")); 465 isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test"));
466 isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test")); 466 isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test"));
467 } 467 }
468 CHECK(i::Isolate::Current()->IsInitialized()); 468 CHECK(i::Isolate::Current()->IsInitialized());
469 CHECK_NE(NULL, isolate->GetCpuProfiler()); 469 CHECK_NE(NULL, isolate->GetCpuProfiler());
470 isolate->Dispose(); 470 isolate->Dispose();
471 CHECK_EQ(NULL, isolate->GetCpuProfiler()); 471 CHECK_EQ(NULL, isolate->GetCpuProfiler());
472 } 472 }
473 473
474 474
475 static const v8::CpuProfile* RunProfiler(
476 LocalContext& env, v8::Handle<v8::Function> function,
477 v8::Handle<v8::Value> argv[], int argc,
478 unsigned min_js_samples) {
479 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
480 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
481
482 cpu_profiler->StartCpuProfiling(profile_name);
483
484 i::Sampler* sampler =
485 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler();
486 sampler->StartCountingSamples();
487 do {
488 function->Call(env->Global(), argc, argv);
489 } while (sampler->js_and_external_sample_count() < min_js_samples);
490
491 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
492
493 CHECK_NE(NULL, profile);
494 // Dump collected profile to have a better diagnostic in case of failure.
495 reinterpret_cast<i::CpuProfile*>(
496 const_cast<v8::CpuProfile*>(profile))->Print();
497
498 return profile;
499 }
500
501
475 static bool ContainsString(v8::Handle<v8::String> string, 502 static bool ContainsString(v8::Handle<v8::String> string,
476 const Vector<v8::Handle<v8::String> >& vector) { 503 const Vector<v8::Handle<v8::String> >& vector) {
477 for (int i = 0; i < vector.length(); i++) { 504 for (int i = 0; i < vector.length(); i++) {
478 if (string->Equals(vector[i])) 505 if (string->Equals(vector[i]))
479 return true; 506 return true;
480 } 507 }
481 return false; 508 return false;
482 } 509 }
483 510
484 511
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // 2 2 (program) [-1] 605 // 2 2 (program) [-1]
579 // 6 6 (garbage collector) [-1] 606 // 6 6 (garbage collector) [-1]
580 TEST(CollectCpuProfile) { 607 TEST(CollectCpuProfile) {
581 LocalContext env; 608 LocalContext env;
582 v8::HandleScope scope(env->GetIsolate()); 609 v8::HandleScope scope(env->GetIsolate());
583 610
584 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); 611 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run();
585 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 612 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
586 env->Global()->Get(v8::String::New("start"))); 613 env->Global()->Get(v8::String::New("start")));
587 614
588 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
589 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
590
591 cpu_profiler->StartCpuProfiling(profile_name);
592 int32_t profiling_interval_ms = 200; 615 int32_t profiling_interval_ms = 200;
593 #if defined(_WIN32) || defined(_WIN64)
594 // 200ms is not enough on Windows. See
595 // https://code.google.com/p/v8/issues/detail?id=2628
596 profiling_interval_ms = 500;
597 #endif
598 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; 616 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) };
617 const v8::CpuProfile* profile =
618 RunProfiler(env, function, args, ARRAY_SIZE(args), 200);
599 function->Call(env->Global(), ARRAY_SIZE(args), args); 619 function->Call(env->Global(), ARRAY_SIZE(args), args);
600 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
601
602 CHECK_NE(NULL, profile);
603 // Dump collected profile to have a better diagnostic in case of failure.
604 reinterpret_cast<i::CpuProfile*>(
605 const_cast<v8::CpuProfile*>(profile))->Print();
606 620
607 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 621 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
608 622
609 ScopedVector<v8::Handle<v8::String> > names(3); 623 ScopedVector<v8::Handle<v8::String> > names(3);
610 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 624 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
611 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 625 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
612 names[2] = v8::String::New("start"); 626 names[2] = v8::String::New("start");
613 CheckChildrenNames(root, names); 627 CheckChildrenNames(root, names);
614 628
615 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 629 const v8::CpuProfileNode* startNode = GetChild(root, "start");
616 CHECK_EQ(1, startNode->GetChildrenCount()); 630 CHECK_EQ(1, startNode->GetChildrenCount());
617 631
618 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); 632 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo");
619 CHECK_EQ(3, fooNode->GetChildrenCount()); 633 CHECK_EQ(3, fooNode->GetChildrenCount());
620 634
621 const char* barBranch[] = { "bar", "delay", "loop" }; 635 const char* barBranch[] = { "bar", "delay", "loop" };
622 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); 636 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch));
623 const char* bazBranch[] = { "baz", "delay", "loop" }; 637 const char* bazBranch[] = { "baz", "delay", "loop" };
624 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); 638 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch));
625 const char* delayBranch[] = { "delay", "loop" }; 639 const char* delayBranch[] = { "delay", "loop" };
626 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); 640 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch));
627 641
642 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
628 cpu_profiler->DeleteAllCpuProfiles(); 643 cpu_profiler->DeleteAllCpuProfiles();
629 } 644 }
630 645
631 646
632 647
633 static const char* cpu_profiler_test_source2 = "function loop() {}\n" 648 static const char* cpu_profiler_test_source2 = "function loop() {}\n"
634 "function delay() { loop(); }\n" 649 "function delay() { loop(); }\n"
635 "function start(count) {\n" 650 "function start(count) {\n"
636 " var k = 0;\n" 651 " var k = 0;\n"
637 " do {\n" 652 " do {\n"
(...skipping 13 matching lines...) Expand all
651 // 16 16 loop [-1] #5 666 // 16 16 loop [-1] #5
652 // 14 14 (program) [-1] #2 667 // 14 14 (program) [-1] #2
653 TEST(SampleWhenFrameIsNotSetup) { 668 TEST(SampleWhenFrameIsNotSetup) {
654 LocalContext env; 669 LocalContext env;
655 v8::HandleScope scope(env->GetIsolate()); 670 v8::HandleScope scope(env->GetIsolate());
656 671
657 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run(); 672 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run();
658 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 673 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
659 env->Global()->Get(v8::String::New("start"))); 674 env->Global()->Get(v8::String::New("start")));
660 675
661 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
662 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
663
664 cpu_profiler->StartCpuProfiling(profile_name);
665 int32_t repeat_count = 100; 676 int32_t repeat_count = 100;
666 #if defined(USE_SIMULATOR) 677 #if defined(USE_SIMULATOR)
667 // Simulators are much slower. 678 // Simulators are much slower.
668 repeat_count = 1; 679 repeat_count = 1;
669 #endif 680 #endif
670 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 681 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
671 function->Call(env->Global(), ARRAY_SIZE(args), args); 682 const v8::CpuProfile* profile =
672 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 683 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
673
674 CHECK_NE(NULL, profile);
675 // Dump collected profile to have a better diagnostic in case of failure.
676 reinterpret_cast<i::CpuProfile*>(
677 const_cast<v8::CpuProfile*>(profile))->Print();
678 684
679 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 685 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
680 686
681 ScopedVector<v8::Handle<v8::String> > names(3); 687 ScopedVector<v8::Handle<v8::String> > names(3);
682 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 688 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
683 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 689 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
684 names[2] = v8::String::New("start"); 690 names[2] = v8::String::New("start");
685 CheckChildrenNames(root, names); 691 CheckChildrenNames(root, names);
686 692
687 const v8::CpuProfileNode* startNode = FindChild(root, "start"); 693 const v8::CpuProfileNode* startNode = FindChild(root, "start");
688 // On slow machines there may be no meaningfull samples at all, skip the 694 // On slow machines there may be no meaningfull samples at all, skip the
689 // check there. 695 // check there.
690 if (startNode && startNode->GetChildrenCount() > 0) { 696 if (startNode && startNode->GetChildrenCount() > 0) {
691 CHECK_EQ(1, startNode->GetChildrenCount()); 697 CHECK_EQ(1, startNode->GetChildrenCount());
692 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); 698 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay");
693 if (delayNode->GetChildrenCount() > 0) { 699 if (delayNode->GetChildrenCount() > 0) {
694 CHECK_EQ(1, delayNode->GetChildrenCount()); 700 CHECK_EQ(1, delayNode->GetChildrenCount());
695 GetChild(delayNode, "loop"); 701 GetChild(delayNode, "loop");
696 } 702 }
697 } 703 }
698 704
705 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
699 cpu_profiler->DeleteAllCpuProfiles(); 706 cpu_profiler->DeleteAllCpuProfiles();
700 } 707 }
701 708
702 709
703 static const char* native_accessor_test_source = "function start(count) {\n" 710 static const char* native_accessor_test_source = "function start(count) {\n"
704 " for (var i = 0; i < count; i++) {\n" 711 " for (var i = 0; i < count; i++) {\n"
705 " var o = instance.foo;\n" 712 " var o = instance.foo;\n"
706 " instance.foo = o + 1;\n" 713 " instance.foo = o + 1;\n"
707 " }\n" 714 " }\n"
708 "}\n"; 715 "}\n";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 v8::String::New("foo"), &TestApiCallbacks::Getter, 788 v8::String::New("foo"), &TestApiCallbacks::Getter,
782 &TestApiCallbacks::Setter, data); 789 &TestApiCallbacks::Setter, data);
783 v8::Local<v8::Function> func = func_template->GetFunction(); 790 v8::Local<v8::Function> func = func_template->GetFunction();
784 v8::Local<v8::Object> instance = func->NewInstance(); 791 v8::Local<v8::Object> instance = func->NewInstance();
785 env->Global()->Set(v8::String::New("instance"), instance); 792 env->Global()->Set(v8::String::New("instance"), instance);
786 793
787 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run(); 794 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run();
788 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 795 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
789 env->Global()->Get(v8::String::New("start"))); 796 env->Global()->Get(v8::String::New("start")));
790 797
791 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
792 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
793
794 cpu_profiler->StartCpuProfiling(profile_name);
795 int32_t repeat_count = 1; 798 int32_t repeat_count = 1;
796 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 799 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
797 function->Call(env->Global(), ARRAY_SIZE(args), args); 800 const v8::CpuProfile* profile =
798 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 801 RunProfiler(env, function, args, ARRAY_SIZE(args), 180);
799
800 CHECK_NE(NULL, profile);
801 // Dump collected profile to have a better diagnostic in case of failure.
802 reinterpret_cast<i::CpuProfile*>(
803 const_cast<v8::CpuProfile*>(profile))->Print();
804 802
805 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 803 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
806 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 804 const v8::CpuProfileNode* startNode = GetChild(root, "start");
807 GetChild(startNode, "get foo"); 805 GetChild(startNode, "get foo");
808 GetChild(startNode, "set foo"); 806 GetChild(startNode, "set foo");
809 807
808 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
810 cpu_profiler->DeleteAllCpuProfiles(); 809 cpu_profiler->DeleteAllCpuProfiles();
811 } 810 }
812 811
813 812
814 // Test that native accessors are properly reported in the CPU profile. 813 // Test that native accessors are properly reported in the CPU profile.
815 // This test makes sure that the accessors are called enough times to become 814 // This test makes sure that the accessors are called enough times to become
816 // hot and to trigger optimizations. 815 // hot and to trigger optimizations.
817 TEST(NativeAccessorMonomorphicIC) { 816 TEST(NativeAccessorMonomorphicIC) {
818 LocalContext env; 817 LocalContext env;
819 v8::HandleScope scope(env->GetIsolate()); 818 v8::HandleScope scope(env->GetIsolate());
(...skipping 19 matching lines...) Expand all
839 { 838 {
840 // Make sure accessors ICs are in monomorphic state before starting 839 // Make sure accessors ICs are in monomorphic state before starting
841 // profiling. 840 // profiling.
842 accessors.set_warming_up(true); 841 accessors.set_warming_up(true);
843 int32_t warm_up_iterations = 3; 842 int32_t warm_up_iterations = 3;
844 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; 843 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) };
845 function->Call(env->Global(), ARRAY_SIZE(args), args); 844 function->Call(env->Global(), ARRAY_SIZE(args), args);
846 accessors.set_warming_up(false); 845 accessors.set_warming_up(false);
847 } 846 }
848 847
849 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
850 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
851
852 cpu_profiler->StartCpuProfiling(profile_name);
853 int32_t repeat_count = 100; 848 int32_t repeat_count = 100;
854 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 849 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
855 function->Call(env->Global(), ARRAY_SIZE(args), args); 850 const v8::CpuProfile* profile =
856 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 851 RunProfiler(env, function, args, ARRAY_SIZE(args), 200);
857
858 CHECK_NE(NULL, profile);
859 // Dump collected profile to have a better diagnostic in case of failure.
860 reinterpret_cast<i::CpuProfile*>(
861 const_cast<v8::CpuProfile*>(profile))->Print();
862 852
863 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 853 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
864 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 854 const v8::CpuProfileNode* startNode = GetChild(root, "start");
865 GetChild(startNode, "get foo"); 855 GetChild(startNode, "get foo");
866 GetChild(startNode, "set foo"); 856 GetChild(startNode, "set foo");
867 857
858 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
868 cpu_profiler->DeleteAllCpuProfiles(); 859 cpu_profiler->DeleteAllCpuProfiles();
869 } 860 }
870 861
871 862
872 static const char* native_method_test_source = "function start(count) {\n" 863 static const char* native_method_test_source = "function start(count) {\n"
873 " for (var i = 0; i < count; i++) {\n" 864 " for (var i = 0; i < count; i++) {\n"
874 " instance.fooMethod();\n" 865 " instance.fooMethod();\n"
875 " }\n" 866 " }\n"
876 "}\n"; 867 "}\n";
877 868
(...skipping 14 matching lines...) Expand all
892 &TestApiCallbacks::Callback, data, signature, 0)); 883 &TestApiCallbacks::Callback, data, signature, 0));
893 884
894 v8::Local<v8::Function> func = func_template->GetFunction(); 885 v8::Local<v8::Function> func = func_template->GetFunction();
895 v8::Local<v8::Object> instance = func->NewInstance(); 886 v8::Local<v8::Object> instance = func->NewInstance();
896 env->Global()->Set(v8::String::New("instance"), instance); 887 env->Global()->Set(v8::String::New("instance"), instance);
897 888
898 v8::Script::Compile(v8::String::New(native_method_test_source))->Run(); 889 v8::Script::Compile(v8::String::New(native_method_test_source))->Run();
899 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 890 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
900 env->Global()->Get(v8::String::New("start"))); 891 env->Global()->Get(v8::String::New("start")));
901 892
902 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
903 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
904
905 cpu_profiler->StartCpuProfiling(profile_name);
906 int32_t repeat_count = 1; 893 int32_t repeat_count = 1;
907 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 894 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
908 function->Call(env->Global(), ARRAY_SIZE(args), args); 895 const v8::CpuProfile* profile =
909 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 896 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
910
911 CHECK_NE(NULL, profile);
912 // Dump collected profile to have a better diagnostic in case of failure.
913 reinterpret_cast<i::CpuProfile*>(
914 const_cast<v8::CpuProfile*>(profile))->Print();
915 897
916 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 898 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
917 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 899 const v8::CpuProfileNode* startNode = GetChild(root, "start");
918 GetChild(startNode, "fooMethod"); 900 GetChild(startNode, "fooMethod");
919 901
902 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
920 cpu_profiler->DeleteAllCpuProfiles(); 903 cpu_profiler->DeleteAllCpuProfiles();
921 } 904 }
922 905
923 906
924 TEST(NativeMethodMonomorphicIC) { 907 TEST(NativeMethodMonomorphicIC) {
925 LocalContext env; 908 LocalContext env;
926 v8::HandleScope scope(env->GetIsolate()); 909 v8::HandleScope scope(env->GetIsolate());
927 910
928 TestApiCallbacks callbacks(1); 911 TestApiCallbacks callbacks(1);
929 v8::Local<v8::External> data = v8::External::New(&callbacks); 912 v8::Local<v8::External> data = v8::External::New(&callbacks);
(...skipping 16 matching lines...) Expand all
946 { 929 {
947 // Make sure method ICs are in monomorphic state before starting 930 // Make sure method ICs are in monomorphic state before starting
948 // profiling. 931 // profiling.
949 callbacks.set_warming_up(true); 932 callbacks.set_warming_up(true);
950 int32_t warm_up_iterations = 3; 933 int32_t warm_up_iterations = 3;
951 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; 934 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) };
952 function->Call(env->Global(), ARRAY_SIZE(args), args); 935 function->Call(env->Global(), ARRAY_SIZE(args), args);
953 callbacks.set_warming_up(false); 936 callbacks.set_warming_up(false);
954 } 937 }
955 938
956 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
957 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
958
959 cpu_profiler->StartCpuProfiling(profile_name);
960 int32_t repeat_count = 100; 939 int32_t repeat_count = 100;
961 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; 940 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
962 function->Call(env->Global(), ARRAY_SIZE(args), args); 941 const v8::CpuProfile* profile =
963 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 942 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
964
965 CHECK_NE(NULL, profile);
966 // Dump collected profile to have a better diagnostic in case of failure.
967 reinterpret_cast<i::CpuProfile*>(
968 const_cast<v8::CpuProfile*>(profile))->Print();
969 943
970 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 944 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
971 GetChild(root, "start"); 945 GetChild(root, "start");
972 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 946 const v8::CpuProfileNode* startNode = GetChild(root, "start");
973 GetChild(startNode, "fooMethod"); 947 GetChild(startNode, "fooMethod");
974 948
949 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
975 cpu_profiler->DeleteAllCpuProfiles(); 950 cpu_profiler->DeleteAllCpuProfiles();
976 } 951 }
977 952
978 953
979 static const char* bound_function_test_source = "function foo(iterations) {\n" 954 static const char* bound_function_test_source = "function foo(iterations) {\n"
980 " var r = 0;\n" 955 " var r = 0;\n"
981 " for (var i = 0; i < iterations; i++) { r += i; }\n" 956 " for (var i = 0; i < iterations; i++) { r += i; }\n"
982 " return r;\n" 957 " return r;\n"
983 "}\n" 958 "}\n"
984 "function start(duration) {\n" 959 "function start(duration) {\n"
985 " var callback = foo.bind(this);\n" 960 " var callback = foo.bind(this);\n"
986 " var start = Date.now();\n" 961 " var start = Date.now();\n"
987 " while (Date.now() - start < duration) {\n" 962 " while (Date.now() - start < duration) {\n"
988 " callback(10 * 1000);\n" 963 " callback(10 * 1000);\n"
989 " }\n" 964 " }\n"
990 "}"; 965 "}";
991 966
992 967
993 TEST(BoundFunctionCall) { 968 TEST(BoundFunctionCall) {
994 LocalContext env; 969 LocalContext env;
995 v8::HandleScope scope(env->GetIsolate()); 970 v8::HandleScope scope(env->GetIsolate());
996 971
997 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); 972 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run();
998 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 973 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
999 env->Global()->Get(v8::String::New("start"))); 974 env->Global()->Get(v8::String::New("start")));
1000 975
1001 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1002 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
1003
1004 cpu_profiler->StartCpuProfiling(profile_name);
1005 int32_t duration_ms = 100; 976 int32_t duration_ms = 100;
1006 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; 977 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1007 function->Call(env->Global(), ARRAY_SIZE(args), args); 978 const v8::CpuProfile* profile =
1008 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 979 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
1009
1010 CHECK_NE(NULL, profile);
1011 // Dump collected profile to have a better diagnostic in case of failure.
1012 reinterpret_cast<i::CpuProfile*>(
1013 const_cast<v8::CpuProfile*>(profile))->Print();
1014 980
1015 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 981 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1016 ScopedVector<v8::Handle<v8::String> > names(3); 982 ScopedVector<v8::Handle<v8::String> > names(3);
1017 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 983 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1018 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 984 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1019 names[2] = v8::String::New("start"); 985 names[2] = v8::String::New("start");
1020 // Don't allow |foo| node to be at the top level. 986 // Don't allow |foo| node to be at the top level.
1021 CheckChildrenNames(root, names); 987 CheckChildrenNames(root, names);
1022 988
1023 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 989 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1024 GetChild(startNode, "foo"); 990 GetChild(startNode, "foo");
1025 991
992 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1026 cpu_profiler->DeleteAllCpuProfiles(); 993 cpu_profiler->DeleteAllCpuProfiles();
1027 } 994 }
1028 995
1029 996
1030 static const char* call_function_test_source = "function bar(iterations) {\n" 997 static const char* call_function_test_source = "function bar(iterations) {\n"
1031 "}\n" 998 "}\n"
1032 "function start(duration) {\n" 999 "function start(duration) {\n"
1033 " var start = Date.now();\n" 1000 " var start = Date.now();\n"
1034 " while (Date.now() - start < duration) {\n" 1001 " while (Date.now() - start < duration) {\n"
1035 " try {\n" 1002 " try {\n"
(...skipping 16 matching lines...) Expand all
1052 // 1 1 bar [-1] #7 1019 // 1 1 bar [-1] #7
1053 // 19 19 (program) [-1] #2 1020 // 19 19 (program) [-1] #2
1054 TEST(FunctionCallSample) { 1021 TEST(FunctionCallSample) {
1055 LocalContext env; 1022 LocalContext env;
1056 v8::HandleScope scope(env->GetIsolate()); 1023 v8::HandleScope scope(env->GetIsolate());
1057 1024
1058 v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); 1025 v8::Script::Compile(v8::String::New(call_function_test_source))->Run();
1059 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1026 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1060 env->Global()->Get(v8::String::New("start"))); 1027 env->Global()->Get(v8::String::New("start")));
1061 1028
1062 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1029 int32_t duration_ms = 100;
1063 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); 1030 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1064 1031
1065 cpu_profiler->StartCpuProfiling(profile_name); 1032 const v8::CpuProfile* profile =
1066 int32_t duration_ms = 100; 1033 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
1067 #if defined(_WIN32) || defined(_WIN64)
1068 // 100ms is not enough on Windows. See
1069 // https://code.google.com/p/v8/issues/detail?id=2628
1070 duration_ms = 400;
1071 #endif
1072 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1073 function->Call(env->Global(), ARRAY_SIZE(args), args);
1074 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
1075
1076 CHECK_NE(NULL, profile);
1077 // Dump collected profile to have a better diagnostic in case of failure.
1078 reinterpret_cast<i::CpuProfile*>(
1079 const_cast<v8::CpuProfile*>(profile))->Print();
1080 1034
1081 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1035 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1082 { 1036 {
1083 ScopedVector<v8::Handle<v8::String> > names(4); 1037 ScopedVector<v8::Handle<v8::String> > names(4);
1084 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 1038 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1085 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 1039 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1086 names[2] = v8::String::New("start"); 1040 names[2] = v8::String::New("start");
1087 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName); 1041 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName);
1088 // Don't allow |bar| and |call| nodes to be at the top level. 1042 // Don't allow |bar| and |call| nodes to be at the top level.
1089 CheckChildrenNames(root, names); 1043 CheckChildrenNames(root, names);
(...skipping 13 matching lines...) Expand all
1103 } 1057 }
1104 1058
1105 const v8::CpuProfileNode* unresolvedNode = 1059 const v8::CpuProfileNode* unresolvedNode =
1106 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); 1060 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName);
1107 if (unresolvedNode) { 1061 if (unresolvedNode) {
1108 ScopedVector<v8::Handle<v8::String> > names(1); 1062 ScopedVector<v8::Handle<v8::String> > names(1);
1109 names[0] = v8::String::New("call"); 1063 names[0] = v8::String::New("call");
1110 CheckChildrenNames(unresolvedNode, names); 1064 CheckChildrenNames(unresolvedNode, names);
1111 } 1065 }
1112 1066
1067 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1113 cpu_profiler->DeleteAllCpuProfiles(); 1068 cpu_profiler->DeleteAllCpuProfiles();
1114 } 1069 }
1115 1070
1116 1071
1117 static const char* function_apply_test_source = "function bar(iterations) {\n" 1072 static const char* function_apply_test_source = "function bar(iterations) {\n"
1118 "}\n" 1073 "}\n"
1119 "function test() {\n" 1074 "function test() {\n"
1120 " bar.apply(this, [10 * 1000]);\n" 1075 " bar.apply(this, [10 * 1000]);\n"
1121 "}\n" 1076 "}\n"
1122 "function start(duration) {\n" 1077 "function start(duration) {\n"
(...skipping 17 matching lines...) Expand all
1140 // 9 9 apply [-1] #0 5 1095 // 9 9 apply [-1] #0 5
1141 // 10 10 (program) [-1] #0 2 1096 // 10 10 (program) [-1] #0 2
1142 TEST(FunctionApplySample) { 1097 TEST(FunctionApplySample) {
1143 LocalContext env; 1098 LocalContext env;
1144 v8::HandleScope scope(env->GetIsolate()); 1099 v8::HandleScope scope(env->GetIsolate());
1145 1100
1146 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run(); 1101 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run();
1147 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1102 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1148 env->Global()->Get(v8::String::New("start"))); 1103 env->Global()->Get(v8::String::New("start")));
1149 1104
1150 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1151 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
1152
1153 cpu_profiler->StartCpuProfiling(profile_name);
1154 int32_t duration_ms = 100; 1105 int32_t duration_ms = 100;
1155 #if defined(_WIN32) || defined(_WIN64)
1156 // 100ms is not enough on Windows. See
1157 // https://code.google.com/p/v8/issues/detail?id=2628
1158 duration_ms = 400;
1159 #endif
1160 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; 1106 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1161 function->Call(env->Global(), ARRAY_SIZE(args), args); 1107 const v8::CpuProfile* profile =
1162 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 1108 RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
1163
1164 CHECK_NE(NULL, profile);
1165 // Dump collected profile to have a better diagnostic in case of failure.
1166 reinterpret_cast<i::CpuProfile*>(
1167 const_cast<v8::CpuProfile*>(profile))->Print();
1168 1109
1169 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1110 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1170 { 1111 {
1171 ScopedVector<v8::Handle<v8::String> > names(3); 1112 ScopedVector<v8::Handle<v8::String> > names(3);
1172 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 1113 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1173 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 1114 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1174 names[2] = v8::String::New("start"); 1115 names[2] = v8::String::New("start");
1175 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. 1116 // Don't allow |test|, |bar| and |apply| nodes to be at the top level.
1176 CheckChildrenNames(root, names); 1117 CheckChildrenNames(root, names);
1177 } 1118 }
(...skipping 17 matching lines...) Expand all
1195 1136
1196 if (const v8::CpuProfileNode* unresolvedNode = 1137 if (const v8::CpuProfileNode* unresolvedNode =
1197 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { 1138 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) {
1198 ScopedVector<v8::Handle<v8::String> > names(1); 1139 ScopedVector<v8::Handle<v8::String> > names(1);
1199 names[0] = v8::String::New("apply"); 1140 names[0] = v8::String::New("apply");
1200 CheckChildrenNames(unresolvedNode, names); 1141 CheckChildrenNames(unresolvedNode, names);
1201 GetChild(unresolvedNode, "apply"); 1142 GetChild(unresolvedNode, "apply");
1202 } 1143 }
1203 } 1144 }
1204 1145
1146 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1205 cpu_profiler->DeleteAllCpuProfiles(); 1147 cpu_profiler->DeleteAllCpuProfiles();
1206 } 1148 }
OLDNEW
« no previous file with comments | « src/sampler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698