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

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

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

Powered by Google App Engine
This is Rietveld 408576698