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

Side by Side Diff: runtime/vm/profiler_test.cc

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/runtime_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/profiler.h" 10 #include "vm/profiler.h"
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 559 }
560 560
561 561
562 TEST_CASE(Profiler_IntrinsicAllocation) { 562 TEST_CASE(Profiler_IntrinsicAllocation) {
563 DisableNativeProfileScope dnps; 563 DisableNativeProfileScope dnps;
564 const char* kScript = "double foo(double a, double b) => a + b;"; 564 const char* kScript = "double foo(double a, double b) => a + b;";
565 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 565 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
566 EXPECT_VALID(lib); 566 EXPECT_VALID(lib);
567 Library& root_library = Library::Handle(); 567 Library& root_library = Library::Handle();
568 root_library ^= Api::UnwrapHandle(lib); 568 root_library ^= Api::UnwrapHandle(lib);
569 Isolate* isolate = Isolate::Current(); 569 Isolate* isolate = thread->isolate();
570 570
571 const Class& double_class = 571 const Class& double_class =
572 Class::Handle(isolate->object_store()->double_class()); 572 Class::Handle(isolate->object_store()->double_class());
573 EXPECT(!double_class.IsNull()); 573 EXPECT(!double_class.IsNull());
574 574
575 Dart_Handle args[2] = { Dart_NewDouble(1.0), Dart_NewDouble(2.0), }; 575 Dart_Handle args[2] = { Dart_NewDouble(1.0), Dart_NewDouble(2.0), };
576 576
577 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 577 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
578 EXPECT_VALID(result); 578 EXPECT_VALID(result);
579 579
580 { 580 {
581 StackZone zone(isolate); 581 StackZone zone(thread);
582 HANDLESCOPE(isolate); 582 HANDLESCOPE(thread);
583 Profile profile(isolate); 583 Profile profile(isolate);
584 AllocationFilter filter(isolate, double_class.id()); 584 AllocationFilter filter(isolate, double_class.id());
585 profile.Build(&filter, Profile::kNoTags); 585 profile.Build(&filter, Profile::kNoTags);
586 // We should have no allocation samples. 586 // We should have no allocation samples.
587 EXPECT_EQ(0, profile.sample_count()); 587 EXPECT_EQ(0, profile.sample_count());
588 } 588 }
589 589
590 double_class.SetTraceAllocation(true); 590 double_class.SetTraceAllocation(true);
591 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 591 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
592 EXPECT_VALID(result); 592 EXPECT_VALID(result);
593 593
594 { 594 {
595 StackZone zone(isolate); 595 StackZone zone(thread);
596 HANDLESCOPE(isolate); 596 HANDLESCOPE(thread);
597 Profile profile(isolate); 597 Profile profile(isolate);
598 AllocationFilter filter(isolate, double_class.id()); 598 AllocationFilter filter(isolate, double_class.id());
599 profile.Build(&filter, Profile::kNoTags); 599 profile.Build(&filter, Profile::kNoTags);
600 // We should have one allocation sample. 600 // We should have one allocation sample.
601 EXPECT_EQ(1, profile.sample_count()); 601 EXPECT_EQ(1, profile.sample_count());
602 ProfileTrieWalker walker(&profile); 602 ProfileTrieWalker walker(&profile);
603 603
604 walker.Reset(Profile::kExclusiveCode); 604 walker.Reset(Profile::kExclusiveCode);
605 EXPECT(walker.Down()); 605 EXPECT(walker.Down());
606 EXPECT_STREQ("_Double._add", walker.CurrentName()); 606 EXPECT_STREQ("_Double._add", walker.CurrentName());
607 EXPECT(walker.Down()); 607 EXPECT(walker.Down());
608 EXPECT_STREQ("_Double.+", walker.CurrentName()); 608 EXPECT_STREQ("_Double.+", walker.CurrentName());
609 EXPECT(walker.Down()); 609 EXPECT(walker.Down());
610 EXPECT_STREQ("foo", walker.CurrentName()); 610 EXPECT_STREQ("foo", walker.CurrentName());
611 EXPECT(!walker.Down()); 611 EXPECT(!walker.Down());
612 } 612 }
613 613
614 double_class.SetTraceAllocation(false); 614 double_class.SetTraceAllocation(false);
615 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 615 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
616 EXPECT_VALID(result); 616 EXPECT_VALID(result);
617 617
618 { 618 {
619 StackZone zone(isolate); 619 StackZone zone(thread);
620 HANDLESCOPE(isolate); 620 HANDLESCOPE(thread);
621 Profile profile(isolate); 621 Profile profile(isolate);
622 AllocationFilter filter(isolate, double_class.id()); 622 AllocationFilter filter(isolate, double_class.id());
623 profile.Build(&filter, Profile::kNoTags); 623 profile.Build(&filter, Profile::kNoTags);
624 // We should still only have one allocation sample. 624 // We should still only have one allocation sample.
625 EXPECT_EQ(1, profile.sample_count()); 625 EXPECT_EQ(1, profile.sample_count());
626 } 626 }
627 } 627 }
628 628
629 629
630 TEST_CASE(Profiler_ArrayAllocation) { 630 TEST_CASE(Profiler_ArrayAllocation) {
631 DisableNativeProfileScope dnps; 631 DisableNativeProfileScope dnps;
632 const char* kScript = 632 const char* kScript =
633 "List foo() => new List(4);\n" 633 "List foo() => new List(4);\n"
634 "List bar() => new List();\n"; 634 "List bar() => new List();\n";
635 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 635 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
636 EXPECT_VALID(lib); 636 EXPECT_VALID(lib);
637 Library& root_library = Library::Handle(); 637 Library& root_library = Library::Handle();
638 root_library ^= Api::UnwrapHandle(lib); 638 root_library ^= Api::UnwrapHandle(lib);
639 Isolate* isolate = Isolate::Current(); 639 Isolate* isolate = thread->isolate();
640 640
641 const Class& array_class = 641 const Class& array_class =
642 Class::Handle(isolate->object_store()->array_class()); 642 Class::Handle(isolate->object_store()->array_class());
643 EXPECT(!array_class.IsNull()); 643 EXPECT(!array_class.IsNull());
644 644
645 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 645 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
646 EXPECT_VALID(result); 646 EXPECT_VALID(result);
647 647
648 { 648 {
649 StackZone zone(isolate); 649 StackZone zone(thread);
650 HANDLESCOPE(isolate); 650 HANDLESCOPE(thread);
651 Profile profile(isolate); 651 Profile profile(isolate);
652 AllocationFilter filter(isolate, array_class.id()); 652 AllocationFilter filter(isolate, array_class.id());
653 profile.Build(&filter, Profile::kNoTags); 653 profile.Build(&filter, Profile::kNoTags);
654 // We should have no allocation samples. 654 // We should have no allocation samples.
655 EXPECT_EQ(0, profile.sample_count()); 655 EXPECT_EQ(0, profile.sample_count());
656 } 656 }
657 657
658 array_class.SetTraceAllocation(true); 658 array_class.SetTraceAllocation(true);
659 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 659 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
660 EXPECT_VALID(result); 660 EXPECT_VALID(result);
661 661
662 { 662 {
663 StackZone zone(isolate); 663 StackZone zone(thread);
664 HANDLESCOPE(isolate); 664 HANDLESCOPE(thread);
665 Profile profile(isolate); 665 Profile profile(isolate);
666 AllocationFilter filter(isolate, array_class.id()); 666 AllocationFilter filter(isolate, array_class.id());
667 profile.Build(&filter, Profile::kNoTags); 667 profile.Build(&filter, Profile::kNoTags);
668 // We should have one allocation sample. 668 // We should have one allocation sample.
669 EXPECT_EQ(1, profile.sample_count()); 669 EXPECT_EQ(1, profile.sample_count());
670 ProfileTrieWalker walker(&profile); 670 ProfileTrieWalker walker(&profile);
671 671
672 walker.Reset(Profile::kExclusiveCode); 672 walker.Reset(Profile::kExclusiveCode);
673 EXPECT(walker.Down()); 673 EXPECT(walker.Down());
674 EXPECT_STREQ("_List._List", walker.CurrentName()); 674 EXPECT_STREQ("_List._List", walker.CurrentName());
675 EXPECT(walker.Down()); 675 EXPECT(walker.Down());
676 EXPECT_STREQ("List.List", walker.CurrentName()); 676 EXPECT_STREQ("List.List", walker.CurrentName());
677 EXPECT(walker.Down()); 677 EXPECT(walker.Down());
678 EXPECT_STREQ("foo", walker.CurrentName()); 678 EXPECT_STREQ("foo", walker.CurrentName());
679 EXPECT(!walker.Down()); 679 EXPECT(!walker.Down());
680 } 680 }
681 681
682 array_class.SetTraceAllocation(false); 682 array_class.SetTraceAllocation(false);
683 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 683 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
684 EXPECT_VALID(result); 684 EXPECT_VALID(result);
685 685
686 { 686 {
687 StackZone zone(isolate); 687 StackZone zone(thread);
688 HANDLESCOPE(isolate); 688 HANDLESCOPE(thread);
689 Profile profile(isolate); 689 Profile profile(isolate);
690 AllocationFilter filter(isolate, array_class.id()); 690 AllocationFilter filter(isolate, array_class.id());
691 profile.Build(&filter, Profile::kNoTags); 691 profile.Build(&filter, Profile::kNoTags);
692 // We should still only have one allocation sample. 692 // We should still only have one allocation sample.
693 EXPECT_EQ(1, profile.sample_count()); 693 EXPECT_EQ(1, profile.sample_count());
694 } 694 }
695 695
696 // Clear the samples. 696 // Clear the samples.
697 ProfilerService::ClearSamples(); 697 ProfilerService::ClearSamples();
698 698
699 // Compile bar (many List objects allocated). 699 // Compile bar (many List objects allocated).
700 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 700 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
701 EXPECT_VALID(result); 701 EXPECT_VALID(result);
702 702
703 // Enable again. 703 // Enable again.
704 array_class.SetTraceAllocation(true); 704 array_class.SetTraceAllocation(true);
705 705
706 // Run bar. 706 // Run bar.
707 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 707 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
708 EXPECT_VALID(result); 708 EXPECT_VALID(result);
709 709
710 { 710 {
711 StackZone zone(isolate); 711 StackZone zone(thread);
712 HANDLESCOPE(isolate); 712 HANDLESCOPE(thread);
713 Profile profile(isolate); 713 Profile profile(isolate);
714 AllocationFilter filter(isolate, array_class.id()); 714 AllocationFilter filter(isolate, array_class.id());
715 profile.Build(&filter, Profile::kNoTags); 715 profile.Build(&filter, Profile::kNoTags);
716 // We should still only have one allocation sample. 716 // We should still only have one allocation sample.
717 EXPECT_EQ(1, profile.sample_count()); 717 EXPECT_EQ(1, profile.sample_count());
718 ProfileTrieWalker walker(&profile); 718 ProfileTrieWalker walker(&profile);
719 719
720 walker.Reset(Profile::kExclusiveCode); 720 walker.Reset(Profile::kExclusiveCode);
721 EXPECT(walker.Down()); 721 EXPECT(walker.Down());
722 EXPECT_STREQ("_List._List", walker.CurrentName()); 722 EXPECT_STREQ("_List._List", walker.CurrentName());
(...skipping 13 matching lines...) Expand all
736 const char* kScript = 736 const char* kScript =
737 "var msg1 = 'a';\n" 737 "var msg1 = 'a';\n"
738 "foo() {\n" 738 "foo() {\n"
739 " var msg = msg1 + msg1;\n" 739 " var msg = msg1 + msg1;\n"
740 " return (x) { return '$msg + $msg'; }(msg);\n" 740 " return (x) { return '$msg + $msg'; }(msg);\n"
741 "}\n"; 741 "}\n";
742 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 742 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
743 EXPECT_VALID(lib); 743 EXPECT_VALID(lib);
744 Library& root_library = Library::Handle(); 744 Library& root_library = Library::Handle();
745 root_library ^= Api::UnwrapHandle(lib); 745 root_library ^= Api::UnwrapHandle(lib);
746 Isolate* isolate = Isolate::Current(); 746 Isolate* isolate = thread->isolate();
747 747
748 const Class& context_class = 748 const Class& context_class =
749 Class::Handle(Object::context_class()); 749 Class::Handle(Object::context_class());
750 EXPECT(!context_class.IsNull()); 750 EXPECT(!context_class.IsNull());
751 751
752 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 752 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
753 EXPECT_VALID(result); 753 EXPECT_VALID(result);
754 754
755 { 755 {
756 StackZone zone(isolate); 756 StackZone zone(thread);
757 HANDLESCOPE(isolate); 757 HANDLESCOPE(thread);
758 Profile profile(isolate); 758 Profile profile(isolate);
759 AllocationFilter filter(isolate, context_class.id()); 759 AllocationFilter filter(isolate, context_class.id());
760 profile.Build(&filter, Profile::kNoTags); 760 profile.Build(&filter, Profile::kNoTags);
761 // We should have no allocation samples. 761 // We should have no allocation samples.
762 EXPECT_EQ(0, profile.sample_count()); 762 EXPECT_EQ(0, profile.sample_count());
763 } 763 }
764 764
765 context_class.SetTraceAllocation(true); 765 context_class.SetTraceAllocation(true);
766 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 766 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
767 EXPECT_VALID(result); 767 EXPECT_VALID(result);
768 768
769 { 769 {
770 StackZone zone(isolate); 770 StackZone zone(thread);
771 HANDLESCOPE(isolate); 771 HANDLESCOPE(thread);
772 Profile profile(isolate); 772 Profile profile(isolate);
773 AllocationFilter filter(isolate, context_class.id()); 773 AllocationFilter filter(isolate, context_class.id());
774 profile.Build(&filter, Profile::kNoTags); 774 profile.Build(&filter, Profile::kNoTags);
775 // We should have one allocation sample. 775 // We should have one allocation sample.
776 EXPECT_EQ(1, profile.sample_count()); 776 EXPECT_EQ(1, profile.sample_count());
777 ProfileTrieWalker walker(&profile); 777 ProfileTrieWalker walker(&profile);
778 778
779 walker.Reset(Profile::kExclusiveCode); 779 walker.Reset(Profile::kExclusiveCode);
780 EXPECT(walker.Down()); 780 EXPECT(walker.Down());
781 EXPECT_STREQ("foo", walker.CurrentName()); 781 EXPECT_STREQ("foo", walker.CurrentName());
782 EXPECT(!walker.Down()); 782 EXPECT(!walker.Down());
783 } 783 }
784 784
785 context_class.SetTraceAllocation(false); 785 context_class.SetTraceAllocation(false);
786 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 786 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
787 EXPECT_VALID(result); 787 EXPECT_VALID(result);
788 788
789 { 789 {
790 StackZone zone(isolate); 790 StackZone zone(thread);
791 HANDLESCOPE(isolate); 791 HANDLESCOPE(thread);
792 Profile profile(isolate); 792 Profile profile(isolate);
793 AllocationFilter filter(isolate, context_class.id()); 793 AllocationFilter filter(isolate, context_class.id());
794 profile.Build(&filter, Profile::kNoTags); 794 profile.Build(&filter, Profile::kNoTags);
795 // We should still only have one allocation sample. 795 // We should still only have one allocation sample.
796 EXPECT_EQ(1, profile.sample_count()); 796 EXPECT_EQ(1, profile.sample_count());
797 } 797 }
798 } 798 }
799 799
800 800
801 TEST_CASE(Profiler_ClassAllocation) { 801 TEST_CASE(Profiler_ClassAllocation) {
802 DisableNativeProfileScope dnps; 802 DisableNativeProfileScope dnps;
803 const char* kScript = 803 const char* kScript =
804 "var msg1 = 'a';\n" 804 "var msg1 = 'a';\n"
805 "\n" 805 "\n"
806 "foo() {\n" 806 "foo() {\n"
807 " var msg = msg1 + msg1;\n" 807 " var msg = msg1 + msg1;\n"
808 " var msg2 = msg + msg;\n" 808 " var msg2 = msg + msg;\n"
809 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" 809 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n"
810 "}\n" 810 "}\n"
811 "bar() {\n" 811 "bar() {\n"
812 " var msg = msg1 + msg1;\n" 812 " var msg = msg1 + msg1;\n"
813 " var msg2 = msg + msg;\n" 813 " var msg2 = msg + msg;\n"
814 " return (x, y) { return '$x + $y'; }(msg, msg2);\n" 814 " return (x, y) { return '$x + $y'; }(msg, msg2);\n"
815 "}\n"; 815 "}\n";
816 816
817 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 817 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
818 EXPECT_VALID(lib); 818 EXPECT_VALID(lib);
819 Library& root_library = Library::Handle(); 819 Library& root_library = Library::Handle();
820 root_library ^= Api::UnwrapHandle(lib); 820 root_library ^= Api::UnwrapHandle(lib);
821 Isolate* isolate = Isolate::Current(); 821 Isolate* isolate = thread->isolate();
822 822
823 const Class& class_class = 823 const Class& class_class =
824 Class::Handle(Object::class_class()); 824 Class::Handle(Object::class_class());
825 EXPECT(!class_class.IsNull()); 825 EXPECT(!class_class.IsNull());
826 class_class.SetTraceAllocation(true); 826 class_class.SetTraceAllocation(true);
827 827
828 // Invoke "foo" which during compilation, triggers a closure class allocation. 828 // Invoke "foo" which during compilation, triggers a closure class allocation.
829 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 829 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
830 EXPECT_VALID(result); 830 EXPECT_VALID(result);
831 831
832 { 832 {
833 StackZone zone(isolate); 833 StackZone zone(thread);
834 HANDLESCOPE(isolate); 834 HANDLESCOPE(thread);
835 Profile profile(isolate); 835 Profile profile(isolate);
836 AllocationFilter filter(isolate, class_class.id()); 836 AllocationFilter filter(isolate, class_class.id());
837 filter.set_enable_embedder_ticks(true); 837 filter.set_enable_embedder_ticks(true);
838 profile.Build(&filter, Profile::kNoTags); 838 profile.Build(&filter, Profile::kNoTags);
839 // We should have one allocation sample. 839 // We should have one allocation sample.
840 EXPECT_EQ(1, profile.sample_count()); 840 EXPECT_EQ(1, profile.sample_count());
841 ProfileTrieWalker walker(&profile); 841 ProfileTrieWalker walker(&profile);
842 842
843 walker.Reset(Profile::kExclusiveCode); 843 walker.Reset(Profile::kExclusiveCode);
844 EXPECT(walker.Down()); 844 EXPECT(walker.Down());
845 #if defined(TARGET_OS_WINDOWS) 845 #if defined(TARGET_OS_WINDOWS)
846 // TODO(johnmccutchan): Hookup native symbol resolver on Windows. 846 // TODO(johnmccutchan): Hookup native symbol resolver on Windows.
847 EXPECT_SUBSTRING("[Native]", walker.CurrentName()); 847 EXPECT_SUBSTRING("[Native]", walker.CurrentName());
848 #else 848 #else
849 EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName()); 849 EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName());
850 #endif 850 #endif
851 EXPECT(!walker.Down()); 851 EXPECT(!walker.Down());
852 } 852 }
853 853
854 // Disable allocation tracing for Class. 854 // Disable allocation tracing for Class.
855 class_class.SetTraceAllocation(false); 855 class_class.SetTraceAllocation(false);
856 856
857 // Invoke "bar" which during compilation, triggers a closure class allocation. 857 // Invoke "bar" which during compilation, triggers a closure class allocation.
858 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 858 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
859 EXPECT_VALID(result); 859 EXPECT_VALID(result);
860 860
861 { 861 {
862 StackZone zone(isolate); 862 StackZone zone(thread);
863 HANDLESCOPE(isolate); 863 HANDLESCOPE(thread);
864 Profile profile(isolate); 864 Profile profile(isolate);
865 AllocationFilter filter(isolate, class_class.id()); 865 AllocationFilter filter(isolate, class_class.id());
866 filter.set_enable_embedder_ticks(true); 866 filter.set_enable_embedder_ticks(true);
867 profile.Build(&filter, Profile::kNoTags); 867 profile.Build(&filter, Profile::kNoTags);
868 // We should still only have one allocation sample. 868 // We should still only have one allocation sample.
869 EXPECT_EQ(1, profile.sample_count()); 869 EXPECT_EQ(1, profile.sample_count());
870 } 870 }
871 } 871 }
872 872
873 873
874 TEST_CASE(Profiler_TypedArrayAllocation) { 874 TEST_CASE(Profiler_TypedArrayAllocation) {
875 DisableNativeProfileScope dnps; 875 DisableNativeProfileScope dnps;
876 const char* kScript = 876 const char* kScript =
877 "import 'dart:typed_data';\n" 877 "import 'dart:typed_data';\n"
878 "List foo() => new Float32List(4);\n"; 878 "List foo() => new Float32List(4);\n";
879 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 879 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
880 EXPECT_VALID(lib); 880 EXPECT_VALID(lib);
881 Library& root_library = Library::Handle(); 881 Library& root_library = Library::Handle();
882 root_library ^= Api::UnwrapHandle(lib); 882 root_library ^= Api::UnwrapHandle(lib);
883 Isolate* isolate = Isolate::Current(); 883 Isolate* isolate = thread->isolate();
884 884
885 const Library& typed_data_library = 885 const Library& typed_data_library =
886 Library::Handle(isolate->object_store()->typed_data_library()); 886 Library::Handle(isolate->object_store()->typed_data_library());
887 887
888 const Class& float32_list_class = 888 const Class& float32_list_class =
889 Class::Handle(GetClass(typed_data_library, "_Float32Array")); 889 Class::Handle(GetClass(typed_data_library, "_Float32Array"));
890 EXPECT(!float32_list_class.IsNull()); 890 EXPECT(!float32_list_class.IsNull());
891 891
892 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 892 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
893 EXPECT_VALID(result); 893 EXPECT_VALID(result);
894 894
895 { 895 {
896 StackZone zone(isolate); 896 StackZone zone(thread);
897 HANDLESCOPE(isolate); 897 HANDLESCOPE(thread);
898 Profile profile(isolate); 898 Profile profile(isolate);
899 AllocationFilter filter(isolate, float32_list_class.id()); 899 AllocationFilter filter(isolate, float32_list_class.id());
900 profile.Build(&filter, Profile::kNoTags); 900 profile.Build(&filter, Profile::kNoTags);
901 // We should have no allocation samples. 901 // We should have no allocation samples.
902 EXPECT_EQ(0, profile.sample_count()); 902 EXPECT_EQ(0, profile.sample_count());
903 } 903 }
904 904
905 float32_list_class.SetTraceAllocation(true); 905 float32_list_class.SetTraceAllocation(true);
906 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 906 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
907 EXPECT_VALID(result); 907 EXPECT_VALID(result);
908 908
909 { 909 {
910 StackZone zone(isolate); 910 StackZone zone(thread);
911 HANDLESCOPE(isolate); 911 HANDLESCOPE(thread);
912 Profile profile(isolate); 912 Profile profile(isolate);
913 AllocationFilter filter(isolate, float32_list_class.id()); 913 AllocationFilter filter(isolate, float32_list_class.id());
914 profile.Build(&filter, Profile::kNoTags); 914 profile.Build(&filter, Profile::kNoTags);
915 // We should have one allocation sample. 915 // We should have one allocation sample.
916 EXPECT_EQ(1, profile.sample_count()); 916 EXPECT_EQ(1, profile.sample_count());
917 ProfileTrieWalker walker(&profile); 917 ProfileTrieWalker walker(&profile);
918 918
919 walker.Reset(Profile::kExclusiveCode); 919 walker.Reset(Profile::kExclusiveCode);
920 EXPECT(walker.Down()); 920 EXPECT(walker.Down());
921 EXPECT_STREQ("_Float32Array._new", walker.CurrentName()); 921 EXPECT_STREQ("_Float32Array._new", walker.CurrentName());
922 EXPECT(walker.Down()); 922 EXPECT(walker.Down());
923 EXPECT_STREQ("_Float32Array._Float32Array", walker.CurrentName()); 923 EXPECT_STREQ("_Float32Array._Float32Array", walker.CurrentName());
924 EXPECT(walker.Down()); 924 EXPECT(walker.Down());
925 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName()); 925 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName());
926 EXPECT(walker.Down()); 926 EXPECT(walker.Down());
927 EXPECT_STREQ("foo", walker.CurrentName()); 927 EXPECT_STREQ("foo", walker.CurrentName());
928 EXPECT(!walker.Down()); 928 EXPECT(!walker.Down());
929 } 929 }
930 930
931 float32_list_class.SetTraceAllocation(false); 931 float32_list_class.SetTraceAllocation(false);
932 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 932 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
933 EXPECT_VALID(result); 933 EXPECT_VALID(result);
934 934
935 { 935 {
936 StackZone zone(isolate); 936 StackZone zone(thread);
937 HANDLESCOPE(isolate); 937 HANDLESCOPE(thread);
938 Profile profile(isolate); 938 Profile profile(isolate);
939 AllocationFilter filter(isolate, float32_list_class.id()); 939 AllocationFilter filter(isolate, float32_list_class.id());
940 profile.Build(&filter, Profile::kNoTags); 940 profile.Build(&filter, Profile::kNoTags);
941 // We should still only have one allocation sample. 941 // We should still only have one allocation sample.
942 EXPECT_EQ(1, profile.sample_count()); 942 EXPECT_EQ(1, profile.sample_count());
943 } 943 }
944 944
945 float32_list_class.SetTraceAllocation(true); 945 float32_list_class.SetTraceAllocation(true);
946 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 946 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
947 EXPECT_VALID(result); 947 EXPECT_VALID(result);
948 948
949 { 949 {
950 StackZone zone(isolate); 950 StackZone zone(thread);
951 HANDLESCOPE(isolate); 951 HANDLESCOPE(thread);
952 Profile profile(isolate); 952 Profile profile(isolate);
953 AllocationFilter filter(isolate, float32_list_class.id()); 953 AllocationFilter filter(isolate, float32_list_class.id());
954 profile.Build(&filter, Profile::kNoTags); 954 profile.Build(&filter, Profile::kNoTags);
955 // We should now have two allocation samples. 955 // We should now have two allocation samples.
956 EXPECT_EQ(2, profile.sample_count()); 956 EXPECT_EQ(2, profile.sample_count());
957 } 957 }
958 } 958 }
959 959
960 960
961 TEST_CASE(Profiler_StringAllocation) { 961 TEST_CASE(Profiler_StringAllocation) {
962 DisableNativeProfileScope dnps; 962 DisableNativeProfileScope dnps;
963 const char* kScript = "String foo(String a, String b) => a + b;"; 963 const char* kScript = "String foo(String a, String b) => a + b;";
964 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 964 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
965 EXPECT_VALID(lib); 965 EXPECT_VALID(lib);
966 Library& root_library = Library::Handle(); 966 Library& root_library = Library::Handle();
967 root_library ^= Api::UnwrapHandle(lib); 967 root_library ^= Api::UnwrapHandle(lib);
968 Isolate* isolate = Isolate::Current(); 968 Isolate* isolate = thread->isolate();
969 969
970 const Class& one_byte_string_class = 970 const Class& one_byte_string_class =
971 Class::Handle(isolate->object_store()->one_byte_string_class()); 971 Class::Handle(isolate->object_store()->one_byte_string_class());
972 EXPECT(!one_byte_string_class.IsNull()); 972 EXPECT(!one_byte_string_class.IsNull());
973 973
974 Dart_Handle args[2] = { NewString("a"), NewString("b"), }; 974 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
975 975
976 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 976 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
977 EXPECT_VALID(result); 977 EXPECT_VALID(result);
978 978
979 { 979 {
980 StackZone zone(isolate); 980 StackZone zone(thread);
981 HANDLESCOPE(isolate); 981 HANDLESCOPE(thread);
982 Profile profile(isolate); 982 Profile profile(isolate);
983 AllocationFilter filter(isolate, one_byte_string_class.id()); 983 AllocationFilter filter(isolate, one_byte_string_class.id());
984 profile.Build(&filter, Profile::kNoTags); 984 profile.Build(&filter, Profile::kNoTags);
985 // We should have no allocation samples. 985 // We should have no allocation samples.
986 EXPECT_EQ(0, profile.sample_count()); 986 EXPECT_EQ(0, profile.sample_count());
987 } 987 }
988 988
989 one_byte_string_class.SetTraceAllocation(true); 989 one_byte_string_class.SetTraceAllocation(true);
990 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 990 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
991 EXPECT_VALID(result); 991 EXPECT_VALID(result);
992 992
993 { 993 {
994 StackZone zone(isolate); 994 StackZone zone(thread);
995 HANDLESCOPE(isolate); 995 HANDLESCOPE(thread);
996 Profile profile(isolate); 996 Profile profile(isolate);
997 AllocationFilter filter(isolate, one_byte_string_class.id()); 997 AllocationFilter filter(isolate, one_byte_string_class.id());
998 profile.Build(&filter, Profile::kNoTags); 998 profile.Build(&filter, Profile::kNoTags);
999 // We should still only have one allocation sample. 999 // We should still only have one allocation sample.
1000 EXPECT_EQ(1, profile.sample_count()); 1000 EXPECT_EQ(1, profile.sample_count());
1001 ProfileTrieWalker walker(&profile); 1001 ProfileTrieWalker walker(&profile);
1002 1002
1003 walker.Reset(Profile::kExclusiveCode); 1003 walker.Reset(Profile::kExclusiveCode);
1004 EXPECT(walker.Down()); 1004 EXPECT(walker.Down());
1005 EXPECT_STREQ("_StringBase.+", walker.CurrentName()); 1005 EXPECT_STREQ("_StringBase.+", walker.CurrentName());
1006 EXPECT(walker.Down()); 1006 EXPECT(walker.Down());
1007 EXPECT_STREQ("foo", walker.CurrentName()); 1007 EXPECT_STREQ("foo", walker.CurrentName());
1008 EXPECT(!walker.Down()); 1008 EXPECT(!walker.Down());
1009 } 1009 }
1010 1010
1011 one_byte_string_class.SetTraceAllocation(false); 1011 one_byte_string_class.SetTraceAllocation(false);
1012 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1012 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1013 EXPECT_VALID(result); 1013 EXPECT_VALID(result);
1014 1014
1015 { 1015 {
1016 StackZone zone(isolate); 1016 StackZone zone(thread);
1017 HANDLESCOPE(isolate); 1017 HANDLESCOPE(thread);
1018 Profile profile(isolate); 1018 Profile profile(isolate);
1019 AllocationFilter filter(isolate, one_byte_string_class.id()); 1019 AllocationFilter filter(isolate, one_byte_string_class.id());
1020 profile.Build(&filter, Profile::kNoTags); 1020 profile.Build(&filter, Profile::kNoTags);
1021 // We should still only have one allocation sample. 1021 // We should still only have one allocation sample.
1022 EXPECT_EQ(1, profile.sample_count()); 1022 EXPECT_EQ(1, profile.sample_count());
1023 } 1023 }
1024 1024
1025 one_byte_string_class.SetTraceAllocation(true); 1025 one_byte_string_class.SetTraceAllocation(true);
1026 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1026 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1027 EXPECT_VALID(result); 1027 EXPECT_VALID(result);
1028 1028
1029 { 1029 {
1030 StackZone zone(isolate); 1030 StackZone zone(thread);
1031 HANDLESCOPE(isolate); 1031 HANDLESCOPE(thread);
1032 Profile profile(isolate); 1032 Profile profile(isolate);
1033 AllocationFilter filter(isolate, one_byte_string_class.id()); 1033 AllocationFilter filter(isolate, one_byte_string_class.id());
1034 profile.Build(&filter, Profile::kNoTags); 1034 profile.Build(&filter, Profile::kNoTags);
1035 // We should now have two allocation samples. 1035 // We should now have two allocation samples.
1036 EXPECT_EQ(2, profile.sample_count()); 1036 EXPECT_EQ(2, profile.sample_count());
1037 } 1037 }
1038 } 1038 }
1039 1039
1040 1040
1041 TEST_CASE(Profiler_StringInterpolation) { 1041 TEST_CASE(Profiler_StringInterpolation) {
1042 DisableNativeProfileScope dnps; 1042 DisableNativeProfileScope dnps;
1043 const char* kScript = "String foo(String a, String b) => '$a | $b';"; 1043 const char* kScript = "String foo(String a, String b) => '$a | $b';";
1044 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 1044 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1045 EXPECT_VALID(lib); 1045 EXPECT_VALID(lib);
1046 Library& root_library = Library::Handle(); 1046 Library& root_library = Library::Handle();
1047 root_library ^= Api::UnwrapHandle(lib); 1047 root_library ^= Api::UnwrapHandle(lib);
1048 Isolate* isolate = Isolate::Current(); 1048 Isolate* isolate = thread->isolate();
1049 1049
1050 const Class& one_byte_string_class = 1050 const Class& one_byte_string_class =
1051 Class::Handle(isolate->object_store()->one_byte_string_class()); 1051 Class::Handle(isolate->object_store()->one_byte_string_class());
1052 EXPECT(!one_byte_string_class.IsNull()); 1052 EXPECT(!one_byte_string_class.IsNull());
1053 1053
1054 Dart_Handle args[2] = { NewString("a"), NewString("b"), }; 1054 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
1055 1055
1056 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1056 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1057 EXPECT_VALID(result); 1057 EXPECT_VALID(result);
1058 1058
1059 { 1059 {
1060 StackZone zone(isolate); 1060 StackZone zone(thread);
1061 HANDLESCOPE(isolate); 1061 HANDLESCOPE(thread);
1062 Profile profile(isolate); 1062 Profile profile(isolate);
1063 AllocationFilter filter(isolate, one_byte_string_class.id()); 1063 AllocationFilter filter(isolate, one_byte_string_class.id());
1064 profile.Build(&filter, Profile::kNoTags); 1064 profile.Build(&filter, Profile::kNoTags);
1065 // We should have no allocation samples. 1065 // We should have no allocation samples.
1066 EXPECT_EQ(0, profile.sample_count()); 1066 EXPECT_EQ(0, profile.sample_count());
1067 } 1067 }
1068 1068
1069 one_byte_string_class.SetTraceAllocation(true); 1069 one_byte_string_class.SetTraceAllocation(true);
1070 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1070 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1071 EXPECT_VALID(result); 1071 EXPECT_VALID(result);
1072 1072
1073 { 1073 {
1074 StackZone zone(isolate); 1074 StackZone zone(thread);
1075 HANDLESCOPE(isolate); 1075 HANDLESCOPE(thread);
1076 Profile profile(isolate); 1076 Profile profile(isolate);
1077 AllocationFilter filter(isolate, one_byte_string_class.id()); 1077 AllocationFilter filter(isolate, one_byte_string_class.id());
1078 profile.Build(&filter, Profile::kNoTags); 1078 profile.Build(&filter, Profile::kNoTags);
1079 // We should still only have one allocation sample. 1079 // We should still only have one allocation sample.
1080 EXPECT_EQ(1, profile.sample_count()); 1080 EXPECT_EQ(1, profile.sample_count());
1081 ProfileTrieWalker walker(&profile); 1081 ProfileTrieWalker walker(&profile);
1082 1082
1083 walker.Reset(Profile::kExclusiveCode); 1083 walker.Reset(Profile::kExclusiveCode);
1084 EXPECT(walker.Down()); 1084 EXPECT(walker.Down());
1085 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName()); 1085 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName());
1086 EXPECT(walker.Down()); 1086 EXPECT(walker.Down());
1087 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName()); 1087 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName());
1088 EXPECT(walker.Down()); 1088 EXPECT(walker.Down());
1089 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName()); 1089 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName());
1090 EXPECT(walker.Down()); 1090 EXPECT(walker.Down());
1091 EXPECT_STREQ("foo", walker.CurrentName()); 1091 EXPECT_STREQ("foo", walker.CurrentName());
1092 EXPECT(!walker.Down()); 1092 EXPECT(!walker.Down());
1093 } 1093 }
1094 1094
1095 one_byte_string_class.SetTraceAllocation(false); 1095 one_byte_string_class.SetTraceAllocation(false);
1096 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1096 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1097 EXPECT_VALID(result); 1097 EXPECT_VALID(result);
1098 1098
1099 { 1099 {
1100 StackZone zone(isolate); 1100 StackZone zone(thread);
1101 HANDLESCOPE(isolate); 1101 HANDLESCOPE(thread);
1102 Profile profile(isolate); 1102 Profile profile(isolate);
1103 AllocationFilter filter(isolate, one_byte_string_class.id()); 1103 AllocationFilter filter(isolate, one_byte_string_class.id());
1104 profile.Build(&filter, Profile::kNoTags); 1104 profile.Build(&filter, Profile::kNoTags);
1105 // We should still only have one allocation sample. 1105 // We should still only have one allocation sample.
1106 EXPECT_EQ(1, profile.sample_count()); 1106 EXPECT_EQ(1, profile.sample_count());
1107 } 1107 }
1108 1108
1109 one_byte_string_class.SetTraceAllocation(true); 1109 one_byte_string_class.SetTraceAllocation(true);
1110 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1110 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1111 EXPECT_VALID(result); 1111 EXPECT_VALID(result);
1112 1112
1113 { 1113 {
1114 StackZone zone(isolate); 1114 StackZone zone(thread);
1115 HANDLESCOPE(isolate); 1115 HANDLESCOPE(thread);
1116 Profile profile(isolate); 1116 Profile profile(isolate);
1117 AllocationFilter filter(isolate, one_byte_string_class.id()); 1117 AllocationFilter filter(isolate, one_byte_string_class.id());
1118 profile.Build(&filter, Profile::kNoTags); 1118 profile.Build(&filter, Profile::kNoTags);
1119 // We should now have two allocation samples. 1119 // We should now have two allocation samples.
1120 EXPECT_EQ(2, profile.sample_count()); 1120 EXPECT_EQ(2, profile.sample_count());
1121 } 1121 }
1122 } 1122 }
1123 1123
1124 1124
1125 TEST_CASE(Profiler_FunctionInline) { 1125 TEST_CASE(Profiler_FunctionInline) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 EXPECT(walker.Down()); 1472 EXPECT(walker.Down());
1473 EXPECT_STREQ("go", walker.CurrentName()); 1473 EXPECT_STREQ("go", walker.CurrentName());
1474 EXPECT(walker.Down()); 1474 EXPECT(walker.Down());
1475 EXPECT_STREQ("main", walker.CurrentName()); 1475 EXPECT_STREQ("main", walker.CurrentName());
1476 EXPECT(!walker.Down()); 1476 EXPECT(!walker.Down());
1477 } 1477 }
1478 } 1478 }
1479 1479
1480 } // namespace dart 1480 } // namespace dart
1481 1481
OLDNEW
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/runtime_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698