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