OLD | NEW |
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 HANDLESCOPE(thread); | 846 HANDLESCOPE(thread); |
847 Profile profile(isolate); | 847 Profile profile(isolate); |
848 AllocationFilter filter(isolate, context_class.id()); | 848 AllocationFilter filter(isolate, context_class.id()); |
849 profile.Build(thread, &filter, Profile::kNoTags); | 849 profile.Build(thread, &filter, Profile::kNoTags); |
850 // We should still only have one allocation sample. | 850 // We should still only have one allocation sample. |
851 EXPECT_EQ(1, profile.sample_count()); | 851 EXPECT_EQ(1, profile.sample_count()); |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 | 855 |
856 TEST_CASE(Profiler_ClassAllocation) { | 856 TEST_CASE(Profiler_ClosureAllocation) { |
857 DisableNativeProfileScope dnps; | 857 DisableNativeProfileScope dnps; |
858 const char* kScript = | 858 const char* kScript = |
859 "var msg1 = 'a';\n" | 859 "var msg1 = 'a';\n" |
860 "\n" | 860 "\n" |
861 "foo() {\n" | 861 "foo() {\n" |
862 " var msg = msg1 + msg1;\n" | 862 " var msg = msg1 + msg1;\n" |
863 " var msg2 = msg + msg;\n" | 863 " var msg2 = msg + msg;\n" |
864 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" | 864 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" |
865 "}\n" | 865 "}\n" |
866 "bar() {\n" | 866 "bar() {\n" |
867 " var msg = msg1 + msg1;\n" | 867 " var msg = msg1 + msg1;\n" |
868 " var msg2 = msg + msg;\n" | 868 " var msg2 = msg + msg;\n" |
869 " return (x, y) { return '$x + $y'; }(msg, msg2);\n" | 869 " return (x, y) { return '$x + $y'; }(msg, msg2);\n" |
870 "}\n"; | 870 "}\n"; |
871 | 871 |
872 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 872 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
873 EXPECT_VALID(lib); | 873 EXPECT_VALID(lib); |
874 Library& root_library = Library::Handle(); | 874 Library& root_library = Library::Handle(); |
875 root_library ^= Api::UnwrapHandle(lib); | 875 root_library ^= Api::UnwrapHandle(lib); |
876 Isolate* isolate = thread->isolate(); | 876 Isolate* isolate = thread->isolate(); |
877 | 877 |
878 const Class& class_class = | 878 const Class& closure_class = |
879 Class::Handle(Object::class_class()); | 879 Class::Handle(Isolate::Current()->object_store()->closure_class()); |
880 EXPECT(!class_class.IsNull()); | 880 EXPECT(!closure_class.IsNull()); |
881 class_class.SetTraceAllocation(true); | 881 closure_class.SetTraceAllocation(true); |
882 | 882 |
883 // Invoke "foo" which during compilation, triggers a closure class allocation. | 883 // Invoke "foo" which during compilation, triggers a closure allocation. |
884 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 884 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
885 EXPECT_VALID(result); | 885 EXPECT_VALID(result); |
886 | 886 |
887 { | 887 { |
888 StackZone zone(thread); | 888 StackZone zone(thread); |
889 HANDLESCOPE(thread); | 889 HANDLESCOPE(thread); |
890 Profile profile(isolate); | 890 Profile profile(isolate); |
891 AllocationFilter filter(isolate, class_class.id()); | 891 AllocationFilter filter(isolate, closure_class.id()); |
892 filter.set_enable_vm_ticks(true); | 892 filter.set_enable_vm_ticks(true); |
893 profile.Build(thread, &filter, Profile::kNoTags); | 893 profile.Build(thread, &filter, Profile::kNoTags); |
894 // We should have one allocation sample. | 894 // We should have one allocation sample. |
895 EXPECT_EQ(1, profile.sample_count()); | 895 EXPECT_EQ(1, profile.sample_count()); |
896 ProfileTrieWalker walker(&profile); | 896 ProfileTrieWalker walker(&profile); |
897 | 897 |
898 walker.Reset(Profile::kExclusiveCode); | 898 walker.Reset(Profile::kExclusiveCode); |
899 EXPECT(walker.Down()); | 899 EXPECT(walker.Down()); |
900 #if defined(TARGET_OS_WINDOWS) | 900 EXPECT_SUBSTRING("foo", walker.CurrentName()); |
901 // TODO(johnmccutchan): Hookup native symbol resolver on Windows. | |
902 EXPECT_SUBSTRING("[Native]", walker.CurrentName()); | |
903 #else | |
904 EXPECT_SUBSTRING("dart::Profiler::SampleAllocation", walker.CurrentName()); | |
905 #endif | |
906 EXPECT(!walker.Down()); | 901 EXPECT(!walker.Down()); |
907 } | 902 } |
908 | 903 |
909 // Disable allocation tracing for Class. | 904 // Disable allocation tracing for Closure. |
910 class_class.SetTraceAllocation(false); | 905 closure_class.SetTraceAllocation(false); |
911 | 906 |
912 // Invoke "bar" which during compilation, triggers a closure class allocation. | 907 // Invoke "bar" which during compilation, triggers a closure allocation. |
913 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); | 908 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
914 EXPECT_VALID(result); | 909 EXPECT_VALID(result); |
915 | 910 |
916 { | 911 { |
917 StackZone zone(thread); | 912 StackZone zone(thread); |
918 HANDLESCOPE(thread); | 913 HANDLESCOPE(thread); |
919 Profile profile(isolate); | 914 Profile profile(isolate); |
920 AllocationFilter filter(isolate, class_class.id()); | 915 AllocationFilter filter(isolate, closure_class.id()); |
921 filter.set_enable_vm_ticks(true); | 916 filter.set_enable_vm_ticks(true); |
922 profile.Build(thread, &filter, Profile::kNoTags); | 917 profile.Build(thread, &filter, Profile::kNoTags); |
923 // We should still only have one allocation sample. | 918 // We should still only have one allocation sample. |
924 EXPECT_EQ(1, profile.sample_count()); | 919 EXPECT_EQ(1, profile.sample_count()); |
925 } | 920 } |
926 } | 921 } |
927 | 922 |
928 | 923 |
929 TEST_CASE(Profiler_TypedArrayAllocation) { | 924 TEST_CASE(Profiler_TypedArrayAllocation) { |
930 DisableNativeProfileScope dnps; | 925 DisableNativeProfileScope dnps; |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 EXPECT(walker.Down()); | 1652 EXPECT(walker.Down()); |
1658 EXPECT_STREQ("go", walker.CurrentName()); | 1653 EXPECT_STREQ("go", walker.CurrentName()); |
1659 EXPECT(walker.Down()); | 1654 EXPECT(walker.Down()); |
1660 EXPECT_STREQ("main", walker.CurrentName()); | 1655 EXPECT_STREQ("main", walker.CurrentName()); |
1661 EXPECT(!walker.Down()); | 1656 EXPECT(!walker.Down()); |
1662 } | 1657 } |
1663 } | 1658 } |
1664 | 1659 |
1665 } // namespace dart | 1660 } // namespace dart |
1666 | 1661 |
OLD | NEW |