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