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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 using i::SmartPointer; | 49 using i::SmartPointer; |
50 using i::Vector; | 50 using i::Vector; |
51 | 51 |
52 | 52 |
53 // Helper methods | 53 // Helper methods |
54 static v8::Local<v8::Function> GetFunction(v8::Context* env, const char* name) { | 54 static v8::Local<v8::Function> GetFunction(v8::Context* env, const char* name) { |
55 return v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str(name))); | 55 return v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str(name))); |
56 } | 56 } |
57 | 57 |
58 | 58 |
| 59 static const char* reason(const i::Deoptimizer::DeoptReason reason) { |
| 60 return i::Deoptimizer::GetDeoptReason(reason); |
| 61 } |
| 62 |
| 63 |
59 TEST(StartStop) { | 64 TEST(StartStop) { |
60 i::Isolate* isolate = CcTest::i_isolate(); | 65 i::Isolate* isolate = CcTest::i_isolate(); |
61 CpuProfilesCollection profiles(isolate->heap()); | 66 CpuProfilesCollection profiles(isolate->heap()); |
62 ProfileGenerator generator(&profiles); | 67 ProfileGenerator generator(&profiles); |
63 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 68 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
64 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); | 69 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
65 processor->Start(); | 70 processor->Start(); |
66 processor->StopSynchronously(); | 71 processor->StopSynchronously(); |
67 } | 72 } |
68 | 73 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 CHECK(ContainsString(name, names)); | 453 CHECK(ContainsString(name, names)); |
449 // Check that there are no duplicates. | 454 // Check that there are no duplicates. |
450 for (int j = 0; j < count; j++) { | 455 for (int j = 0; j < count; j++) { |
451 if (j == i) continue; | 456 if (j == i) continue; |
452 CHECK(!name->Equals(node->GetChild(j)->GetFunctionName())); | 457 CHECK(!name->Equals(node->GetChild(j)->GetFunctionName())); |
453 } | 458 } |
454 } | 459 } |
455 } | 460 } |
456 | 461 |
457 | 462 |
458 static const v8::CpuProfileNode* FindChild(v8::Isolate* isolate, | 463 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, |
459 const v8::CpuProfileNode* node, | |
460 const char* name) { | 464 const char* name) { |
461 int count = node->GetChildrenCount(); | 465 int count = node->GetChildrenCount(); |
462 v8::Handle<v8::String> nameHandle = v8_str(name); | 466 v8::Handle<v8::String> nameHandle = v8_str(name); |
463 for (int i = 0; i < count; i++) { | 467 for (int i = 0; i < count; i++) { |
464 const v8::CpuProfileNode* child = node->GetChild(i); | 468 const v8::CpuProfileNode* child = node->GetChild(i); |
465 if (nameHandle->Equals(child->GetFunctionName())) return child; | 469 if (nameHandle->Equals(child->GetFunctionName())) return child; |
466 } | 470 } |
467 return NULL; | 471 return NULL; |
468 } | 472 } |
469 | 473 |
470 | 474 |
471 static const v8::CpuProfileNode* GetChild(v8::Isolate* isolate, | 475 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node, |
472 const v8::CpuProfileNode* node, | |
473 const char* name) { | 476 const char* name) { |
474 const v8::CpuProfileNode* result = FindChild(isolate, node, name); | 477 const v8::CpuProfileNode* result = FindChild(node, name); |
475 if (!result) { | 478 if (!result) { |
476 char buffer[100]; | 479 char buffer[100]; |
477 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)), | 480 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)), |
478 "Failed to GetChild: %s", name); | 481 "Failed to GetChild: %s", name); |
479 FATAL(buffer); | 482 FATAL(buffer); |
480 } | 483 } |
481 return result; | 484 return result; |
482 } | 485 } |
483 | 486 |
484 | 487 |
485 static void CheckSimpleBranch(v8::Isolate* isolate, | 488 static void CheckSimpleBranch(const v8::CpuProfileNode* node, |
486 const v8::CpuProfileNode* node, | |
487 const char* names[], int length) { | 489 const char* names[], int length) { |
488 for (int i = 0; i < length; i++) { | 490 for (int i = 0; i < length; i++) { |
489 const char* name = names[i]; | 491 const char* name = names[i]; |
490 node = GetChild(isolate, node, name); | 492 node = GetChild(node, name); |
491 int expectedChildrenCount = (i == length - 1) ? 0 : 1; | 493 int expectedChildrenCount = (i == length - 1) ? 0 : 1; |
492 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); | 494 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); |
493 } | 495 } |
494 } | 496 } |
495 | 497 |
496 | 498 |
497 static const v8::CpuProfileNode* GetSimpleBranch(v8::Isolate* isolate, | 499 static const ProfileNode* GetSimpleBranch(v8::CpuProfile* profile, |
498 const v8::CpuProfileNode* node, | 500 const char* names[], int length) { |
499 const char* names[], | 501 const v8::CpuProfileNode* node = profile->GetTopDownRoot(); |
500 int length) { | |
501 for (int i = 0; i < length; i++) { | 502 for (int i = 0; i < length; i++) { |
502 node = GetChild(isolate, node, names[i]); | 503 node = GetChild(node, names[i]); |
503 } | 504 } |
504 return node; | 505 return reinterpret_cast<const ProfileNode*>(node); |
505 } | 506 } |
506 | 507 |
507 | 508 |
508 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" | 509 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" |
509 " this.mmm = 0;\n" | 510 " this.mmm = 0;\n" |
510 " var start = Date.now();\n" | 511 " var start = Date.now();\n" |
511 " while (Date.now() - start < timeout) {\n" | 512 " while (Date.now() - start < timeout) {\n" |
512 " var n = 100*1000;\n" | 513 " var n = 100*1000;\n" |
513 " while(n > 1) {\n" | 514 " while(n > 1) {\n" |
514 " n--;\n" | 515 " n--;\n" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 function->Call(env->Global(), arraysize(args), args); | 571 function->Call(env->Global(), arraysize(args), args); |
571 | 572 |
572 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 573 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
573 | 574 |
574 ScopedVector<v8::Handle<v8::String> > names(3); | 575 ScopedVector<v8::Handle<v8::String> > names(3); |
575 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 576 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
576 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 577 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
577 names[2] = v8_str("start"); | 578 names[2] = v8_str("start"); |
578 CheckChildrenNames(root, names); | 579 CheckChildrenNames(root, names); |
579 | 580 |
580 const v8::CpuProfileNode* startNode = | 581 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
581 GetChild(env->GetIsolate(), root, "start"); | |
582 CHECK_EQ(1, startNode->GetChildrenCount()); | 582 CHECK_EQ(1, startNode->GetChildrenCount()); |
583 | 583 |
584 const v8::CpuProfileNode* fooNode = | 584 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); |
585 GetChild(env->GetIsolate(), startNode, "foo"); | |
586 CHECK_EQ(3, fooNode->GetChildrenCount()); | 585 CHECK_EQ(3, fooNode->GetChildrenCount()); |
587 | 586 |
588 const char* barBranch[] = { "bar", "delay", "loop" }; | 587 const char* barBranch[] = { "bar", "delay", "loop" }; |
589 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, | 588 CheckSimpleBranch(fooNode, barBranch, arraysize(barBranch)); |
590 arraysize(barBranch)); | |
591 const char* bazBranch[] = { "baz", "delay", "loop" }; | 589 const char* bazBranch[] = { "baz", "delay", "loop" }; |
592 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, | 590 CheckSimpleBranch(fooNode, bazBranch, arraysize(bazBranch)); |
593 arraysize(bazBranch)); | |
594 const char* delayBranch[] = { "delay", "loop" }; | 591 const char* delayBranch[] = { "delay", "loop" }; |
595 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, | 592 CheckSimpleBranch(fooNode, delayBranch, arraysize(delayBranch)); |
596 arraysize(delayBranch)); | |
597 | 593 |
598 profile->Delete(); | 594 profile->Delete(); |
599 } | 595 } |
600 | 596 |
601 | 597 |
602 static const char* hot_deopt_no_frame_entry_test_source = | 598 static const char* hot_deopt_no_frame_entry_test_source = |
603 "function foo(a, b) {\n" | 599 "function foo(a, b) {\n" |
604 " try {\n" | 600 " try {\n" |
605 " return a + b;\n" | 601 " return a + b;\n" |
606 " } catch (e) { }\n" | 602 " } catch (e) { }\n" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 function->Call(env->Global(), arraysize(args), args); | 639 function->Call(env->Global(), arraysize(args), args); |
644 | 640 |
645 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 641 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
646 | 642 |
647 ScopedVector<v8::Handle<v8::String> > names(3); | 643 ScopedVector<v8::Handle<v8::String> > names(3); |
648 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 644 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
649 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 645 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
650 names[2] = v8_str("start"); | 646 names[2] = v8_str("start"); |
651 CheckChildrenNames(root, names); | 647 CheckChildrenNames(root, names); |
652 | 648 |
653 const v8::CpuProfileNode* startNode = | 649 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
654 GetChild(env->GetIsolate(), root, "start"); | |
655 CHECK_EQ(1, startNode->GetChildrenCount()); | 650 CHECK_EQ(1, startNode->GetChildrenCount()); |
656 | 651 |
657 GetChild(env->GetIsolate(), startNode, "foo"); | 652 GetChild(startNode, "foo"); |
658 | 653 |
659 profile->Delete(); | 654 profile->Delete(); |
660 } | 655 } |
661 | 656 |
662 | 657 |
663 TEST(CollectCpuProfileSamples) { | 658 TEST(CollectCpuProfileSamples) { |
664 LocalContext env; | 659 LocalContext env; |
665 v8::HandleScope scope(env->GetIsolate()); | 660 v8::HandleScope scope(env->GetIsolate()); |
666 | 661 |
667 CompileRun(cpu_profiler_test_source); | 662 CompileRun(cpu_profiler_test_source); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 RunProfiler(env.local(), function, args, arraysize(args), 100); | 724 RunProfiler(env.local(), function, args, arraysize(args), 100); |
730 | 725 |
731 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 726 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
732 | 727 |
733 ScopedVector<v8::Handle<v8::String> > names(3); | 728 ScopedVector<v8::Handle<v8::String> > names(3); |
734 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 729 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
735 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 730 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
736 names[2] = v8_str("start"); | 731 names[2] = v8_str("start"); |
737 CheckChildrenNames(root, names); | 732 CheckChildrenNames(root, names); |
738 | 733 |
739 const v8::CpuProfileNode* startNode = | 734 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
740 FindChild(env->GetIsolate(), root, "start"); | |
741 // On slow machines there may be no meaningfull samples at all, skip the | 735 // On slow machines there may be no meaningfull samples at all, skip the |
742 // check there. | 736 // check there. |
743 if (startNode && startNode->GetChildrenCount() > 0) { | 737 if (startNode && startNode->GetChildrenCount() > 0) { |
744 CHECK_EQ(1, startNode->GetChildrenCount()); | 738 CHECK_EQ(1, startNode->GetChildrenCount()); |
745 const v8::CpuProfileNode* delayNode = | 739 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); |
746 GetChild(env->GetIsolate(), startNode, "delay"); | |
747 if (delayNode->GetChildrenCount() > 0) { | 740 if (delayNode->GetChildrenCount() > 0) { |
748 CHECK_EQ(1, delayNode->GetChildrenCount()); | 741 CHECK_EQ(1, delayNode->GetChildrenCount()); |
749 GetChild(env->GetIsolate(), delayNode, "loop"); | 742 GetChild(delayNode, "loop"); |
750 } | 743 } |
751 } | 744 } |
752 | 745 |
753 profile->Delete(); | 746 profile->Delete(); |
754 } | 747 } |
755 | 748 |
756 | 749 |
757 static const char* native_accessor_test_source = "function start(count) {\n" | 750 static const char* native_accessor_test_source = "function start(count) {\n" |
758 " for (var i = 0; i < count; i++) {\n" | 751 " for (var i = 0; i < count; i++) {\n" |
759 " var o = instance.foo;\n" | 752 " var o = instance.foo;\n" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 | 828 |
836 CompileRun(native_accessor_test_source); | 829 CompileRun(native_accessor_test_source); |
837 v8::Local<v8::Function> function = GetFunction(*env, "start"); | 830 v8::Local<v8::Function> function = GetFunction(*env, "start"); |
838 | 831 |
839 int32_t repeat_count = 1; | 832 int32_t repeat_count = 1; |
840 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 833 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
841 v8::CpuProfile* profile = | 834 v8::CpuProfile* profile = |
842 RunProfiler(env.local(), function, args, arraysize(args), 180); | 835 RunProfiler(env.local(), function, args, arraysize(args), 180); |
843 | 836 |
844 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 837 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
845 const v8::CpuProfileNode* startNode = | 838 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
846 GetChild(isolate, root, "start"); | 839 GetChild(startNode, "get foo"); |
847 GetChild(isolate, startNode, "get foo"); | 840 GetChild(startNode, "set foo"); |
848 GetChild(isolate, startNode, "set foo"); | |
849 | 841 |
850 profile->Delete(); | 842 profile->Delete(); |
851 } | 843 } |
852 | 844 |
853 | 845 |
854 // Test that native accessors are properly reported in the CPU profile. | 846 // Test that native accessors are properly reported in the CPU profile. |
855 // This test makes sure that the accessors are called enough times to become | 847 // This test makes sure that the accessors are called enough times to become |
856 // hot and to trigger optimizations. | 848 // hot and to trigger optimizations. |
857 TEST(NativeAccessorMonomorphicIC) { | 849 TEST(NativeAccessorMonomorphicIC) { |
858 LocalContext env; | 850 LocalContext env; |
(...skipping 28 matching lines...) Expand all Loading... |
887 function->Call(env->Global(), arraysize(args), args); | 879 function->Call(env->Global(), arraysize(args), args); |
888 accessors.set_warming_up(false); | 880 accessors.set_warming_up(false); |
889 } | 881 } |
890 | 882 |
891 int32_t repeat_count = 100; | 883 int32_t repeat_count = 100; |
892 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 884 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
893 v8::CpuProfile* profile = | 885 v8::CpuProfile* profile = |
894 RunProfiler(env.local(), function, args, arraysize(args), 200); | 886 RunProfiler(env.local(), function, args, arraysize(args), 200); |
895 | 887 |
896 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 888 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
897 const v8::CpuProfileNode* startNode = | 889 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
898 GetChild(isolate, root, "start"); | 890 GetChild(startNode, "get foo"); |
899 GetChild(isolate, startNode, "get foo"); | 891 GetChild(startNode, "set foo"); |
900 GetChild(isolate, startNode, "set foo"); | |
901 | 892 |
902 profile->Delete(); | 893 profile->Delete(); |
903 } | 894 } |
904 | 895 |
905 | 896 |
906 static const char* native_method_test_source = "function start(count) {\n" | 897 static const char* native_method_test_source = "function start(count) {\n" |
907 " for (var i = 0; i < count; i++) {\n" | 898 " for (var i = 0; i < count; i++) {\n" |
908 " instance.fooMethod();\n" | 899 " instance.fooMethod();\n" |
909 " }\n" | 900 " }\n" |
910 "}\n"; | 901 "}\n"; |
(...skipping 26 matching lines...) Expand all Loading... |
937 | 928 |
938 CompileRun(native_method_test_source); | 929 CompileRun(native_method_test_source); |
939 v8::Local<v8::Function> function = GetFunction(*env, "start"); | 930 v8::Local<v8::Function> function = GetFunction(*env, "start"); |
940 | 931 |
941 int32_t repeat_count = 1; | 932 int32_t repeat_count = 1; |
942 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 933 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
943 v8::CpuProfile* profile = | 934 v8::CpuProfile* profile = |
944 RunProfiler(env.local(), function, args, arraysize(args), 100); | 935 RunProfiler(env.local(), function, args, arraysize(args), 100); |
945 | 936 |
946 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 937 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
947 const v8::CpuProfileNode* startNode = | 938 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
948 GetChild(isolate, root, "start"); | 939 GetChild(startNode, "fooMethod"); |
949 GetChild(isolate, startNode, "fooMethod"); | |
950 | 940 |
951 profile->Delete(); | 941 profile->Delete(); |
952 } | 942 } |
953 | 943 |
954 | 944 |
955 TEST(NativeMethodMonomorphicIC) { | 945 TEST(NativeMethodMonomorphicIC) { |
956 LocalContext env; | 946 LocalContext env; |
957 v8::Isolate* isolate = env->GetIsolate(); | 947 v8::Isolate* isolate = env->GetIsolate(); |
958 v8::HandleScope scope(isolate); | 948 v8::HandleScope scope(isolate); |
959 | 949 |
(...skipping 30 matching lines...) Expand all Loading... |
990 function->Call(env->Global(), arraysize(args), args); | 980 function->Call(env->Global(), arraysize(args), args); |
991 callbacks.set_warming_up(false); | 981 callbacks.set_warming_up(false); |
992 } | 982 } |
993 | 983 |
994 int32_t repeat_count = 100; | 984 int32_t repeat_count = 100; |
995 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 985 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
996 v8::CpuProfile* profile = | 986 v8::CpuProfile* profile = |
997 RunProfiler(env.local(), function, args, arraysize(args), 100); | 987 RunProfiler(env.local(), function, args, arraysize(args), 100); |
998 | 988 |
999 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 989 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1000 GetChild(isolate, root, "start"); | 990 GetChild(root, "start"); |
1001 const v8::CpuProfileNode* startNode = | 991 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1002 GetChild(isolate, root, "start"); | 992 GetChild(startNode, "fooMethod"); |
1003 GetChild(isolate, startNode, "fooMethod"); | |
1004 | 993 |
1005 profile->Delete(); | 994 profile->Delete(); |
1006 } | 995 } |
1007 | 996 |
1008 | 997 |
1009 static const char* bound_function_test_source = | 998 static const char* bound_function_test_source = |
1010 "function foo() {\n" | 999 "function foo() {\n" |
1011 " startProfiling('my_profile');\n" | 1000 " startProfiling('my_profile');\n" |
1012 "}\n" | 1001 "}\n" |
1013 "function start() {\n" | 1002 "function start() {\n" |
(...skipping 13 matching lines...) Expand all Loading... |
1027 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); | 1016 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); |
1028 | 1017 |
1029 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1018 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1030 ScopedVector<v8::Handle<v8::String> > names(3); | 1019 ScopedVector<v8::Handle<v8::String> > names(3); |
1031 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1020 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1032 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1021 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1033 names[2] = v8_str("start"); | 1022 names[2] = v8_str("start"); |
1034 // Don't allow |foo| node to be at the top level. | 1023 // Don't allow |foo| node to be at the top level. |
1035 CheckChildrenNames(root, names); | 1024 CheckChildrenNames(root, names); |
1036 | 1025 |
1037 const v8::CpuProfileNode* startNode = | 1026 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1038 GetChild(env->GetIsolate(), root, "start"); | 1027 GetChild(startNode, "foo"); |
1039 GetChild(env->GetIsolate(), startNode, "foo"); | |
1040 | 1028 |
1041 profile->Delete(); | 1029 profile->Delete(); |
1042 } | 1030 } |
1043 | 1031 |
1044 | 1032 |
1045 // This tests checks distribution of the samples through the source lines. | 1033 // This tests checks distribution of the samples through the source lines. |
1046 TEST(TickLines) { | 1034 TEST(TickLines) { |
1047 CcTest::InitializeVM(); | 1035 CcTest::InitializeVM(); |
1048 LocalContext env; | 1036 LocalContext env; |
1049 i::FLAG_turbo_source_positions = true; | 1037 i::FLAG_turbo_source_positions = true; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 names[2] = v8_str("start"); | 1178 names[2] = v8_str("start"); |
1191 names[3] = v8_str(i::ProfileGenerator::kUnresolvedFunctionName); | 1179 names[3] = v8_str(i::ProfileGenerator::kUnresolvedFunctionName); |
1192 // Don't allow |bar| and |call| nodes to be at the top level. | 1180 // Don't allow |bar| and |call| nodes to be at the top level. |
1193 CheckChildrenNames(root, names); | 1181 CheckChildrenNames(root, names); |
1194 } | 1182 } |
1195 | 1183 |
1196 // In case of GC stress tests all samples may be in GC phase and there | 1184 // In case of GC stress tests all samples may be in GC phase and there |
1197 // won't be |start| node in the profiles. | 1185 // won't be |start| node in the profiles. |
1198 bool is_gc_stress_testing = | 1186 bool is_gc_stress_testing = |
1199 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction; | 1187 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction; |
1200 const v8::CpuProfileNode* startNode = | 1188 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
1201 FindChild(env->GetIsolate(), root, "start"); | |
1202 CHECK(is_gc_stress_testing || startNode); | 1189 CHECK(is_gc_stress_testing || startNode); |
1203 if (startNode) { | 1190 if (startNode) { |
1204 ScopedVector<v8::Handle<v8::String> > names(2); | 1191 ScopedVector<v8::Handle<v8::String> > names(2); |
1205 names[0] = v8_str("bar"); | 1192 names[0] = v8_str("bar"); |
1206 names[1] = v8_str("call"); | 1193 names[1] = v8_str("call"); |
1207 CheckChildrenNames(startNode, names); | 1194 CheckChildrenNames(startNode, names); |
1208 } | 1195 } |
1209 | 1196 |
1210 const v8::CpuProfileNode* unresolvedNode = FindChild( | 1197 const v8::CpuProfileNode* unresolvedNode = |
1211 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); | 1198 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); |
1212 if (unresolvedNode) { | 1199 if (unresolvedNode) { |
1213 ScopedVector<v8::Handle<v8::String> > names(1); | 1200 ScopedVector<v8::Handle<v8::String> > names(1); |
1214 names[0] = v8_str("call"); | 1201 names[0] = v8_str("call"); |
1215 CheckChildrenNames(unresolvedNode, names); | 1202 CheckChildrenNames(unresolvedNode, names); |
1216 } | 1203 } |
1217 | 1204 |
1218 profile->Delete(); | 1205 profile->Delete(); |
1219 } | 1206 } |
1220 | 1207 |
1221 | 1208 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1250 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1264 { | 1251 { |
1265 ScopedVector<v8::Handle<v8::String> > names(3); | 1252 ScopedVector<v8::Handle<v8::String> > names(3); |
1266 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1253 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1267 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1254 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1268 names[2] = v8_str("start"); | 1255 names[2] = v8_str("start"); |
1269 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. | 1256 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. |
1270 CheckChildrenNames(root, names); | 1257 CheckChildrenNames(root, names); |
1271 } | 1258 } |
1272 | 1259 |
1273 const v8::CpuProfileNode* startNode = | 1260 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
1274 FindChild(env->GetIsolate(), root, "start"); | |
1275 if (startNode) { | 1261 if (startNode) { |
1276 { | 1262 { |
1277 ScopedVector<v8::Handle<v8::String> > names(2); | 1263 ScopedVector<v8::Handle<v8::String> > names(2); |
1278 names[0] = v8_str("test"); | 1264 names[0] = v8_str("test"); |
1279 names[1] = v8_str(ProfileGenerator::kUnresolvedFunctionName); | 1265 names[1] = v8_str(ProfileGenerator::kUnresolvedFunctionName); |
1280 CheckChildrenNames(startNode, names); | 1266 CheckChildrenNames(startNode, names); |
1281 } | 1267 } |
1282 | 1268 |
1283 const v8::CpuProfileNode* testNode = | 1269 const v8::CpuProfileNode* testNode = FindChild(startNode, "test"); |
1284 FindChild(env->GetIsolate(), startNode, "test"); | |
1285 if (testNode) { | 1270 if (testNode) { |
1286 ScopedVector<v8::Handle<v8::String> > names(3); | 1271 ScopedVector<v8::Handle<v8::String> > names(3); |
1287 names[0] = v8_str("bar"); | 1272 names[0] = v8_str("bar"); |
1288 names[1] = v8_str("apply"); | 1273 names[1] = v8_str("apply"); |
1289 // apply calls "get length" before invoking the function itself | 1274 // apply calls "get length" before invoking the function itself |
1290 // and we may get hit into it. | 1275 // and we may get hit into it. |
1291 names[2] = v8_str("get length"); | 1276 names[2] = v8_str("get length"); |
1292 CheckChildrenNames(testNode, names); | 1277 CheckChildrenNames(testNode, names); |
1293 } | 1278 } |
1294 | 1279 |
1295 if (const v8::CpuProfileNode* unresolvedNode = | 1280 if (const v8::CpuProfileNode* unresolvedNode = |
1296 FindChild(env->GetIsolate(), startNode, | 1281 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { |
1297 ProfileGenerator::kUnresolvedFunctionName)) { | |
1298 ScopedVector<v8::Handle<v8::String> > names(1); | 1282 ScopedVector<v8::Handle<v8::String> > names(1); |
1299 names[0] = v8_str("apply"); | 1283 names[0] = v8_str("apply"); |
1300 CheckChildrenNames(unresolvedNode, names); | 1284 CheckChildrenNames(unresolvedNode, names); |
1301 GetChild(env->GetIsolate(), unresolvedNode, "apply"); | 1285 GetChild(unresolvedNode, "apply"); |
1302 } | 1286 } |
1303 } | 1287 } |
1304 | 1288 |
1305 profile->Delete(); | 1289 profile->Delete(); |
1306 } | 1290 } |
1307 | 1291 |
1308 | 1292 |
1309 static const char* cpu_profiler_deep_stack_test_source = | 1293 static const char* cpu_profiler_deep_stack_test_source = |
1310 "function foo(n) {\n" | 1294 "function foo(n) {\n" |
1311 " if (n)\n" | 1295 " if (n)\n" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 | 1331 |
1348 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1332 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1349 { | 1333 { |
1350 ScopedVector<v8::Handle<v8::String> > names(3); | 1334 ScopedVector<v8::Handle<v8::String> > names(3); |
1351 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1335 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1352 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1336 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1353 names[2] = v8_str("start"); | 1337 names[2] = v8_str("start"); |
1354 CheckChildrenNames(root, names); | 1338 CheckChildrenNames(root, names); |
1355 } | 1339 } |
1356 | 1340 |
1357 const v8::CpuProfileNode* node = | 1341 const v8::CpuProfileNode* node = GetChild(root, "start"); |
1358 GetChild(env->GetIsolate(), root, "start"); | |
1359 for (int i = 0; i < 250; ++i) { | 1342 for (int i = 0; i < 250; ++i) { |
1360 node = GetChild(env->GetIsolate(), node, "foo"); | 1343 node = GetChild(node, "foo"); |
1361 } | 1344 } |
1362 // TODO(alph): | 1345 // TODO(alph): |
1363 // In theory there must be one more 'foo' and a 'startProfiling' nodes, | 1346 // In theory there must be one more 'foo' and a 'startProfiling' nodes, |
1364 // but due to unstable top frame extraction these might be missing. | 1347 // but due to unstable top frame extraction these might be missing. |
1365 | 1348 |
1366 profile->Delete(); | 1349 profile->Delete(); |
1367 } | 1350 } |
1368 | 1351 |
1369 | 1352 |
1370 static const char* js_native_js_test_source = | 1353 static const char* js_native_js_test_source = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1395 |
1413 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1396 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1414 { | 1397 { |
1415 ScopedVector<v8::Handle<v8::String> > names(3); | 1398 ScopedVector<v8::Handle<v8::String> > names(3); |
1416 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1399 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1417 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1400 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1418 names[2] = v8_str("start"); | 1401 names[2] = v8_str("start"); |
1419 CheckChildrenNames(root, names); | 1402 CheckChildrenNames(root, names); |
1420 } | 1403 } |
1421 | 1404 |
1422 const v8::CpuProfileNode* startNode = | 1405 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1423 GetChild(env->GetIsolate(), root, "start"); | |
1424 CHECK_EQ(1, startNode->GetChildrenCount()); | 1406 CHECK_EQ(1, startNode->GetChildrenCount()); |
1425 const v8::CpuProfileNode* nativeFunctionNode = | 1407 const v8::CpuProfileNode* nativeFunctionNode = |
1426 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1408 GetChild(startNode, "CallJsFunction"); |
1427 | 1409 |
1428 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1410 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
1429 const v8::CpuProfileNode* barNode = | 1411 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); |
1430 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | |
1431 | 1412 |
1432 CHECK_EQ(1, barNode->GetChildrenCount()); | 1413 CHECK_EQ(1, barNode->GetChildrenCount()); |
1433 GetChild(env->GetIsolate(), barNode, "foo"); | 1414 GetChild(barNode, "foo"); |
1434 | 1415 |
1435 profile->Delete(); | 1416 profile->Delete(); |
1436 } | 1417 } |
1437 | 1418 |
1438 | 1419 |
1439 static const char* js_native_js_runtime_js_test_source = | 1420 static const char* js_native_js_runtime_js_test_source = |
1440 "function foo() {\n" | 1421 "function foo() {\n" |
1441 " startProfiling('my_profile');\n" | 1422 " startProfiling('my_profile');\n" |
1442 "}\n" | 1423 "}\n" |
1443 "var bound = foo.bind(this);\n" | 1424 "var bound = foo.bind(this);\n" |
(...skipping 30 matching lines...) Expand all Loading... |
1474 | 1455 |
1475 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); | 1456 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); |
1476 | 1457 |
1477 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1458 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1478 ScopedVector<v8::Handle<v8::String> > names(3); | 1459 ScopedVector<v8::Handle<v8::String> > names(3); |
1479 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1460 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1480 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1461 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1481 names[2] = v8_str("start"); | 1462 names[2] = v8_str("start"); |
1482 CheckChildrenNames(root, names); | 1463 CheckChildrenNames(root, names); |
1483 | 1464 |
1484 const v8::CpuProfileNode* startNode = | 1465 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1485 GetChild(env->GetIsolate(), root, "start"); | |
1486 CHECK_EQ(1, startNode->GetChildrenCount()); | 1466 CHECK_EQ(1, startNode->GetChildrenCount()); |
1487 const v8::CpuProfileNode* nativeFunctionNode = | 1467 const v8::CpuProfileNode* nativeFunctionNode = |
1488 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1468 GetChild(startNode, "CallJsFunction"); |
1489 | 1469 |
1490 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1470 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
1491 const v8::CpuProfileNode* barNode = | 1471 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); |
1492 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | |
1493 | 1472 |
1494 // The child is in fact a bound foo. | 1473 // The child is in fact a bound foo. |
1495 // A bound function has a wrapper that may make calls to | 1474 // A bound function has a wrapper that may make calls to |
1496 // other functions e.g. "get length". | 1475 // other functions e.g. "get length". |
1497 CHECK_LE(1, barNode->GetChildrenCount()); | 1476 CHECK_LE(1, barNode->GetChildrenCount()); |
1498 CHECK_GE(2, barNode->GetChildrenCount()); | 1477 CHECK_GE(2, barNode->GetChildrenCount()); |
1499 GetChild(env->GetIsolate(), barNode, "foo"); | 1478 GetChild(barNode, "foo"); |
1500 | 1479 |
1501 profile->Delete(); | 1480 profile->Delete(); |
1502 } | 1481 } |
1503 | 1482 |
1504 | 1483 |
1505 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1484 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
1506 v8::base::OS::Print("In CallJsFunction2\n"); | 1485 v8::base::OS::Print("In CallJsFunction2\n"); |
1507 CallJsFunction(info); | 1486 CallJsFunction(info); |
1508 } | 1487 } |
1509 | 1488 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 | 1532 |
1554 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); | 1533 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); |
1555 | 1534 |
1556 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1535 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1557 ScopedVector<v8::Handle<v8::String> > names(3); | 1536 ScopedVector<v8::Handle<v8::String> > names(3); |
1558 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1537 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1559 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1538 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1560 names[2] = v8_str("start"); | 1539 names[2] = v8_str("start"); |
1561 CheckChildrenNames(root, names); | 1540 CheckChildrenNames(root, names); |
1562 | 1541 |
1563 const v8::CpuProfileNode* startNode = | 1542 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1564 GetChild(env->GetIsolate(), root, "start"); | |
1565 CHECK_EQ(1, startNode->GetChildrenCount()); | 1543 CHECK_EQ(1, startNode->GetChildrenCount()); |
1566 const v8::CpuProfileNode* nativeNode1 = | 1544 const v8::CpuProfileNode* nativeNode1 = |
1567 GetChild(env->GetIsolate(), startNode, "CallJsFunction1"); | 1545 GetChild(startNode, "CallJsFunction1"); |
1568 | 1546 |
1569 CHECK_EQ(1, nativeNode1->GetChildrenCount()); | 1547 CHECK_EQ(1, nativeNode1->GetChildrenCount()); |
1570 const v8::CpuProfileNode* barNode = | 1548 const v8::CpuProfileNode* barNode = GetChild(nativeNode1, "bar"); |
1571 GetChild(env->GetIsolate(), nativeNode1, "bar"); | |
1572 | 1549 |
1573 CHECK_EQ(1, barNode->GetChildrenCount()); | 1550 CHECK_EQ(1, barNode->GetChildrenCount()); |
1574 const v8::CpuProfileNode* nativeNode2 = | 1551 const v8::CpuProfileNode* nativeNode2 = GetChild(barNode, "CallJsFunction2"); |
1575 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); | |
1576 | 1552 |
1577 CHECK_EQ(1, nativeNode2->GetChildrenCount()); | 1553 CHECK_EQ(1, nativeNode2->GetChildrenCount()); |
1578 GetChild(env->GetIsolate(), nativeNode2, "foo"); | 1554 GetChild(nativeNode2, "foo"); |
1579 | 1555 |
1580 profile->Delete(); | 1556 profile->Delete(); |
1581 } | 1557 } |
1582 | 1558 |
1583 | 1559 |
1584 // [Top down]: | 1560 // [Top down]: |
1585 // 6 0 (root) #0 1 | 1561 // 6 0 (root) #0 1 |
1586 // 3 3 (program) #0 2 | 1562 // 3 3 (program) #0 2 |
1587 // 3 3 (idle) #0 3 | 1563 // 3 3 (idle) #0 3 |
1588 TEST(IdleTime) { | 1564 TEST(IdleTime) { |
(...skipping 24 matching lines...) Expand all Loading... |
1613 reinterpret_cast<i::CpuProfile*>(profile)->Print(); | 1589 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
1614 | 1590 |
1615 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1591 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1616 ScopedVector<v8::Handle<v8::String> > names(3); | 1592 ScopedVector<v8::Handle<v8::String> > names(3); |
1617 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1593 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1618 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1594 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1619 names[2] = v8_str(ProfileGenerator::kIdleEntryName); | 1595 names[2] = v8_str(ProfileGenerator::kIdleEntryName); |
1620 CheckChildrenNames(root, names); | 1596 CheckChildrenNames(root, names); |
1621 | 1597 |
1622 const v8::CpuProfileNode* programNode = | 1598 const v8::CpuProfileNode* programNode = |
1623 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); | 1599 GetChild(root, ProfileGenerator::kProgramEntryName); |
1624 CHECK_EQ(0, programNode->GetChildrenCount()); | 1600 CHECK_EQ(0, programNode->GetChildrenCount()); |
1625 CHECK_GE(programNode->GetHitCount(), 3u); | 1601 CHECK_GE(programNode->GetHitCount(), 3u); |
1626 | 1602 |
1627 const v8::CpuProfileNode* idleNode = | 1603 const v8::CpuProfileNode* idleNode = |
1628 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); | 1604 GetChild(root, ProfileGenerator::kIdleEntryName); |
1629 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1605 CHECK_EQ(0, idleNode->GetChildrenCount()); |
1630 CHECK_GE(idleNode->GetHitCount(), 3u); | 1606 CHECK_GE(idleNode->GetHitCount(), 3u); |
1631 | 1607 |
1632 profile->Delete(); | 1608 profile->Delete(); |
1633 } | 1609 } |
1634 | 1610 |
1635 | 1611 |
1636 static void CheckFunctionDetails(v8::Isolate* isolate, | 1612 static void CheckFunctionDetails(v8::Isolate* isolate, |
1637 const v8::CpuProfileNode* node, | 1613 const v8::CpuProfileNode* node, |
1638 const char* name, const char* script_name, | 1614 const char* name, const char* script_name, |
(...skipping 26 matching lines...) Expand all Loading... |
1665 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); | 1641 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
1666 reinterpret_cast<ProfileNode*>( | 1642 reinterpret_cast<ProfileNode*>( |
1667 const_cast<v8::CpuProfileNode*>(current))->Print(0); | 1643 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
1668 // The tree should look like this: | 1644 // The tree should look like this: |
1669 // 0 (root) 0 #1 | 1645 // 0 (root) 0 #1 |
1670 // 0 "" 19 #2 no reason script_b:1 | 1646 // 0 "" 19 #2 no reason script_b:1 |
1671 // 0 baz 19 #3 TryCatchStatement script_b:3 | 1647 // 0 baz 19 #3 TryCatchStatement script_b:3 |
1672 // 0 foo 18 #4 TryCatchStatement script_a:2 | 1648 // 0 foo 18 #4 TryCatchStatement script_a:2 |
1673 // 1 bar 18 #5 no reason script_a:3 | 1649 // 1 bar 18 #5 no reason script_a:3 |
1674 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1650 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1675 const v8::CpuProfileNode* script = GetChild(env->GetIsolate(), root, ""); | 1651 const v8::CpuProfileNode* script = GetChild(root, ""); |
1676 CheckFunctionDetails(env->GetIsolate(), script, "", "script_b", | 1652 CheckFunctionDetails(env->GetIsolate(), script, "", "script_b", |
1677 script_b->GetUnboundScript()->GetId(), 1, 1); | 1653 script_b->GetUnboundScript()->GetId(), 1, 1); |
1678 const v8::CpuProfileNode* baz = GetChild(env->GetIsolate(), script, "baz"); | 1654 const v8::CpuProfileNode* baz = GetChild(script, "baz"); |
1679 CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b", | 1655 CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b", |
1680 script_b->GetUnboundScript()->GetId(), 3, 16); | 1656 script_b->GetUnboundScript()->GetId(), 3, 16); |
1681 const v8::CpuProfileNode* foo = GetChild(env->GetIsolate(), baz, "foo"); | 1657 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); |
1682 CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a", | 1658 CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a", |
1683 script_a->GetUnboundScript()->GetId(), 2, 1); | 1659 script_a->GetUnboundScript()->GetId(), 2, 1); |
1684 const v8::CpuProfileNode* bar = GetChild(env->GetIsolate(), foo, "bar"); | 1660 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); |
1685 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a", | 1661 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a", |
1686 script_a->GetUnboundScript()->GetId(), 3, 14); | 1662 script_a->GetUnboundScript()->GetId(), 3, 14); |
1687 } | 1663 } |
1688 | 1664 |
1689 | 1665 |
1690 TEST(DontStopOnFinishedProfileDelete) { | 1666 TEST(DontStopOnFinishedProfileDelete) { |
1691 v8::HandleScope scope(CcTest::isolate()); | 1667 v8::HandleScope scope(CcTest::isolate()); |
1692 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 1668 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
1693 v8::Context::Scope context_scope(env); | 1669 v8::Context::Scope context_scope(env); |
1694 | 1670 |
(...skipping 18 matching lines...) Expand all Loading... |
1713 | 1689 |
1714 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1690 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
1715 CHECK(outer_profile); | 1691 CHECK(outer_profile); |
1716 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1692 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1717 outer_profile->Delete(); | 1693 outer_profile->Delete(); |
1718 outer_profile = NULL; | 1694 outer_profile = NULL; |
1719 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1695 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1720 } | 1696 } |
1721 | 1697 |
1722 | 1698 |
1723 static const char* collect_deopt_events_test_source = | 1699 // deopt at top function |
1724 "function opt_function(left, right, depth) {\n" | |
1725 " if (depth) return opt_function(left, right, depth - 1);\n" | |
1726 "\n" | |
1727 " var k = left / 10;\n" | |
1728 " var r = 10 / right;\n" | |
1729 " return k + r;" | |
1730 "}\n" | |
1731 "\n" | |
1732 "function test(left, right) {\n" | |
1733 " return opt_function(left, right, 1);\n" | |
1734 "}\n" | |
1735 "\n" | |
1736 "startProfiling();\n" | |
1737 "\n" | |
1738 "test(10, 10);\n" | |
1739 "\n" | |
1740 "%OptimizeFunctionOnNextCall(opt_function)\n" | |
1741 "\n" | |
1742 "test(10, 10);\n" | |
1743 "\n" | |
1744 "test(undefined, 10);\n" | |
1745 "\n" | |
1746 "%OptimizeFunctionOnNextCall(opt_function)\n" | |
1747 "\n" | |
1748 "test(10, 10);\n" | |
1749 "\n" | |
1750 "test(10, 0);\n" | |
1751 "\n" | |
1752 "stopProfiling();\n" | |
1753 "\n"; | |
1754 | |
1755 | |
1756 TEST(CollectDeoptEvents) { | 1700 TEST(CollectDeoptEvents) { |
1757 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 1701 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
1758 i::FLAG_allow_natives_syntax = true; | 1702 i::FLAG_allow_natives_syntax = true; |
1759 v8::HandleScope scope(CcTest::isolate()); | 1703 v8::HandleScope scope(CcTest::isolate()); |
1760 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 1704 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
1761 v8::Context::Scope context_scope(env); | 1705 v8::Context::Scope context_scope(env); |
1762 v8::Isolate* isolate = env->GetIsolate(); | 1706 v8::Isolate* isolate = env->GetIsolate(); |
1763 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); | 1707 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); |
1764 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); | 1708 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
1765 | 1709 |
1766 v8::Script::Compile(v8_str(collect_deopt_events_test_source))->Run(); | 1710 const char* source = |
| 1711 "function opt_function(left, right, depth) {\n" |
| 1712 " if (depth) return opt_function(left, right, depth - 1);\n" |
| 1713 "\n" |
| 1714 " var k = left / 10;\n" |
| 1715 " var r = 10 / right;\n" |
| 1716 " return k + r;" |
| 1717 "}\n" |
| 1718 "\n" |
| 1719 "function test(left, right) {\n" |
| 1720 " return opt_function(left, right, 1);\n" |
| 1721 "}\n" |
| 1722 "\n" |
| 1723 "startProfiling();\n" |
| 1724 "\n" |
| 1725 "test(10, 10);\n" |
| 1726 "\n" |
| 1727 "%OptimizeFunctionOnNextCall(opt_function)\n" |
| 1728 "\n" |
| 1729 "test(10, 10);\n" |
| 1730 "\n" |
| 1731 "test(undefined, 10);\n" |
| 1732 "\n" |
| 1733 "%OptimizeFunctionOnNextCall(opt_function)\n" |
| 1734 "\n" |
| 1735 "test(10, 10);\n" |
| 1736 "\n" |
| 1737 "test(10, 0);\n" |
| 1738 "\n" |
| 1739 "stopProfiling();\n" |
| 1740 "\n"; |
| 1741 |
| 1742 v8::Script::Compile(v8_str(source))->Run(); |
1767 i::CpuProfile* iprofile = iprofiler->GetProfile(0); | 1743 i::CpuProfile* iprofile = iprofiler->GetProfile(0); |
1768 iprofile->Print(); | 1744 iprofile->Print(); |
1769 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); | 1745 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); |
1770 const char* branch[] = {"", "test", "opt_function", "opt_function"}; | 1746 const char* branch[] = {"", "test", "opt_function", "opt_function"}; |
1771 const v8::CpuProfileNode* opt_function = GetSimpleBranch( | 1747 const ProfileNode* iopt_function = |
1772 env->GetIsolate(), profile->GetTopDownRoot(), branch, arraysize(branch)); | 1748 GetSimpleBranch(profile, branch, arraysize(branch)); |
1773 CHECK(opt_function); | |
1774 const i::ProfileNode* iopt_function = | |
1775 reinterpret_cast<const i::ProfileNode*>(opt_function); | |
1776 CHECK_EQ(2, iopt_function->deopt_infos().length()); | 1749 CHECK_EQ(2, iopt_function->deopt_infos().length()); |
1777 CHECK_EQ(i::Deoptimizer::GetDeoptReason(i::Deoptimizer::kNotAHeapNumber), | 1750 CHECK_EQ(reason(i::Deoptimizer::kNotAHeapNumber), |
1778 iopt_function->deopt_infos()[0].deopt_reason); | 1751 iopt_function->deopt_infos()[0].deopt_reason); |
1779 CHECK_EQ(i::Deoptimizer::GetDeoptReason(i::Deoptimizer::kDivisionByZero), | 1752 CHECK_EQ(reason(i::Deoptimizer::kDivisionByZero), |
1780 iopt_function->deopt_infos()[1].deopt_reason); | 1753 iopt_function->deopt_infos()[1].deopt_reason); |
1781 iprofiler->DeleteProfile(iprofile); | 1754 iprofiler->DeleteProfile(iprofile); |
1782 } | 1755 } |
1783 | 1756 |
1784 | 1757 |
1785 TEST(SourceLocation) { | 1758 TEST(SourceLocation) { |
1786 i::FLAG_always_opt = true; | 1759 i::FLAG_always_opt = true; |
1787 i::FLAG_hydrogen_track_positions = true; | 1760 i::FLAG_hydrogen_track_positions = true; |
1788 LocalContext env; | 1761 LocalContext env; |
1789 v8::HandleScope scope(CcTest::isolate()); | 1762 v8::HandleScope scope(CcTest::isolate()); |
1790 | 1763 |
1791 const char* source = | 1764 const char* source = |
1792 "function CompareStatementWithThis() {\n" | 1765 "function CompareStatementWithThis() {\n" |
1793 " if (this === 1) {}\n" | 1766 " if (this === 1) {}\n" |
1794 "}\n" | 1767 "}\n" |
1795 "CompareStatementWithThis();\n"; | 1768 "CompareStatementWithThis();\n"; |
1796 | 1769 |
1797 v8::Script::Compile(v8_str(source))->Run(); | 1770 v8::Script::Compile(v8_str(source))->Run(); |
1798 } | 1771 } |
OLD | NEW |