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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return sample->is_allocation_sample() && (sample->allocation_cid() == cid_); | 182 return sample->is_allocation_sample() && (sample->allocation_cid() == cid_); |
183 } | 183 } |
184 | 184 |
185 void set_enable_vm_ticks(bool enable) { enable_vm_ticks_ = enable; } | 185 void set_enable_vm_ticks(bool enable) { enable_vm_ticks_ = enable; } |
186 | 186 |
187 private: | 187 private: |
188 intptr_t cid_; | 188 intptr_t cid_; |
189 bool enable_vm_ticks_; | 189 bool enable_vm_ticks_; |
190 }; | 190 }; |
191 | 191 |
192 static void EnableProfiler() { | |
193 if (!FLAG_profiler) { | |
194 FLAG_profiler = true; | |
195 Profiler::InitOnce(); | |
196 } | |
197 } | |
198 | |
199 TEST_CASE(Profiler_TrivialRecordAllocation) { | 192 TEST_CASE(Profiler_TrivialRecordAllocation) { |
200 EnableProfiler(); | |
201 DisableNativeProfileScope dnps; | 193 DisableNativeProfileScope dnps; |
202 const char* kScript = | 194 const char* kScript = |
203 "class A {\n" | 195 "class A {\n" |
204 " var a;\n" | 196 " var a;\n" |
205 " var b;\n" | 197 " var b;\n" |
206 "}\n" | 198 "}\n" |
207 "class B {\n" | 199 "class B {\n" |
208 " static boo() {\n" | 200 " static boo() {\n" |
209 " return new A();\n" | 201 " return new A();\n" |
210 " }\n" | 202 " }\n" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 307 |
316 #if defined(DART_USE_TCMALLOC) && defined(HOST_OS_LINUX) && defined(DEBUG) && \ | 308 #if defined(DART_USE_TCMALLOC) && defined(HOST_OS_LINUX) && defined(DEBUG) && \ |
317 defined(HOST_ARCH_x64) | 309 defined(HOST_ARCH_x64) |
318 | 310 |
319 DART_NOINLINE static void NativeAllocationSampleHelper(char** result) { | 311 DART_NOINLINE static void NativeAllocationSampleHelper(char** result) { |
320 ASSERT(result != NULL); | 312 ASSERT(result != NULL); |
321 *result = static_cast<char*>(malloc(sizeof(char) * 1024)); | 313 *result = static_cast<char*>(malloc(sizeof(char) * 1024)); |
322 } | 314 } |
323 | 315 |
324 ISOLATE_UNIT_TEST_CASE(Profiler_NativeAllocation) { | 316 ISOLATE_UNIT_TEST_CASE(Profiler_NativeAllocation) { |
325 EnableProfiler(); | |
326 | |
327 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 317 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
328 FLAG_profiler_native_memory = true; | 318 FLAG_profiler_native_memory = true; |
329 | 319 |
330 MallocHooks::InitOnce(); | 320 MallocHooks::InitOnce(); |
331 MallocHooks::ResetStats(); | 321 MallocHooks::ResetStats(); |
332 bool stack_trace_collection_enabled = | 322 bool stack_trace_collection_enabled = |
333 MallocHooks::stack_trace_collection_enabled(); | 323 MallocHooks::stack_trace_collection_enabled(); |
334 MallocHooks::set_stack_trace_collection_enabled(true); | 324 MallocHooks::set_stack_trace_collection_enabled(true); |
335 | 325 |
336 char* result = NULL; | 326 char* result = NULL; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 509 |
520 MallocHooks::set_stack_trace_collection_enabled( | 510 MallocHooks::set_stack_trace_collection_enabled( |
521 stack_trace_collection_enabled); | 511 stack_trace_collection_enabled); |
522 MallocHooks::TearDown(); | 512 MallocHooks::TearDown(); |
523 FLAG_profiler_native_memory = enable_malloc_hooks_saved; | 513 FLAG_profiler_native_memory = enable_malloc_hooks_saved; |
524 } | 514 } |
525 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && | 515 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && |
526 // !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) | 516 // !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) |
527 | 517 |
528 TEST_CASE(Profiler_ToggleRecordAllocation) { | 518 TEST_CASE(Profiler_ToggleRecordAllocation) { |
529 EnableProfiler(); | |
530 | |
531 DisableNativeProfileScope dnps; | 519 DisableNativeProfileScope dnps; |
532 const char* kScript = | 520 const char* kScript = |
533 "class A {\n" | 521 "class A {\n" |
534 " var a;\n" | 522 " var a;\n" |
535 " var b;\n" | 523 " var b;\n" |
536 "}\n" | 524 "}\n" |
537 "class B {\n" | 525 "class B {\n" |
538 " static boo() {\n" | 526 " static boo() {\n" |
539 " return new A();\n" | 527 " return new A();\n" |
540 " }\n" | 528 " }\n" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 HANDLESCOPE(thread); | 638 HANDLESCOPE(thread); |
651 Profile profile(isolate); | 639 Profile profile(isolate); |
652 AllocationFilter filter(isolate->main_port(), class_a.id()); | 640 AllocationFilter filter(isolate->main_port(), class_a.id()); |
653 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 641 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
654 // We should still only have one allocation sample. | 642 // We should still only have one allocation sample. |
655 EXPECT_EQ(1, profile.sample_count()); | 643 EXPECT_EQ(1, profile.sample_count()); |
656 } | 644 } |
657 } | 645 } |
658 | 646 |
659 TEST_CASE(Profiler_CodeTicks) { | 647 TEST_CASE(Profiler_CodeTicks) { |
660 EnableProfiler(); | |
661 DisableNativeProfileScope dnps; | 648 DisableNativeProfileScope dnps; |
662 const char* kScript = | 649 const char* kScript = |
663 "class A {\n" | 650 "class A {\n" |
664 " var a;\n" | 651 " var a;\n" |
665 " var b;\n" | 652 " var b;\n" |
666 "}\n" | 653 "}\n" |
667 "class B {\n" | 654 "class B {\n" |
668 " static boo() {\n" | 655 " static boo() {\n" |
669 " return new A();\n" | 656 " return new A();\n" |
670 " }\n" | 657 " }\n" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 EXPECT(walker.Down()); | 740 EXPECT(walker.Down()); |
754 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); | 741 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); |
755 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); | 742 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); |
756 EXPECT(walker.Down()); | 743 EXPECT(walker.Down()); |
757 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 744 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
758 EXPECT(!walker.Down()); | 745 EXPECT(!walker.Down()); |
759 } | 746 } |
760 } | 747 } |
761 | 748 |
762 TEST_CASE(Profiler_FunctionTicks) { | 749 TEST_CASE(Profiler_FunctionTicks) { |
763 EnableProfiler(); | |
764 DisableNativeProfileScope dnps; | 750 DisableNativeProfileScope dnps; |
765 const char* kScript = | 751 const char* kScript = |
766 "class A {\n" | 752 "class A {\n" |
767 " var a;\n" | 753 " var a;\n" |
768 " var b;\n" | 754 " var b;\n" |
769 "}\n" | 755 "}\n" |
770 "class B {\n" | 756 "class B {\n" |
771 " static boo() {\n" | 757 " static boo() {\n" |
772 " return new A();\n" | 758 " return new A();\n" |
773 " }\n" | 759 " }\n" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 EXPECT(walker.Down()); | 842 EXPECT(walker.Down()); |
857 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); | 843 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); |
858 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); | 844 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); |
859 EXPECT(walker.Down()); | 845 EXPECT(walker.Down()); |
860 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 846 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
861 EXPECT(!walker.Down()); | 847 EXPECT(!walker.Down()); |
862 } | 848 } |
863 } | 849 } |
864 | 850 |
865 TEST_CASE(Profiler_IntrinsicAllocation) { | 851 TEST_CASE(Profiler_IntrinsicAllocation) { |
866 EnableProfiler(); | |
867 DisableNativeProfileScope dnps; | 852 DisableNativeProfileScope dnps; |
868 const char* kScript = "double foo(double a, double b) => a + b;"; | 853 const char* kScript = "double foo(double a, double b) => a + b;"; |
869 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 854 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
870 EXPECT_VALID(lib); | 855 EXPECT_VALID(lib); |
871 Library& root_library = Library::Handle(); | 856 Library& root_library = Library::Handle(); |
872 root_library ^= Api::UnwrapHandle(lib); | 857 root_library ^= Api::UnwrapHandle(lib); |
873 Isolate* isolate = thread->isolate(); | 858 Isolate* isolate = thread->isolate(); |
874 | 859 |
875 const Class& double_class = | 860 const Class& double_class = |
876 Class::Handle(isolate->object_store()->double_class()); | 861 Class::Handle(isolate->object_store()->double_class()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 HANDLESCOPE(thread); | 913 HANDLESCOPE(thread); |
929 Profile profile(isolate); | 914 Profile profile(isolate); |
930 AllocationFilter filter(isolate->main_port(), double_class.id()); | 915 AllocationFilter filter(isolate->main_port(), double_class.id()); |
931 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 916 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
932 // We should still only have one allocation sample. | 917 // We should still only have one allocation sample. |
933 EXPECT_EQ(1, profile.sample_count()); | 918 EXPECT_EQ(1, profile.sample_count()); |
934 } | 919 } |
935 } | 920 } |
936 | 921 |
937 TEST_CASE(Profiler_ArrayAllocation) { | 922 TEST_CASE(Profiler_ArrayAllocation) { |
938 EnableProfiler(); | |
939 DisableNativeProfileScope dnps; | 923 DisableNativeProfileScope dnps; |
940 const char* kScript = | 924 const char* kScript = |
941 "List foo() => new List(4);\n" | 925 "List foo() => new List(4);\n" |
942 "List bar() => new List();\n"; | 926 "List bar() => new List();\n"; |
943 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 927 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
944 EXPECT_VALID(lib); | 928 EXPECT_VALID(lib); |
945 Library& root_library = Library::Handle(); | 929 Library& root_library = Library::Handle(); |
946 root_library ^= Api::UnwrapHandle(lib); | 930 root_library ^= Api::UnwrapHandle(lib); |
947 Isolate* isolate = thread->isolate(); | 931 Isolate* isolate = thread->isolate(); |
948 | 932 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 Profile profile(isolate); | 1009 Profile profile(isolate); |
1026 AllocationFilter filter(isolate->main_port(), array_class.id()); | 1010 AllocationFilter filter(isolate->main_port(), array_class.id()); |
1027 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1011 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1028 // We should have no allocation samples, since empty | 1012 // We should have no allocation samples, since empty |
1029 // growable lists use a shared backing. | 1013 // growable lists use a shared backing. |
1030 EXPECT_EQ(0, profile.sample_count()); | 1014 EXPECT_EQ(0, profile.sample_count()); |
1031 } | 1015 } |
1032 } | 1016 } |
1033 | 1017 |
1034 TEST_CASE(Profiler_ContextAllocation) { | 1018 TEST_CASE(Profiler_ContextAllocation) { |
1035 EnableProfiler(); | |
1036 DisableNativeProfileScope dnps; | 1019 DisableNativeProfileScope dnps; |
1037 const char* kScript = | 1020 const char* kScript = |
1038 "var msg1 = 'a';\n" | 1021 "var msg1 = 'a';\n" |
1039 "foo() {\n" | 1022 "foo() {\n" |
1040 " var msg = msg1 + msg1;\n" | 1023 " var msg = msg1 + msg1;\n" |
1041 " return (x) { return '$msg + $msg'; }(msg);\n" | 1024 " return (x) { return '$msg + $msg'; }(msg);\n" |
1042 "}\n"; | 1025 "}\n"; |
1043 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 1026 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1044 EXPECT_VALID(lib); | 1027 EXPECT_VALID(lib); |
1045 Library& root_library = Library::Handle(); | 1028 Library& root_library = Library::Handle(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 HANDLESCOPE(thread); | 1078 HANDLESCOPE(thread); |
1096 Profile profile(isolate); | 1079 Profile profile(isolate); |
1097 AllocationFilter filter(isolate->main_port(), context_class.id()); | 1080 AllocationFilter filter(isolate->main_port(), context_class.id()); |
1098 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1081 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1099 // We should still only have one allocation sample. | 1082 // We should still only have one allocation sample. |
1100 EXPECT_EQ(1, profile.sample_count()); | 1083 EXPECT_EQ(1, profile.sample_count()); |
1101 } | 1084 } |
1102 } | 1085 } |
1103 | 1086 |
1104 TEST_CASE(Profiler_ClosureAllocation) { | 1087 TEST_CASE(Profiler_ClosureAllocation) { |
1105 EnableProfiler(); | |
1106 DisableNativeProfileScope dnps; | 1088 DisableNativeProfileScope dnps; |
1107 const char* kScript = | 1089 const char* kScript = |
1108 "var msg1 = 'a';\n" | 1090 "var msg1 = 'a';\n" |
1109 "\n" | 1091 "\n" |
1110 "foo() {\n" | 1092 "foo() {\n" |
1111 " var msg = msg1 + msg1;\n" | 1093 " var msg = msg1 + msg1;\n" |
1112 " var msg2 = msg + msg;\n" | 1094 " var msg2 = msg + msg;\n" |
1113 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" | 1095 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" |
1114 "}\n" | 1096 "}\n" |
1115 "bar() {\n" | 1097 "bar() {\n" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 Profile profile(isolate); | 1149 Profile profile(isolate); |
1168 AllocationFilter filter(isolate->main_port(), closure_class.id()); | 1150 AllocationFilter filter(isolate->main_port(), closure_class.id()); |
1169 filter.set_enable_vm_ticks(true); | 1151 filter.set_enable_vm_ticks(true); |
1170 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1152 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1171 // We should still only have one allocation sample. | 1153 // We should still only have one allocation sample. |
1172 EXPECT_EQ(1, profile.sample_count()); | 1154 EXPECT_EQ(1, profile.sample_count()); |
1173 } | 1155 } |
1174 } | 1156 } |
1175 | 1157 |
1176 TEST_CASE(Profiler_TypedArrayAllocation) { | 1158 TEST_CASE(Profiler_TypedArrayAllocation) { |
1177 EnableProfiler(); | |
1178 DisableNativeProfileScope dnps; | 1159 DisableNativeProfileScope dnps; |
1179 const char* kScript = | 1160 const char* kScript = |
1180 "import 'dart:typed_data';\n" | 1161 "import 'dart:typed_data';\n" |
1181 "List foo() => new Float32List(4);\n"; | 1162 "List foo() => new Float32List(4);\n"; |
1182 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 1163 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1183 EXPECT_VALID(lib); | 1164 EXPECT_VALID(lib); |
1184 Library& root_library = Library::Handle(); | 1165 Library& root_library = Library::Handle(); |
1185 root_library ^= Api::UnwrapHandle(lib); | 1166 root_library ^= Api::UnwrapHandle(lib); |
1186 Isolate* isolate = thread->isolate(); | 1167 Isolate* isolate = thread->isolate(); |
1187 | 1168 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 HANDLESCOPE(thread); | 1233 HANDLESCOPE(thread); |
1253 Profile profile(isolate); | 1234 Profile profile(isolate); |
1254 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); | 1235 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); |
1255 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1236 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1256 // We should now have two allocation samples. | 1237 // We should now have two allocation samples. |
1257 EXPECT_EQ(2, profile.sample_count()); | 1238 EXPECT_EQ(2, profile.sample_count()); |
1258 } | 1239 } |
1259 } | 1240 } |
1260 | 1241 |
1261 TEST_CASE(Profiler_StringAllocation) { | 1242 TEST_CASE(Profiler_StringAllocation) { |
1262 EnableProfiler(); | |
1263 DisableNativeProfileScope dnps; | 1243 DisableNativeProfileScope dnps; |
1264 const char* kScript = "String foo(String a, String b) => a + b;"; | 1244 const char* kScript = "String foo(String a, String b) => a + b;"; |
1265 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 1245 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1266 EXPECT_VALID(lib); | 1246 EXPECT_VALID(lib); |
1267 Library& root_library = Library::Handle(); | 1247 Library& root_library = Library::Handle(); |
1268 root_library ^= Api::UnwrapHandle(lib); | 1248 root_library ^= Api::UnwrapHandle(lib); |
1269 Isolate* isolate = thread->isolate(); | 1249 Isolate* isolate = thread->isolate(); |
1270 | 1250 |
1271 const Class& one_byte_string_class = | 1251 const Class& one_byte_string_class = |
1272 Class::Handle(isolate->object_store()->one_byte_string_class()); | 1252 Class::Handle(isolate->object_store()->one_byte_string_class()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 HANDLESCOPE(thread); | 1318 HANDLESCOPE(thread); |
1339 Profile profile(isolate); | 1319 Profile profile(isolate); |
1340 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); | 1320 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
1341 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1321 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1342 // We should now have two allocation samples. | 1322 // We should now have two allocation samples. |
1343 EXPECT_EQ(2, profile.sample_count()); | 1323 EXPECT_EQ(2, profile.sample_count()); |
1344 } | 1324 } |
1345 } | 1325 } |
1346 | 1326 |
1347 TEST_CASE(Profiler_StringInterpolation) { | 1327 TEST_CASE(Profiler_StringInterpolation) { |
1348 EnableProfiler(); | |
1349 DisableNativeProfileScope dnps; | 1328 DisableNativeProfileScope dnps; |
1350 DisableBackgroundCompilationScope dbcs; | 1329 DisableBackgroundCompilationScope dbcs; |
1351 const char* kScript = "String foo(String a, String b) => '$a | $b';"; | 1330 const char* kScript = "String foo(String a, String b) => '$a | $b';"; |
1352 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 1331 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1353 EXPECT_VALID(lib); | 1332 EXPECT_VALID(lib); |
1354 Library& root_library = Library::Handle(); | 1333 Library& root_library = Library::Handle(); |
1355 root_library ^= Api::UnwrapHandle(lib); | 1334 root_library ^= Api::UnwrapHandle(lib); |
1356 Isolate* isolate = thread->isolate(); | 1335 Isolate* isolate = thread->isolate(); |
1357 | 1336 |
1358 const Class& one_byte_string_class = | 1337 const Class& one_byte_string_class = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 HANDLESCOPE(thread); | 1406 HANDLESCOPE(thread); |
1428 Profile profile(isolate); | 1407 Profile profile(isolate); |
1429 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); | 1408 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
1430 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); | 1409 profile.Build(thread, &filter, Profiler::sample_buffer(), Profile::kNoTags); |
1431 // We should now have two allocation samples. | 1410 // We should now have two allocation samples. |
1432 EXPECT_EQ(2, profile.sample_count()); | 1411 EXPECT_EQ(2, profile.sample_count()); |
1433 } | 1412 } |
1434 } | 1413 } |
1435 | 1414 |
1436 TEST_CASE(Profiler_FunctionInline) { | 1415 TEST_CASE(Profiler_FunctionInline) { |
1437 EnableProfiler(); | |
1438 DisableNativeProfileScope dnps; | 1416 DisableNativeProfileScope dnps; |
1439 DisableBackgroundCompilationScope dbcs; | 1417 DisableBackgroundCompilationScope dbcs; |
1440 | 1418 |
1441 const char* kScript = | 1419 const char* kScript = |
1442 "class A {\n" | 1420 "class A {\n" |
1443 " var a;\n" | 1421 " var a;\n" |
1444 " var b;\n" | 1422 " var b;\n" |
1445 "}\n" | 1423 "}\n" |
1446 "class B {\n" | 1424 "class B {\n" |
1447 " static choo(bool alloc) {\n" | 1425 " static choo(bool alloc) {\n" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 EXPECT(!walker.Down()); | 1695 EXPECT(!walker.Down()); |
1718 } | 1696 } |
1719 } | 1697 } |
1720 | 1698 |
1721 TEST_CASE(Profiler_InliningIntervalBoundry) { | 1699 TEST_CASE(Profiler_InliningIntervalBoundry) { |
1722 // The PC of frames below the top frame is a call's return address, | 1700 // The PC of frames below the top frame is a call's return address, |
1723 // which can belong to a different inlining interval than the call. | 1701 // which can belong to a different inlining interval than the call. |
1724 // This test checks the profiler service takes this into account; see | 1702 // This test checks the profiler service takes this into account; see |
1725 // ProfileBuilder::ProcessFrame. | 1703 // ProfileBuilder::ProcessFrame. |
1726 | 1704 |
1727 EnableProfiler(); | |
1728 DisableNativeProfileScope dnps; | 1705 DisableNativeProfileScope dnps; |
1729 DisableBackgroundCompilationScope dbcs; | 1706 DisableBackgroundCompilationScope dbcs; |
1730 const char* kScript = | 1707 const char* kScript = |
1731 "class A {\n" | 1708 "class A {\n" |
1732 "}\n" | 1709 "}\n" |
1733 "bool alloc = false;" | 1710 "bool alloc = false;" |
1734 "maybeAlloc() {\n" | 1711 "maybeAlloc() {\n" |
1735 " try {\n" | 1712 " try {\n" |
1736 " if (alloc) new A();\n" | 1713 " if (alloc) new A();\n" |
1737 " } catch (e) {\n" | 1714 " } catch (e) {\n" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 EXPECT_STREQ("maybeAlloc", walker.CurrentName()); | 1826 EXPECT_STREQ("maybeAlloc", walker.CurrentName()); |
1850 EXPECT(walker.Down()); | 1827 EXPECT(walker.Down()); |
1851 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); | 1828 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); |
1852 EXPECT(walker.Down()); | 1829 EXPECT(walker.Down()); |
1853 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1830 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
1854 EXPECT(!walker.Down()); | 1831 EXPECT(!walker.Down()); |
1855 } | 1832 } |
1856 } | 1833 } |
1857 | 1834 |
1858 TEST_CASE(Profiler_ChainedSamples) { | 1835 TEST_CASE(Profiler_ChainedSamples) { |
1859 EnableProfiler(); | |
1860 MaxProfileDepthScope mpds(32); | 1836 MaxProfileDepthScope mpds(32); |
1861 DisableNativeProfileScope dnps; | 1837 DisableNativeProfileScope dnps; |
1862 | 1838 |
1863 // Each sample holds 8 stack frames. | 1839 // Each sample holds 8 stack frames. |
1864 // This chain is 20 stack frames deep. | 1840 // This chain is 20 stack frames deep. |
1865 const char* kScript = | 1841 const char* kScript = |
1866 "class A {\n" | 1842 "class A {\n" |
1867 " var a;\n" | 1843 " var a;\n" |
1868 " var b;\n" | 1844 " var b;\n" |
1869 "}\n" | 1845 "}\n" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 EXPECT_STREQ("init", walker.CurrentName()); | 1938 EXPECT_STREQ("init", walker.CurrentName()); |
1963 EXPECT(walker.Down()); | 1939 EXPECT(walker.Down()); |
1964 EXPECT_STREQ("go", walker.CurrentName()); | 1940 EXPECT_STREQ("go", walker.CurrentName()); |
1965 EXPECT(walker.Down()); | 1941 EXPECT(walker.Down()); |
1966 EXPECT_STREQ("main", walker.CurrentName()); | 1942 EXPECT_STREQ("main", walker.CurrentName()); |
1967 EXPECT(!walker.Down()); | 1943 EXPECT(!walker.Down()); |
1968 } | 1944 } |
1969 } | 1945 } |
1970 | 1946 |
1971 TEST_CASE(Profiler_BasicSourcePosition) { | 1947 TEST_CASE(Profiler_BasicSourcePosition) { |
1972 EnableProfiler(); | |
1973 DisableNativeProfileScope dnps; | 1948 DisableNativeProfileScope dnps; |
1974 DisableBackgroundCompilationScope dbcs; | 1949 DisableBackgroundCompilationScope dbcs; |
1975 const char* kScript = | 1950 const char* kScript = |
1976 "const AlwaysInline = 'AlwaysInline';\n" | 1951 "const AlwaysInline = 'AlwaysInline';\n" |
1977 "const NeverInline = 'NeverInline';\n" | 1952 "const NeverInline = 'NeverInline';\n" |
1978 "class A {\n" | 1953 "class A {\n" |
1979 " var a;\n" | 1954 " var a;\n" |
1980 " var b;\n" | 1955 " var b;\n" |
1981 " @NeverInline A() { }\n" | 1956 " @NeverInline A() { }\n" |
1982 "}\n" | 1957 "}\n" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 EXPECT_STREQ("main", walker.CurrentName()); | 2012 EXPECT_STREQ("main", walker.CurrentName()); |
2038 EXPECT_EQ(1, walker.CurrentNodeTickCount()); | 2013 EXPECT_EQ(1, walker.CurrentNodeTickCount()); |
2039 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); | 2014 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); |
2040 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | 2015 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); |
2041 EXPECT_STREQ("boo", walker.CurrentToken()); | 2016 EXPECT_STREQ("boo", walker.CurrentToken()); |
2042 EXPECT(!walker.Down()); | 2017 EXPECT(!walker.Down()); |
2043 } | 2018 } |
2044 } | 2019 } |
2045 | 2020 |
2046 TEST_CASE(Profiler_BasicSourcePositionOptimized) { | 2021 TEST_CASE(Profiler_BasicSourcePositionOptimized) { |
2047 EnableProfiler(); | |
2048 DisableNativeProfileScope dnps; | 2022 DisableNativeProfileScope dnps; |
2049 DisableBackgroundCompilationScope dbcs; | 2023 DisableBackgroundCompilationScope dbcs; |
2050 // We use the AlwaysInline and NeverInline annotations in this test. | 2024 // We use the AlwaysInline and NeverInline annotations in this test. |
2051 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); | 2025 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); |
2052 // Optimize quickly. | 2026 // Optimize quickly. |
2053 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); | 2027 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); |
2054 const char* kScript = | 2028 const char* kScript = |
2055 "const AlwaysInline = 'AlwaysInline';\n" | 2029 "const AlwaysInline = 'AlwaysInline';\n" |
2056 "const NeverInline = 'NeverInline';\n" | 2030 "const NeverInline = 'NeverInline';\n" |
2057 "class A {\n" | 2031 "class A {\n" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2131 EXPECT_STREQ("main", walker.CurrentName()); | 2105 EXPECT_STREQ("main", walker.CurrentName()); |
2132 EXPECT_EQ(1, walker.CurrentNodeTickCount()); | 2106 EXPECT_EQ(1, walker.CurrentNodeTickCount()); |
2133 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); | 2107 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); |
2134 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | 2108 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); |
2135 EXPECT_STREQ("boo", walker.CurrentToken()); | 2109 EXPECT_STREQ("boo", walker.CurrentToken()); |
2136 EXPECT(!walker.Down()); | 2110 EXPECT(!walker.Down()); |
2137 } | 2111 } |
2138 } | 2112 } |
2139 | 2113 |
2140 TEST_CASE(Profiler_SourcePosition) { | 2114 TEST_CASE(Profiler_SourcePosition) { |
2141 EnableProfiler(); | |
2142 DisableNativeProfileScope dnps; | 2115 DisableNativeProfileScope dnps; |
2143 DisableBackgroundCompilationScope dbcs; | 2116 DisableBackgroundCompilationScope dbcs; |
2144 const char* kScript = | 2117 const char* kScript = |
2145 "const AlwaysInline = 'AlwaysInline';\n" | 2118 "const AlwaysInline = 'AlwaysInline';\n" |
2146 "const NeverInline = 'NeverInline';\n" | 2119 "const NeverInline = 'NeverInline';\n" |
2147 "class A {\n" | 2120 "class A {\n" |
2148 " var a;\n" | 2121 " var a;\n" |
2149 " var b;\n" | 2122 " var b;\n" |
2150 " @NeverInline A() { }\n" | 2123 " @NeverInline A() { }\n" |
2151 "}\n" | 2124 "}\n" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 EXPECT_STREQ("main", walker.CurrentName()); | 2209 EXPECT_STREQ("main", walker.CurrentName()); |
2237 EXPECT_EQ(1, walker.CurrentNodeTickCount()); | 2210 EXPECT_EQ(1, walker.CurrentNodeTickCount()); |
2238 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); | 2211 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); |
2239 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | 2212 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); |
2240 EXPECT_STREQ("bacon", walker.CurrentToken()); | 2213 EXPECT_STREQ("bacon", walker.CurrentToken()); |
2241 EXPECT(!walker.Down()); | 2214 EXPECT(!walker.Down()); |
2242 } | 2215 } |
2243 } | 2216 } |
2244 | 2217 |
2245 TEST_CASE(Profiler_SourcePositionOptimized) { | 2218 TEST_CASE(Profiler_SourcePositionOptimized) { |
2246 EnableProfiler(); | |
2247 DisableNativeProfileScope dnps; | 2219 DisableNativeProfileScope dnps; |
2248 DisableBackgroundCompilationScope dbcs; | 2220 DisableBackgroundCompilationScope dbcs; |
2249 // We use the AlwaysInline and NeverInline annotations in this test. | 2221 // We use the AlwaysInline and NeverInline annotations in this test. |
2250 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); | 2222 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); |
2251 // Optimize quickly. | 2223 // Optimize quickly. |
2252 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); | 2224 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); |
2253 | 2225 |
2254 const char* kScript = | 2226 const char* kScript = |
2255 "const AlwaysInline = 'AlwaysInline';\n" | 2227 "const AlwaysInline = 'AlwaysInline';\n" |
2256 "const NeverInline = 'NeverInline';\n" | 2228 "const NeverInline = 'NeverInline';\n" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 EXPECT_STREQ("main", walker.CurrentName()); | 2333 EXPECT_STREQ("main", walker.CurrentName()); |
2362 EXPECT_EQ(1, walker.CurrentNodeTickCount()); | 2334 EXPECT_EQ(1, walker.CurrentNodeTickCount()); |
2363 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); | 2335 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); |
2364 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | 2336 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); |
2365 EXPECT_STREQ("bacon", walker.CurrentToken()); | 2337 EXPECT_STREQ("bacon", walker.CurrentToken()); |
2366 EXPECT(!walker.Down()); | 2338 EXPECT(!walker.Down()); |
2367 } | 2339 } |
2368 } | 2340 } |
2369 | 2341 |
2370 TEST_CASE(Profiler_BinaryOperatorSourcePosition) { | 2342 TEST_CASE(Profiler_BinaryOperatorSourcePosition) { |
2371 EnableProfiler(); | |
2372 DisableNativeProfileScope dnps; | 2343 DisableNativeProfileScope dnps; |
2373 DisableBackgroundCompilationScope dbcs; | 2344 DisableBackgroundCompilationScope dbcs; |
2374 const char* kScript = | 2345 const char* kScript = |
2375 "const AlwaysInline = 'AlwaysInline';\n" | 2346 "const AlwaysInline = 'AlwaysInline';\n" |
2376 "const NeverInline = 'NeverInline';\n" | 2347 "const NeverInline = 'NeverInline';\n" |
2377 "class A {\n" | 2348 "class A {\n" |
2378 " var a;\n" | 2349 " var a;\n" |
2379 " var b;\n" | 2350 " var b;\n" |
2380 " @NeverInline A() { }\n" | 2351 " @NeverInline A() { }\n" |
2381 "}\n" | 2352 "}\n" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 EXPECT_STREQ("main", walker.CurrentName()); | 2446 EXPECT_STREQ("main", walker.CurrentName()); |
2476 EXPECT_EQ(1, walker.CurrentNodeTickCount()); | 2447 EXPECT_EQ(1, walker.CurrentNodeTickCount()); |
2477 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); | 2448 EXPECT_EQ(1, walker.CurrentInclusiveTicks()); |
2478 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | 2449 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); |
2479 EXPECT_STREQ("bacon", walker.CurrentToken()); | 2450 EXPECT_STREQ("bacon", walker.CurrentToken()); |
2480 EXPECT(!walker.Down()); | 2451 EXPECT(!walker.Down()); |
2481 } | 2452 } |
2482 } | 2453 } |
2483 | 2454 |
2484 TEST_CASE(Profiler_BinaryOperatorSourcePositionOptimized) { | 2455 TEST_CASE(Profiler_BinaryOperatorSourcePositionOptimized) { |
2485 EnableProfiler(); | |
2486 DisableNativeProfileScope dnps; | 2456 DisableNativeProfileScope dnps; |
2487 DisableBackgroundCompilationScope dbcs; | 2457 DisableBackgroundCompilationScope dbcs; |
2488 // We use the AlwaysInline and NeverInline annotations in this test. | 2458 // We use the AlwaysInline and NeverInline annotations in this test. |
2489 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); | 2459 SetFlagScope<bool> sfs(&FLAG_enable_inlining_annotations, true); |
2490 // Optimize quickly. | 2460 // Optimize quickly. |
2491 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); | 2461 SetFlagScope<int> sfs2(&FLAG_optimization_counter_threshold, 5); |
2492 | 2462 |
2493 const char* kScript = | 2463 const char* kScript = |
2494 "const AlwaysInline = 'AlwaysInline';\n" | 2464 "const AlwaysInline = 'AlwaysInline';\n" |
2495 "const NeverInline = 'NeverInline';\n" | 2465 "const NeverInline = 'NeverInline';\n" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2648 &token_positions); | 2618 &token_positions); |
2649 if (token_positions[0] == tp) { | 2619 if (token_positions[0] == tp) { |
2650 return code.PayloadStart() + pc_offset; | 2620 return code.PayloadStart() + pc_offset; |
2651 } | 2621 } |
2652 } | 2622 } |
2653 | 2623 |
2654 return 0; | 2624 return 0; |
2655 } | 2625 } |
2656 | 2626 |
2657 TEST_CASE(Profiler_GetSourceReport) { | 2627 TEST_CASE(Profiler_GetSourceReport) { |
2658 EnableProfiler(); | |
2659 const char* kScript = | 2628 const char* kScript = |
2660 "doWork(i) => i * i;\n" | 2629 "doWork(i) => i * i;\n" |
2661 "main() {\n" | 2630 "main() {\n" |
2662 " var sum = 0;\n" | 2631 " var sum = 0;\n" |
2663 " for (var i = 0; i < 100; i++) {\n" | 2632 " for (var i = 0; i < 100; i++) {\n" |
2664 " sum += doWork(i);\n" | 2633 " sum += doWork(i);\n" |
2665 " }\n" | 2634 " }\n" |
2666 " return sum;\n" | 2635 " return sum;\n" |
2667 "}\n"; | 2636 "}\n"; |
2668 | 2637 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2889 EXPECT_EQ(table->FindCodeForPC(45), code1); // Merged right. | 2858 EXPECT_EQ(table->FindCodeForPC(45), code1); // Merged right. |
2890 EXPECT_EQ(table->FindCodeForPC(54), code1); // Merged right. | 2859 EXPECT_EQ(table->FindCodeForPC(54), code1); // Merged right. |
2891 EXPECT_EQ(table->FindCodeForPC(20), code2); // Merged left. | 2860 EXPECT_EQ(table->FindCodeForPC(20), code2); // Merged left. |
2892 EXPECT_EQ(table->FindCodeForPC(49), code1); // Truncated. | 2861 EXPECT_EQ(table->FindCodeForPC(49), code1); // Truncated. |
2893 EXPECT_EQ(table->FindCodeForPC(50), code1); | 2862 EXPECT_EQ(table->FindCodeForPC(50), code1); |
2894 } | 2863 } |
2895 | 2864 |
2896 #endif // !PRODUCT | 2865 #endif // !PRODUCT |
2897 | 2866 |
2898 } // namespace dart | 2867 } // namespace dart |
OLD | NEW |