| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 ~MaxProfileDepthScope() { Profiler::SetSampleDepth(FLAG_max_profile_depth_); } | 62 ~MaxProfileDepthScope() { Profiler::SetSampleDepth(FLAG_max_profile_depth_); } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 const intptr_t FLAG_max_profile_depth_; | 65 const intptr_t FLAG_max_profile_depth_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 | 68 |
| 69 class ProfileSampleBufferTestHelper { | 69 class ProfileSampleBufferTestHelper { |
| 70 public: | 70 public: |
| 71 static intptr_t IterateCount(const Isolate* isolate, | 71 static intptr_t IterateCount(const Dart_Port port, |
| 72 const SampleBuffer& sample_buffer) { | 72 const SampleBuffer& sample_buffer) { |
| 73 intptr_t c = 0; | 73 intptr_t c = 0; |
| 74 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { | 74 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { |
| 75 Sample* sample = sample_buffer.At(i); | 75 Sample* sample = sample_buffer.At(i); |
| 76 if (sample->isolate() != isolate) { | 76 if (sample->port() != port) { |
| 77 continue; | 77 continue; |
| 78 } | 78 } |
| 79 c++; | 79 c++; |
| 80 } | 80 } |
| 81 return c; | 81 return c; |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 |
| 85 static intptr_t IterateSumPC(const Isolate* isolate, | 85 static intptr_t IterateSumPC(const Dart_Port port, |
| 86 const SampleBuffer& sample_buffer) { | 86 const SampleBuffer& sample_buffer) { |
| 87 intptr_t c = 0; | 87 intptr_t c = 0; |
| 88 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { | 88 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { |
| 89 Sample* sample = sample_buffer.At(i); | 89 Sample* sample = sample_buffer.At(i); |
| 90 if (sample->isolate() != isolate) { | 90 if (sample->port() != port) { |
| 91 continue; | 91 continue; |
| 92 } | 92 } |
| 93 c += sample->At(0); | 93 c += sample->At(0); |
| 94 } | 94 } |
| 95 return c; | 95 return c; |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 | 99 |
| 100 TEST_CASE(Profiler_SampleBufferWrapTest) { | 100 TEST_CASE(Profiler_SampleBufferWrapTest) { |
| 101 SampleBuffer* sample_buffer = new SampleBuffer(3); | 101 SampleBuffer* sample_buffer = new SampleBuffer(3); |
| 102 Isolate* i = reinterpret_cast<Isolate*>(0x1); | 102 Dart_Port i = 123; |
| 103 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 103 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
| 104 Sample* s; | 104 Sample* s; |
| 105 s = sample_buffer->ReserveSample(); | 105 s = sample_buffer->ReserveSample(); |
| 106 s->Init(i, 0, 0); | 106 s->Init(i, 0, 0); |
| 107 s->SetAt(0, 2); | 107 s->SetAt(0, 2); |
| 108 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 108 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
| 109 s = sample_buffer->ReserveSample(); | 109 s = sample_buffer->ReserveSample(); |
| 110 s->Init(i, 0, 0); | 110 s->Init(i, 0, 0); |
| 111 s->SetAt(0, 4); | 111 s->SetAt(0, 4); |
| 112 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 112 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
| 113 s = sample_buffer->ReserveSample(); | 113 s = sample_buffer->ReserveSample(); |
| 114 s->Init(i, 0, 0); | 114 s->Init(i, 0, 0); |
| 115 s->SetAt(0, 6); | 115 s->SetAt(0, 6); |
| 116 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 116 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
| 117 s = sample_buffer->ReserveSample(); | 117 s = sample_buffer->ReserveSample(); |
| 118 s->Init(i, 0, 0); | 118 s->Init(i, 0, 0); |
| 119 s->SetAt(0, 8); | 119 s->SetAt(0, 8); |
| 120 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 120 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
| 121 delete sample_buffer; | 121 delete sample_buffer; |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 TEST_CASE(Profiler_SampleBufferIterateTest) { | 125 TEST_CASE(Profiler_SampleBufferIterateTest) { |
| 126 SampleBuffer* sample_buffer = new SampleBuffer(3); | 126 SampleBuffer* sample_buffer = new SampleBuffer(3); |
| 127 Isolate* i = reinterpret_cast<Isolate*>(0x1); | 127 Dart_Port i = 123; |
| 128 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 128 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
| 129 Sample* s; | 129 Sample* s; |
| 130 s = sample_buffer->ReserveSample(); | 130 s = sample_buffer->ReserveSample(); |
| 131 s->Init(i, 0, 0); | 131 s->Init(i, 0, 0); |
| 132 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 132 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
| 133 s = sample_buffer->ReserveSample(); | 133 s = sample_buffer->ReserveSample(); |
| 134 s->Init(i, 0, 0); | 134 s->Init(i, 0, 0); |
| 135 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 135 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
| 136 s = sample_buffer->ReserveSample(); | 136 s = sample_buffer->ReserveSample(); |
| 137 s->Init(i, 0, 0); | 137 s->Init(i, 0, 0); |
| 138 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 138 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
| 139 s = sample_buffer->ReserveSample(); | 139 s = sample_buffer->ReserveSample(); |
| 140 s->Init(i, 0, 0); | 140 s->Init(i, 0, 0); |
| 141 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 141 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
| 142 delete sample_buffer; | 142 delete sample_buffer; |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 TEST_CASE(Profiler_AllocationSampleTest) { | 146 TEST_CASE(Profiler_AllocationSampleTest) { |
| 147 Isolate* isolate = Isolate::Current(); | 147 Isolate* isolate = Isolate::Current(); |
| 148 SampleBuffer* sample_buffer = new SampleBuffer(3); | 148 SampleBuffer* sample_buffer = new SampleBuffer(3); |
| 149 Sample* sample = sample_buffer->ReserveSample(); | 149 Sample* sample = sample_buffer->ReserveSample(); |
| 150 sample->Init(isolate, 0, 0); | 150 sample->Init(isolate->main_port(), 0, 0); |
| 151 sample->set_metadata(99); | 151 sample->set_metadata(99); |
| 152 sample->set_is_allocation_sample(true); | 152 sample->set_is_allocation_sample(true); |
| 153 EXPECT_EQ(99, sample->allocation_cid()); | 153 EXPECT_EQ(99, sample->allocation_cid()); |
| 154 delete sample_buffer; | 154 delete sample_buffer; |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 static RawClass* GetClass(const Library& lib, const char* name) { | 158 static RawClass* GetClass(const Library& lib, const char* name) { |
| 159 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate( | 159 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate( |
| 160 String::Handle(Symbols::New(Thread::Current(), name)))); | 160 String::Handle(Symbols::New(Thread::Current(), name)))); |
| 161 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 161 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 162 return cls.raw(); | 162 return cls.raw(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 static RawFunction* GetFunction(const Library& lib, const char* name) { | 166 static RawFunction* GetFunction(const Library& lib, const char* name) { |
| 167 const Function& func = Function::Handle(lib.LookupFunctionAllowPrivate( | 167 const Function& func = Function::Handle(lib.LookupFunctionAllowPrivate( |
| 168 String::Handle(Symbols::New(Thread::Current(), name)))); | 168 String::Handle(Symbols::New(Thread::Current(), name)))); |
| 169 EXPECT(!func.IsNull()); // No ambiguity error expected. | 169 EXPECT(!func.IsNull()); // No ambiguity error expected. |
| 170 return func.raw(); | 170 return func.raw(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 class AllocationFilter : public SampleFilter { | 174 class AllocationFilter : public SampleFilter { |
| 175 public: | 175 public: |
| 176 AllocationFilter(Isolate* isolate, | 176 AllocationFilter(Dart_Port port, |
| 177 intptr_t cid, | 177 intptr_t cid, |
| 178 int64_t time_origin_micros = -1, | 178 int64_t time_origin_micros = -1, |
| 179 int64_t time_extent_micros = -1) | 179 int64_t time_extent_micros = -1) |
| 180 : SampleFilter(isolate, | 180 : SampleFilter(port, |
| 181 Thread::kMutatorTask, | 181 Thread::kMutatorTask, |
| 182 time_origin_micros, | 182 time_origin_micros, |
| 183 time_extent_micros), | 183 time_extent_micros), |
| 184 cid_(cid), | 184 cid_(cid), |
| 185 enable_vm_ticks_(false) {} | 185 enable_vm_ticks_(false) {} |
| 186 | 186 |
| 187 bool FilterSample(Sample* sample) { | 187 bool FilterSample(Sample* sample) { |
| 188 if (!enable_vm_ticks_ && (sample->vm_tag() == VMTag::kVMTagId)) { | 188 if (!enable_vm_ticks_ && (sample->vm_tag() == VMTag::kVMTagId)) { |
| 189 // We don't want to see embedder ticks in the test. | 189 // We don't want to see embedder ticks in the test. |
| 190 return false; | 190 return false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 const int64_t after_allocations_micros = Dart_TimelineGetMicros(); | 232 const int64_t after_allocations_micros = Dart_TimelineGetMicros(); |
| 233 const int64_t allocation_extent_micros = | 233 const int64_t allocation_extent_micros = |
| 234 after_allocations_micros - before_allocations_micros; | 234 after_allocations_micros - before_allocations_micros; |
| 235 { | 235 { |
| 236 Thread* thread = Thread::Current(); | 236 Thread* thread = Thread::Current(); |
| 237 Isolate* isolate = thread->isolate(); | 237 Isolate* isolate = thread->isolate(); |
| 238 StackZone zone(thread); | 238 StackZone zone(thread); |
| 239 HANDLESCOPE(thread); | 239 HANDLESCOPE(thread); |
| 240 Profile profile(isolate); | 240 Profile profile(isolate); |
| 241 // Filter for the class in the time range. | 241 // Filter for the class in the time range. |
| 242 AllocationFilter filter(isolate, class_a.id(), before_allocations_micros, | 242 AllocationFilter filter(isolate->main_port(), class_a.id(), |
| 243 before_allocations_micros, |
| 243 allocation_extent_micros); | 244 allocation_extent_micros); |
| 244 profile.Build(thread, &filter, Profile::kNoTags); | 245 profile.Build(thread, &filter, Profile::kNoTags); |
| 245 // We should have 1 allocation sample. | 246 // We should have 1 allocation sample. |
| 246 EXPECT_EQ(1, profile.sample_count()); | 247 EXPECT_EQ(1, profile.sample_count()); |
| 247 ProfileTrieWalker walker(&profile); | 248 ProfileTrieWalker walker(&profile); |
| 248 | 249 |
| 249 // Exclusive code: B.boo -> main. | 250 // Exclusive code: B.boo -> main. |
| 250 walker.Reset(Profile::kExclusiveCode); | 251 walker.Reset(Profile::kExclusiveCode); |
| 251 // Move down from the root. | 252 // Move down from the root. |
| 252 EXPECT(walker.Down()); | 253 EXPECT(walker.Down()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 EXPECT(!walker.Down()); | 300 EXPECT(!walker.Down()); |
| 300 } | 301 } |
| 301 | 302 |
| 302 // Query with a time filter where no allocations occurred. | 303 // Query with a time filter where no allocations occurred. |
| 303 { | 304 { |
| 304 Thread* thread = Thread::Current(); | 305 Thread* thread = Thread::Current(); |
| 305 Isolate* isolate = thread->isolate(); | 306 Isolate* isolate = thread->isolate(); |
| 306 StackZone zone(thread); | 307 StackZone zone(thread); |
| 307 HANDLESCOPE(thread); | 308 HANDLESCOPE(thread); |
| 308 Profile profile(isolate); | 309 Profile profile(isolate); |
| 309 AllocationFilter filter(isolate, class_a.id(), Dart_TimelineGetMicros(), | 310 AllocationFilter filter(isolate->main_port(), class_a.id(), |
| 310 16000); | 311 Dart_TimelineGetMicros(), 16000); |
| 311 profile.Build(thread, &filter, Profile::kNoTags); | 312 profile.Build(thread, &filter, Profile::kNoTags); |
| 312 // We should have no allocation samples because none occured within | 313 // We should have no allocation samples because none occured within |
| 313 // the specified time range. | 314 // the specified time range. |
| 314 EXPECT_EQ(0, profile.sample_count()); | 315 EXPECT_EQ(0, profile.sample_count()); |
| 315 } | 316 } |
| 316 } | 317 } |
| 317 | 318 |
| 318 | 319 |
| 319 TEST_CASE(Profiler_ToggleRecordAllocation) { | 320 TEST_CASE(Profiler_ToggleRecordAllocation) { |
| 320 DisableNativeProfileScope dnps; | 321 DisableNativeProfileScope dnps; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 343 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 344 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 344 EXPECT_VALID(result); | 345 EXPECT_VALID(result); |
| 345 | 346 |
| 346 | 347 |
| 347 { | 348 { |
| 348 Thread* thread = Thread::Current(); | 349 Thread* thread = Thread::Current(); |
| 349 Isolate* isolate = thread->isolate(); | 350 Isolate* isolate = thread->isolate(); |
| 350 StackZone zone(thread); | 351 StackZone zone(thread); |
| 351 HANDLESCOPE(thread); | 352 HANDLESCOPE(thread); |
| 352 Profile profile(isolate); | 353 Profile profile(isolate); |
| 353 AllocationFilter filter(isolate, class_a.id()); | 354 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 354 profile.Build(thread, &filter, Profile::kNoTags); | 355 profile.Build(thread, &filter, Profile::kNoTags); |
| 355 // We should have no allocation samples. | 356 // We should have no allocation samples. |
| 356 EXPECT_EQ(0, profile.sample_count()); | 357 EXPECT_EQ(0, profile.sample_count()); |
| 357 } | 358 } |
| 358 | 359 |
| 359 // Turn on allocation tracing for A. | 360 // Turn on allocation tracing for A. |
| 360 class_a.SetTraceAllocation(true); | 361 class_a.SetTraceAllocation(true); |
| 361 | 362 |
| 362 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 363 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 363 EXPECT_VALID(result); | 364 EXPECT_VALID(result); |
| 364 | 365 |
| 365 { | 366 { |
| 366 Thread* thread = Thread::Current(); | 367 Thread* thread = Thread::Current(); |
| 367 Isolate* isolate = thread->isolate(); | 368 Isolate* isolate = thread->isolate(); |
| 368 StackZone zone(thread); | 369 StackZone zone(thread); |
| 369 HANDLESCOPE(thread); | 370 HANDLESCOPE(thread); |
| 370 Profile profile(isolate); | 371 Profile profile(isolate); |
| 371 AllocationFilter filter(isolate, class_a.id()); | 372 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 372 profile.Build(thread, &filter, Profile::kNoTags); | 373 profile.Build(thread, &filter, Profile::kNoTags); |
| 373 // We should have one allocation sample. | 374 // We should have one allocation sample. |
| 374 EXPECT_EQ(1, profile.sample_count()); | 375 EXPECT_EQ(1, profile.sample_count()); |
| 375 ProfileTrieWalker walker(&profile); | 376 ProfileTrieWalker walker(&profile); |
| 376 | 377 |
| 377 // Exclusive code: B.boo -> main. | 378 // Exclusive code: B.boo -> main. |
| 378 walker.Reset(Profile::kExclusiveCode); | 379 walker.Reset(Profile::kExclusiveCode); |
| 379 // Move down from the root. | 380 // Move down from the root. |
| 380 EXPECT(walker.Down()); | 381 EXPECT(walker.Down()); |
| 381 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 382 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 433 |
| 433 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 434 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 434 EXPECT_VALID(result); | 435 EXPECT_VALID(result); |
| 435 | 436 |
| 436 { | 437 { |
| 437 Thread* thread = Thread::Current(); | 438 Thread* thread = Thread::Current(); |
| 438 Isolate* isolate = thread->isolate(); | 439 Isolate* isolate = thread->isolate(); |
| 439 StackZone zone(thread); | 440 StackZone zone(thread); |
| 440 HANDLESCOPE(thread); | 441 HANDLESCOPE(thread); |
| 441 Profile profile(isolate); | 442 Profile profile(isolate); |
| 442 AllocationFilter filter(isolate, class_a.id()); | 443 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 443 profile.Build(thread, &filter, Profile::kNoTags); | 444 profile.Build(thread, &filter, Profile::kNoTags); |
| 444 // We should still only have one allocation sample. | 445 // We should still only have one allocation sample. |
| 445 EXPECT_EQ(1, profile.sample_count()); | 446 EXPECT_EQ(1, profile.sample_count()); |
| 446 } | 447 } |
| 447 } | 448 } |
| 448 | 449 |
| 449 | 450 |
| 450 TEST_CASE(Profiler_CodeTicks) { | 451 TEST_CASE(Profiler_CodeTicks) { |
| 451 DisableNativeProfileScope dnps; | 452 DisableNativeProfileScope dnps; |
| 452 const char* kScript = | 453 const char* kScript = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 473 | 474 |
| 474 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 475 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 475 EXPECT_VALID(result); | 476 EXPECT_VALID(result); |
| 476 | 477 |
| 477 { | 478 { |
| 478 Thread* thread = Thread::Current(); | 479 Thread* thread = Thread::Current(); |
| 479 Isolate* isolate = thread->isolate(); | 480 Isolate* isolate = thread->isolate(); |
| 480 StackZone zone(thread); | 481 StackZone zone(thread); |
| 481 HANDLESCOPE(thread); | 482 HANDLESCOPE(thread); |
| 482 Profile profile(isolate); | 483 Profile profile(isolate); |
| 483 AllocationFilter filter(isolate, class_a.id()); | 484 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 484 profile.Build(thread, &filter, Profile::kNoTags); | 485 profile.Build(thread, &filter, Profile::kNoTags); |
| 485 // We should have no allocation samples. | 486 // We should have no allocation samples. |
| 486 EXPECT_EQ(0, profile.sample_count()); | 487 EXPECT_EQ(0, profile.sample_count()); |
| 487 } | 488 } |
| 488 | 489 |
| 489 // Turn on allocation tracing for A. | 490 // Turn on allocation tracing for A. |
| 490 class_a.SetTraceAllocation(true); | 491 class_a.SetTraceAllocation(true); |
| 491 | 492 |
| 492 // Allocate three times. | 493 // Allocate three times. |
| 493 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 494 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 494 EXPECT_VALID(result); | 495 EXPECT_VALID(result); |
| 495 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 496 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 496 EXPECT_VALID(result); | 497 EXPECT_VALID(result); |
| 497 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 498 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 498 EXPECT_VALID(result); | 499 EXPECT_VALID(result); |
| 499 | 500 |
| 500 { | 501 { |
| 501 Thread* thread = Thread::Current(); | 502 Thread* thread = Thread::Current(); |
| 502 Isolate* isolate = thread->isolate(); | 503 Isolate* isolate = thread->isolate(); |
| 503 StackZone zone(thread); | 504 StackZone zone(thread); |
| 504 HANDLESCOPE(thread); | 505 HANDLESCOPE(thread); |
| 505 Profile profile(isolate); | 506 Profile profile(isolate); |
| 506 AllocationFilter filter(isolate, class_a.id()); | 507 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 507 profile.Build(thread, &filter, Profile::kNoTags); | 508 profile.Build(thread, &filter, Profile::kNoTags); |
| 508 // We should have three allocation samples. | 509 // We should have three allocation samples. |
| 509 EXPECT_EQ(3, profile.sample_count()); | 510 EXPECT_EQ(3, profile.sample_count()); |
| 510 ProfileTrieWalker walker(&profile); | 511 ProfileTrieWalker walker(&profile); |
| 511 | 512 |
| 512 // Exclusive code: B.boo -> main. | 513 // Exclusive code: B.boo -> main. |
| 513 walker.Reset(Profile::kExclusiveCode); | 514 walker.Reset(Profile::kExclusiveCode); |
| 514 // Move down from the root. | 515 // Move down from the root. |
| 515 EXPECT(walker.Down()); | 516 EXPECT(walker.Down()); |
| 516 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 517 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 577 |
| 577 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 578 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 578 EXPECT_VALID(result); | 579 EXPECT_VALID(result); |
| 579 | 580 |
| 580 { | 581 { |
| 581 Thread* thread = Thread::Current(); | 582 Thread* thread = Thread::Current(); |
| 582 Isolate* isolate = thread->isolate(); | 583 Isolate* isolate = thread->isolate(); |
| 583 StackZone zone(thread); | 584 StackZone zone(thread); |
| 584 HANDLESCOPE(thread); | 585 HANDLESCOPE(thread); |
| 585 Profile profile(isolate); | 586 Profile profile(isolate); |
| 586 AllocationFilter filter(isolate, class_a.id()); | 587 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 587 profile.Build(thread, &filter, Profile::kNoTags); | 588 profile.Build(thread, &filter, Profile::kNoTags); |
| 588 // We should have no allocation samples. | 589 // We should have no allocation samples. |
| 589 EXPECT_EQ(0, profile.sample_count()); | 590 EXPECT_EQ(0, profile.sample_count()); |
| 590 } | 591 } |
| 591 | 592 |
| 592 // Turn on allocation tracing for A. | 593 // Turn on allocation tracing for A. |
| 593 class_a.SetTraceAllocation(true); | 594 class_a.SetTraceAllocation(true); |
| 594 | 595 |
| 595 // Allocate three times. | 596 // Allocate three times. |
| 596 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 597 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 597 EXPECT_VALID(result); | 598 EXPECT_VALID(result); |
| 598 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 599 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 599 EXPECT_VALID(result); | 600 EXPECT_VALID(result); |
| 600 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 601 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 601 EXPECT_VALID(result); | 602 EXPECT_VALID(result); |
| 602 | 603 |
| 603 { | 604 { |
| 604 Thread* thread = Thread::Current(); | 605 Thread* thread = Thread::Current(); |
| 605 Isolate* isolate = thread->isolate(); | 606 Isolate* isolate = thread->isolate(); |
| 606 StackZone zone(thread); | 607 StackZone zone(thread); |
| 607 HANDLESCOPE(thread); | 608 HANDLESCOPE(thread); |
| 608 Profile profile(isolate); | 609 Profile profile(isolate); |
| 609 AllocationFilter filter(isolate, class_a.id()); | 610 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 610 profile.Build(thread, &filter, Profile::kNoTags); | 611 profile.Build(thread, &filter, Profile::kNoTags); |
| 611 // We should have three allocation samples. | 612 // We should have three allocation samples. |
| 612 EXPECT_EQ(3, profile.sample_count()); | 613 EXPECT_EQ(3, profile.sample_count()); |
| 613 ProfileTrieWalker walker(&profile); | 614 ProfileTrieWalker walker(&profile); |
| 614 | 615 |
| 615 // Exclusive function: B.boo -> main. | 616 // Exclusive function: B.boo -> main. |
| 616 walker.Reset(Profile::kExclusiveFunction); | 617 walker.Reset(Profile::kExclusiveFunction); |
| 617 // Move down from the root. | 618 // Move down from the root. |
| 618 EXPECT(walker.Down()); | 619 EXPECT(walker.Down()); |
| 619 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 620 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 Dart_NewDouble(1.0), Dart_NewDouble(2.0), | 671 Dart_NewDouble(1.0), Dart_NewDouble(2.0), |
| 671 }; | 672 }; |
| 672 | 673 |
| 673 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 674 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 674 EXPECT_VALID(result); | 675 EXPECT_VALID(result); |
| 675 | 676 |
| 676 { | 677 { |
| 677 StackZone zone(thread); | 678 StackZone zone(thread); |
| 678 HANDLESCOPE(thread); | 679 HANDLESCOPE(thread); |
| 679 Profile profile(isolate); | 680 Profile profile(isolate); |
| 680 AllocationFilter filter(isolate, double_class.id()); | 681 AllocationFilter filter(isolate->main_port(), double_class.id()); |
| 681 profile.Build(thread, &filter, Profile::kNoTags); | 682 profile.Build(thread, &filter, Profile::kNoTags); |
| 682 // We should have no allocation samples. | 683 // We should have no allocation samples. |
| 683 EXPECT_EQ(0, profile.sample_count()); | 684 EXPECT_EQ(0, profile.sample_count()); |
| 684 } | 685 } |
| 685 | 686 |
| 686 double_class.SetTraceAllocation(true); | 687 double_class.SetTraceAllocation(true); |
| 687 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 688 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 688 EXPECT_VALID(result); | 689 EXPECT_VALID(result); |
| 689 | 690 |
| 690 { | 691 { |
| 691 StackZone zone(thread); | 692 StackZone zone(thread); |
| 692 HANDLESCOPE(thread); | 693 HANDLESCOPE(thread); |
| 693 Profile profile(isolate); | 694 Profile profile(isolate); |
| 694 AllocationFilter filter(isolate, double_class.id()); | 695 AllocationFilter filter(isolate->main_port(), double_class.id()); |
| 695 profile.Build(thread, &filter, Profile::kNoTags); | 696 profile.Build(thread, &filter, Profile::kNoTags); |
| 696 // We should have one allocation sample. | 697 // We should have one allocation sample. |
| 697 EXPECT_EQ(1, profile.sample_count()); | 698 EXPECT_EQ(1, profile.sample_count()); |
| 698 ProfileTrieWalker walker(&profile); | 699 ProfileTrieWalker walker(&profile); |
| 699 | 700 |
| 700 walker.Reset(Profile::kExclusiveCode); | 701 walker.Reset(Profile::kExclusiveCode); |
| 701 EXPECT(walker.Down()); | 702 EXPECT(walker.Down()); |
| 702 EXPECT_STREQ("Double_add", walker.CurrentName()); | 703 EXPECT_STREQ("Double_add", walker.CurrentName()); |
| 703 EXPECT(walker.Down()); | 704 EXPECT(walker.Down()); |
| 704 EXPECT_STREQ("_Double._add", walker.CurrentName()); | 705 EXPECT_STREQ("_Double._add", walker.CurrentName()); |
| 705 EXPECT(walker.Down()); | 706 EXPECT(walker.Down()); |
| 706 EXPECT_STREQ("_Double.+", walker.CurrentName()); | 707 EXPECT_STREQ("_Double.+", walker.CurrentName()); |
| 707 EXPECT(walker.Down()); | 708 EXPECT(walker.Down()); |
| 708 EXPECT_STREQ("foo", walker.CurrentName()); | 709 EXPECT_STREQ("foo", walker.CurrentName()); |
| 709 EXPECT(!walker.Down()); | 710 EXPECT(!walker.Down()); |
| 710 } | 711 } |
| 711 | 712 |
| 712 double_class.SetTraceAllocation(false); | 713 double_class.SetTraceAllocation(false); |
| 713 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 714 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 714 EXPECT_VALID(result); | 715 EXPECT_VALID(result); |
| 715 | 716 |
| 716 { | 717 { |
| 717 StackZone zone(thread); | 718 StackZone zone(thread); |
| 718 HANDLESCOPE(thread); | 719 HANDLESCOPE(thread); |
| 719 Profile profile(isolate); | 720 Profile profile(isolate); |
| 720 AllocationFilter filter(isolate, double_class.id()); | 721 AllocationFilter filter(isolate->main_port(), double_class.id()); |
| 721 profile.Build(thread, &filter, Profile::kNoTags); | 722 profile.Build(thread, &filter, Profile::kNoTags); |
| 722 // We should still only have one allocation sample. | 723 // We should still only have one allocation sample. |
| 723 EXPECT_EQ(1, profile.sample_count()); | 724 EXPECT_EQ(1, profile.sample_count()); |
| 724 } | 725 } |
| 725 } | 726 } |
| 726 | 727 |
| 727 | 728 |
| 728 TEST_CASE(Profiler_ArrayAllocation) { | 729 TEST_CASE(Profiler_ArrayAllocation) { |
| 729 DisableNativeProfileScope dnps; | 730 DisableNativeProfileScope dnps; |
| 730 const char* kScript = | 731 const char* kScript = |
| 731 "List foo() => new List(4);\n" | 732 "List foo() => new List(4);\n" |
| 732 "List bar() => new List();\n"; | 733 "List bar() => new List();\n"; |
| 733 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 734 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 734 EXPECT_VALID(lib); | 735 EXPECT_VALID(lib); |
| 735 Library& root_library = Library::Handle(); | 736 Library& root_library = Library::Handle(); |
| 736 root_library ^= Api::UnwrapHandle(lib); | 737 root_library ^= Api::UnwrapHandle(lib); |
| 737 Isolate* isolate = thread->isolate(); | 738 Isolate* isolate = thread->isolate(); |
| 738 | 739 |
| 739 const Class& array_class = | 740 const Class& array_class = |
| 740 Class::Handle(isolate->object_store()->array_class()); | 741 Class::Handle(isolate->object_store()->array_class()); |
| 741 EXPECT(!array_class.IsNull()); | 742 EXPECT(!array_class.IsNull()); |
| 742 | 743 |
| 743 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 744 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 744 EXPECT_VALID(result); | 745 EXPECT_VALID(result); |
| 745 | 746 |
| 746 { | 747 { |
| 747 StackZone zone(thread); | 748 StackZone zone(thread); |
| 748 HANDLESCOPE(thread); | 749 HANDLESCOPE(thread); |
| 749 Profile profile(isolate); | 750 Profile profile(isolate); |
| 750 AllocationFilter filter(isolate, array_class.id()); | 751 AllocationFilter filter(isolate->main_port(), array_class.id()); |
| 751 profile.Build(thread, &filter, Profile::kNoTags); | 752 profile.Build(thread, &filter, Profile::kNoTags); |
| 752 // We should have no allocation samples. | 753 // We should have no allocation samples. |
| 753 EXPECT_EQ(0, profile.sample_count()); | 754 EXPECT_EQ(0, profile.sample_count()); |
| 754 } | 755 } |
| 755 | 756 |
| 756 array_class.SetTraceAllocation(true); | 757 array_class.SetTraceAllocation(true); |
| 757 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 758 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 758 EXPECT_VALID(result); | 759 EXPECT_VALID(result); |
| 759 | 760 |
| 760 { | 761 { |
| 761 StackZone zone(thread); | 762 StackZone zone(thread); |
| 762 HANDLESCOPE(thread); | 763 HANDLESCOPE(thread); |
| 763 Profile profile(isolate); | 764 Profile profile(isolate); |
| 764 AllocationFilter filter(isolate, array_class.id()); | 765 AllocationFilter filter(isolate->main_port(), array_class.id()); |
| 765 profile.Build(thread, &filter, Profile::kNoTags); | 766 profile.Build(thread, &filter, Profile::kNoTags); |
| 766 // We should have one allocation sample. | 767 // We should have one allocation sample. |
| 767 EXPECT_EQ(1, profile.sample_count()); | 768 EXPECT_EQ(1, profile.sample_count()); |
| 768 ProfileTrieWalker walker(&profile); | 769 ProfileTrieWalker walker(&profile); |
| 769 | 770 |
| 770 walker.Reset(Profile::kExclusiveCode); | 771 walker.Reset(Profile::kExclusiveCode); |
| 771 EXPECT(walker.Down()); | 772 EXPECT(walker.Down()); |
| 772 EXPECT_STREQ("DRT_AllocateArray", walker.CurrentName()); | 773 EXPECT_STREQ("DRT_AllocateArray", walker.CurrentName()); |
| 773 EXPECT(walker.Down()); | 774 EXPECT(walker.Down()); |
| 774 EXPECT_STREQ("[Stub] AllocateArray", walker.CurrentName()); | 775 EXPECT_STREQ("[Stub] AllocateArray", walker.CurrentName()); |
| 775 EXPECT(walker.Down()); | 776 EXPECT(walker.Down()); |
| 776 EXPECT_STREQ("_List._List", walker.CurrentName()); | 777 EXPECT_STREQ("_List._List", walker.CurrentName()); |
| 777 EXPECT(walker.Down()); | 778 EXPECT(walker.Down()); |
| 778 EXPECT_STREQ("List.List._internal", walker.CurrentName()); | 779 EXPECT_STREQ("List.List._internal", walker.CurrentName()); |
| 779 EXPECT(walker.Down()); | 780 EXPECT(walker.Down()); |
| 780 EXPECT_STREQ("foo", walker.CurrentName()); | 781 EXPECT_STREQ("foo", walker.CurrentName()); |
| 781 EXPECT(!walker.Down()); | 782 EXPECT(!walker.Down()); |
| 782 } | 783 } |
| 783 | 784 |
| 784 array_class.SetTraceAllocation(false); | 785 array_class.SetTraceAllocation(false); |
| 785 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 786 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 786 EXPECT_VALID(result); | 787 EXPECT_VALID(result); |
| 787 | 788 |
| 788 { | 789 { |
| 789 StackZone zone(thread); | 790 StackZone zone(thread); |
| 790 HANDLESCOPE(thread); | 791 HANDLESCOPE(thread); |
| 791 Profile profile(isolate); | 792 Profile profile(isolate); |
| 792 AllocationFilter filter(isolate, array_class.id()); | 793 AllocationFilter filter(isolate->main_port(), array_class.id()); |
| 793 profile.Build(thread, &filter, Profile::kNoTags); | 794 profile.Build(thread, &filter, Profile::kNoTags); |
| 794 // We should still only have one allocation sample. | 795 // We should still only have one allocation sample. |
| 795 EXPECT_EQ(1, profile.sample_count()); | 796 EXPECT_EQ(1, profile.sample_count()); |
| 796 } | 797 } |
| 797 | 798 |
| 798 // Clear the samples. | 799 // Clear the samples. |
| 799 ProfilerService::ClearSamples(); | 800 ProfilerService::ClearSamples(); |
| 800 | 801 |
| 801 // Compile bar (many List objects allocated). | 802 // Compile bar (many List objects allocated). |
| 802 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); | 803 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
| 803 EXPECT_VALID(result); | 804 EXPECT_VALID(result); |
| 804 | 805 |
| 805 // Enable again. | 806 // Enable again. |
| 806 array_class.SetTraceAllocation(true); | 807 array_class.SetTraceAllocation(true); |
| 807 | 808 |
| 808 // Run bar. | 809 // Run bar. |
| 809 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); | 810 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
| 810 EXPECT_VALID(result); | 811 EXPECT_VALID(result); |
| 811 | 812 |
| 812 { | 813 { |
| 813 StackZone zone(thread); | 814 StackZone zone(thread); |
| 814 HANDLESCOPE(thread); | 815 HANDLESCOPE(thread); |
| 815 Profile profile(isolate); | 816 Profile profile(isolate); |
| 816 AllocationFilter filter(isolate, array_class.id()); | 817 AllocationFilter filter(isolate->main_port(), array_class.id()); |
| 817 profile.Build(thread, &filter, Profile::kNoTags); | 818 profile.Build(thread, &filter, Profile::kNoTags); |
| 818 // We should still only have one allocation sample. | 819 // We should still only have one allocation sample. |
| 819 EXPECT_EQ(1, profile.sample_count()); | 820 EXPECT_EQ(1, profile.sample_count()); |
| 820 ProfileTrieWalker walker(&profile); | 821 ProfileTrieWalker walker(&profile); |
| 821 | 822 |
| 822 walker.Reset(Profile::kExclusiveCode); | 823 walker.Reset(Profile::kExclusiveCode); |
| 823 EXPECT(walker.Down()); | 824 EXPECT(walker.Down()); |
| 824 EXPECT_STREQ("DRT_AllocateArray", walker.CurrentName()); | 825 EXPECT_STREQ("DRT_AllocateArray", walker.CurrentName()); |
| 825 EXPECT(walker.Down()); | 826 EXPECT(walker.Down()); |
| 826 EXPECT_STREQ("[Stub] AllocateArray", walker.CurrentName()); | 827 EXPECT_STREQ("[Stub] AllocateArray", walker.CurrentName()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 854 const Class& context_class = Class::Handle(Object::context_class()); | 855 const Class& context_class = Class::Handle(Object::context_class()); |
| 855 EXPECT(!context_class.IsNull()); | 856 EXPECT(!context_class.IsNull()); |
| 856 | 857 |
| 857 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 858 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 858 EXPECT_VALID(result); | 859 EXPECT_VALID(result); |
| 859 | 860 |
| 860 { | 861 { |
| 861 StackZone zone(thread); | 862 StackZone zone(thread); |
| 862 HANDLESCOPE(thread); | 863 HANDLESCOPE(thread); |
| 863 Profile profile(isolate); | 864 Profile profile(isolate); |
| 864 AllocationFilter filter(isolate, context_class.id()); | 865 AllocationFilter filter(isolate->main_port(), context_class.id()); |
| 865 profile.Build(thread, &filter, Profile::kNoTags); | 866 profile.Build(thread, &filter, Profile::kNoTags); |
| 866 // We should have no allocation samples. | 867 // We should have no allocation samples. |
| 867 EXPECT_EQ(0, profile.sample_count()); | 868 EXPECT_EQ(0, profile.sample_count()); |
| 868 } | 869 } |
| 869 | 870 |
| 870 context_class.SetTraceAllocation(true); | 871 context_class.SetTraceAllocation(true); |
| 871 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 872 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 872 EXPECT_VALID(result); | 873 EXPECT_VALID(result); |
| 873 | 874 |
| 874 { | 875 { |
| 875 StackZone zone(thread); | 876 StackZone zone(thread); |
| 876 HANDLESCOPE(thread); | 877 HANDLESCOPE(thread); |
| 877 Profile profile(isolate); | 878 Profile profile(isolate); |
| 878 AllocationFilter filter(isolate, context_class.id()); | 879 AllocationFilter filter(isolate->main_port(), context_class.id()); |
| 879 profile.Build(thread, &filter, Profile::kNoTags); | 880 profile.Build(thread, &filter, Profile::kNoTags); |
| 880 // We should have one allocation sample. | 881 // We should have one allocation sample. |
| 881 EXPECT_EQ(1, profile.sample_count()); | 882 EXPECT_EQ(1, profile.sample_count()); |
| 882 ProfileTrieWalker walker(&profile); | 883 ProfileTrieWalker walker(&profile); |
| 883 | 884 |
| 884 walker.Reset(Profile::kExclusiveCode); | 885 walker.Reset(Profile::kExclusiveCode); |
| 885 EXPECT(walker.Down()); | 886 EXPECT(walker.Down()); |
| 886 EXPECT_STREQ("DRT_AllocateContext", walker.CurrentName()); | 887 EXPECT_STREQ("DRT_AllocateContext", walker.CurrentName()); |
| 887 EXPECT(walker.Down()); | 888 EXPECT(walker.Down()); |
| 888 EXPECT_STREQ("[Stub] AllocateContext", walker.CurrentName()); | 889 EXPECT_STREQ("[Stub] AllocateContext", walker.CurrentName()); |
| 889 EXPECT(walker.Down()); | 890 EXPECT(walker.Down()); |
| 890 EXPECT_STREQ("foo", walker.CurrentName()); | 891 EXPECT_STREQ("foo", walker.CurrentName()); |
| 891 EXPECT(!walker.Down()); | 892 EXPECT(!walker.Down()); |
| 892 } | 893 } |
| 893 | 894 |
| 894 context_class.SetTraceAllocation(false); | 895 context_class.SetTraceAllocation(false); |
| 895 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 896 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 896 EXPECT_VALID(result); | 897 EXPECT_VALID(result); |
| 897 | 898 |
| 898 { | 899 { |
| 899 StackZone zone(thread); | 900 StackZone zone(thread); |
| 900 HANDLESCOPE(thread); | 901 HANDLESCOPE(thread); |
| 901 Profile profile(isolate); | 902 Profile profile(isolate); |
| 902 AllocationFilter filter(isolate, context_class.id()); | 903 AllocationFilter filter(isolate->main_port(), context_class.id()); |
| 903 profile.Build(thread, &filter, Profile::kNoTags); | 904 profile.Build(thread, &filter, Profile::kNoTags); |
| 904 // We should still only have one allocation sample. | 905 // We should still only have one allocation sample. |
| 905 EXPECT_EQ(1, profile.sample_count()); | 906 EXPECT_EQ(1, profile.sample_count()); |
| 906 } | 907 } |
| 907 } | 908 } |
| 908 | 909 |
| 909 | 910 |
| 910 TEST_CASE(Profiler_ClosureAllocation) { | 911 TEST_CASE(Profiler_ClosureAllocation) { |
| 911 DisableNativeProfileScope dnps; | 912 DisableNativeProfileScope dnps; |
| 912 const char* kScript = | 913 const char* kScript = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 935 closure_class.SetTraceAllocation(true); | 936 closure_class.SetTraceAllocation(true); |
| 936 | 937 |
| 937 // Invoke "foo" which during compilation, triggers a closure allocation. | 938 // Invoke "foo" which during compilation, triggers a closure allocation. |
| 938 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 939 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 939 EXPECT_VALID(result); | 940 EXPECT_VALID(result); |
| 940 | 941 |
| 941 { | 942 { |
| 942 StackZone zone(thread); | 943 StackZone zone(thread); |
| 943 HANDLESCOPE(thread); | 944 HANDLESCOPE(thread); |
| 944 Profile profile(isolate); | 945 Profile profile(isolate); |
| 945 AllocationFilter filter(isolate, closure_class.id()); | 946 AllocationFilter filter(isolate->main_port(), closure_class.id()); |
| 946 filter.set_enable_vm_ticks(true); | 947 filter.set_enable_vm_ticks(true); |
| 947 profile.Build(thread, &filter, Profile::kNoTags); | 948 profile.Build(thread, &filter, Profile::kNoTags); |
| 948 // We should have one allocation sample. | 949 // We should have one allocation sample. |
| 949 EXPECT_EQ(1, profile.sample_count()); | 950 EXPECT_EQ(1, profile.sample_count()); |
| 950 ProfileTrieWalker walker(&profile); | 951 ProfileTrieWalker walker(&profile); |
| 951 | 952 |
| 952 walker.Reset(Profile::kExclusiveCode); | 953 walker.Reset(Profile::kExclusiveCode); |
| 953 EXPECT(walker.Down()); | 954 EXPECT(walker.Down()); |
| 954 EXPECT_SUBSTRING("DRT_AllocateObject", walker.CurrentName()); | 955 EXPECT_SUBSTRING("DRT_AllocateObject", walker.CurrentName()); |
| 955 EXPECT(walker.Down()); | 956 EXPECT(walker.Down()); |
| 956 EXPECT_STREQ("[Stub] Allocate _Closure", walker.CurrentName()); | 957 EXPECT_STREQ("[Stub] Allocate _Closure", walker.CurrentName()); |
| 957 EXPECT(walker.Down()); | 958 EXPECT(walker.Down()); |
| 958 EXPECT_SUBSTRING("foo", walker.CurrentName()); | 959 EXPECT_SUBSTRING("foo", walker.CurrentName()); |
| 959 EXPECT(!walker.Down()); | 960 EXPECT(!walker.Down()); |
| 960 } | 961 } |
| 961 | 962 |
| 962 // Disable allocation tracing for Closure. | 963 // Disable allocation tracing for Closure. |
| 963 closure_class.SetTraceAllocation(false); | 964 closure_class.SetTraceAllocation(false); |
| 964 | 965 |
| 965 // Invoke "bar" which during compilation, triggers a closure allocation. | 966 // Invoke "bar" which during compilation, triggers a closure allocation. |
| 966 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); | 967 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
| 967 EXPECT_VALID(result); | 968 EXPECT_VALID(result); |
| 968 | 969 |
| 969 { | 970 { |
| 970 StackZone zone(thread); | 971 StackZone zone(thread); |
| 971 HANDLESCOPE(thread); | 972 HANDLESCOPE(thread); |
| 972 Profile profile(isolate); | 973 Profile profile(isolate); |
| 973 AllocationFilter filter(isolate, closure_class.id()); | 974 AllocationFilter filter(isolate->main_port(), closure_class.id()); |
| 974 filter.set_enable_vm_ticks(true); | 975 filter.set_enable_vm_ticks(true); |
| 975 profile.Build(thread, &filter, Profile::kNoTags); | 976 profile.Build(thread, &filter, Profile::kNoTags); |
| 976 // We should still only have one allocation sample. | 977 // We should still only have one allocation sample. |
| 977 EXPECT_EQ(1, profile.sample_count()); | 978 EXPECT_EQ(1, profile.sample_count()); |
| 978 } | 979 } |
| 979 } | 980 } |
| 980 | 981 |
| 981 | 982 |
| 982 TEST_CASE(Profiler_TypedArrayAllocation) { | 983 TEST_CASE(Profiler_TypedArrayAllocation) { |
| 983 DisableNativeProfileScope dnps; | 984 DisableNativeProfileScope dnps; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 997 Class::Handle(GetClass(typed_data_library, "_Float32List")); | 998 Class::Handle(GetClass(typed_data_library, "_Float32List")); |
| 998 EXPECT(!float32_list_class.IsNull()); | 999 EXPECT(!float32_list_class.IsNull()); |
| 999 | 1000 |
| 1000 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 1001 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 1001 EXPECT_VALID(result); | 1002 EXPECT_VALID(result); |
| 1002 | 1003 |
| 1003 { | 1004 { |
| 1004 StackZone zone(thread); | 1005 StackZone zone(thread); |
| 1005 HANDLESCOPE(thread); | 1006 HANDLESCOPE(thread); |
| 1006 Profile profile(isolate); | 1007 Profile profile(isolate); |
| 1007 AllocationFilter filter(isolate, float32_list_class.id()); | 1008 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); |
| 1008 profile.Build(thread, &filter, Profile::kNoTags); | 1009 profile.Build(thread, &filter, Profile::kNoTags); |
| 1009 // We should have no allocation samples. | 1010 // We should have no allocation samples. |
| 1010 EXPECT_EQ(0, profile.sample_count()); | 1011 EXPECT_EQ(0, profile.sample_count()); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 float32_list_class.SetTraceAllocation(true); | 1014 float32_list_class.SetTraceAllocation(true); |
| 1014 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 1015 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 1015 EXPECT_VALID(result); | 1016 EXPECT_VALID(result); |
| 1016 | 1017 |
| 1017 { | 1018 { |
| 1018 StackZone zone(thread); | 1019 StackZone zone(thread); |
| 1019 HANDLESCOPE(thread); | 1020 HANDLESCOPE(thread); |
| 1020 Profile profile(isolate); | 1021 Profile profile(isolate); |
| 1021 AllocationFilter filter(isolate, float32_list_class.id()); | 1022 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); |
| 1022 profile.Build(thread, &filter, Profile::kNoTags); | 1023 profile.Build(thread, &filter, Profile::kNoTags); |
| 1023 // We should have one allocation sample. | 1024 // We should have one allocation sample. |
| 1024 EXPECT_EQ(1, profile.sample_count()); | 1025 EXPECT_EQ(1, profile.sample_count()); |
| 1025 ProfileTrieWalker walker(&profile); | 1026 ProfileTrieWalker walker(&profile); |
| 1026 | 1027 |
| 1027 walker.Reset(Profile::kExclusiveCode); | 1028 walker.Reset(Profile::kExclusiveCode); |
| 1028 EXPECT(walker.Down()); | 1029 EXPECT(walker.Down()); |
| 1029 EXPECT_STREQ("TypedData_Float32Array_new", walker.CurrentName()); | 1030 EXPECT_STREQ("TypedData_Float32Array_new", walker.CurrentName()); |
| 1030 EXPECT(walker.Down()); | 1031 EXPECT(walker.Down()); |
| 1031 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName()); | 1032 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName()); |
| 1032 EXPECT(walker.Down()); | 1033 EXPECT(walker.Down()); |
| 1033 EXPECT_STREQ("foo", walker.CurrentName()); | 1034 EXPECT_STREQ("foo", walker.CurrentName()); |
| 1034 EXPECT(!walker.Down()); | 1035 EXPECT(!walker.Down()); |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 float32_list_class.SetTraceAllocation(false); | 1038 float32_list_class.SetTraceAllocation(false); |
| 1038 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 1039 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 1039 EXPECT_VALID(result); | 1040 EXPECT_VALID(result); |
| 1040 | 1041 |
| 1041 { | 1042 { |
| 1042 StackZone zone(thread); | 1043 StackZone zone(thread); |
| 1043 HANDLESCOPE(thread); | 1044 HANDLESCOPE(thread); |
| 1044 Profile profile(isolate); | 1045 Profile profile(isolate); |
| 1045 AllocationFilter filter(isolate, float32_list_class.id()); | 1046 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); |
| 1046 profile.Build(thread, &filter, Profile::kNoTags); | 1047 profile.Build(thread, &filter, Profile::kNoTags); |
| 1047 // We should still only have one allocation sample. | 1048 // We should still only have one allocation sample. |
| 1048 EXPECT_EQ(1, profile.sample_count()); | 1049 EXPECT_EQ(1, profile.sample_count()); |
| 1049 } | 1050 } |
| 1050 | 1051 |
| 1051 float32_list_class.SetTraceAllocation(true); | 1052 float32_list_class.SetTraceAllocation(true); |
| 1052 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 1053 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 1053 EXPECT_VALID(result); | 1054 EXPECT_VALID(result); |
| 1054 | 1055 |
| 1055 { | 1056 { |
| 1056 StackZone zone(thread); | 1057 StackZone zone(thread); |
| 1057 HANDLESCOPE(thread); | 1058 HANDLESCOPE(thread); |
| 1058 Profile profile(isolate); | 1059 Profile profile(isolate); |
| 1059 AllocationFilter filter(isolate, float32_list_class.id()); | 1060 AllocationFilter filter(isolate->main_port(), float32_list_class.id()); |
| 1060 profile.Build(thread, &filter, Profile::kNoTags); | 1061 profile.Build(thread, &filter, Profile::kNoTags); |
| 1061 // We should now have two allocation samples. | 1062 // We should now have two allocation samples. |
| 1062 EXPECT_EQ(2, profile.sample_count()); | 1063 EXPECT_EQ(2, profile.sample_count()); |
| 1063 } | 1064 } |
| 1064 } | 1065 } |
| 1065 | 1066 |
| 1066 | 1067 |
| 1067 TEST_CASE(Profiler_StringAllocation) { | 1068 TEST_CASE(Profiler_StringAllocation) { |
| 1068 DisableNativeProfileScope dnps; | 1069 DisableNativeProfileScope dnps; |
| 1069 const char* kScript = "String foo(String a, String b) => a + b;"; | 1070 const char* kScript = "String foo(String a, String b) => a + b;"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1081 NewString("a"), NewString("b"), | 1082 NewString("a"), NewString("b"), |
| 1082 }; | 1083 }; |
| 1083 | 1084 |
| 1084 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1085 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1085 EXPECT_VALID(result); | 1086 EXPECT_VALID(result); |
| 1086 | 1087 |
| 1087 { | 1088 { |
| 1088 StackZone zone(thread); | 1089 StackZone zone(thread); |
| 1089 HANDLESCOPE(thread); | 1090 HANDLESCOPE(thread); |
| 1090 Profile profile(isolate); | 1091 Profile profile(isolate); |
| 1091 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1092 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1092 profile.Build(thread, &filter, Profile::kNoTags); | 1093 profile.Build(thread, &filter, Profile::kNoTags); |
| 1093 // We should have no allocation samples. | 1094 // We should have no allocation samples. |
| 1094 EXPECT_EQ(0, profile.sample_count()); | 1095 EXPECT_EQ(0, profile.sample_count()); |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 one_byte_string_class.SetTraceAllocation(true); | 1098 one_byte_string_class.SetTraceAllocation(true); |
| 1098 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1099 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1099 EXPECT_VALID(result); | 1100 EXPECT_VALID(result); |
| 1100 | 1101 |
| 1101 { | 1102 { |
| 1102 StackZone zone(thread); | 1103 StackZone zone(thread); |
| 1103 HANDLESCOPE(thread); | 1104 HANDLESCOPE(thread); |
| 1104 Profile profile(isolate); | 1105 Profile profile(isolate); |
| 1105 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1106 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1106 profile.Build(thread, &filter, Profile::kNoTags); | 1107 profile.Build(thread, &filter, Profile::kNoTags); |
| 1107 // We should still only have one allocation sample. | 1108 // We should still only have one allocation sample. |
| 1108 EXPECT_EQ(1, profile.sample_count()); | 1109 EXPECT_EQ(1, profile.sample_count()); |
| 1109 ProfileTrieWalker walker(&profile); | 1110 ProfileTrieWalker walker(&profile); |
| 1110 | 1111 |
| 1111 walker.Reset(Profile::kExclusiveCode); | 1112 walker.Reset(Profile::kExclusiveCode); |
| 1112 EXPECT(walker.Down()); | 1113 EXPECT(walker.Down()); |
| 1113 EXPECT_STREQ("String_concat", walker.CurrentName()); | 1114 EXPECT_STREQ("String_concat", walker.CurrentName()); |
| 1114 EXPECT(walker.Down()); | 1115 EXPECT(walker.Down()); |
| 1115 #if 1 | 1116 #if 1 |
| 1116 EXPECT_STREQ("_StringBase.+", walker.CurrentName()); | 1117 EXPECT_STREQ("_StringBase.+", walker.CurrentName()); |
| 1117 EXPECT(walker.Down()); | 1118 EXPECT(walker.Down()); |
| 1118 #endif | 1119 #endif |
| 1119 EXPECT_STREQ("foo", walker.CurrentName()); | 1120 EXPECT_STREQ("foo", walker.CurrentName()); |
| 1120 EXPECT(!walker.Down()); | 1121 EXPECT(!walker.Down()); |
| 1121 } | 1122 } |
| 1122 | 1123 |
| 1123 one_byte_string_class.SetTraceAllocation(false); | 1124 one_byte_string_class.SetTraceAllocation(false); |
| 1124 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1125 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1125 EXPECT_VALID(result); | 1126 EXPECT_VALID(result); |
| 1126 | 1127 |
| 1127 { | 1128 { |
| 1128 StackZone zone(thread); | 1129 StackZone zone(thread); |
| 1129 HANDLESCOPE(thread); | 1130 HANDLESCOPE(thread); |
| 1130 Profile profile(isolate); | 1131 Profile profile(isolate); |
| 1131 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1132 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1132 profile.Build(thread, &filter, Profile::kNoTags); | 1133 profile.Build(thread, &filter, Profile::kNoTags); |
| 1133 // We should still only have one allocation sample. | 1134 // We should still only have one allocation sample. |
| 1134 EXPECT_EQ(1, profile.sample_count()); | 1135 EXPECT_EQ(1, profile.sample_count()); |
| 1135 } | 1136 } |
| 1136 | 1137 |
| 1137 one_byte_string_class.SetTraceAllocation(true); | 1138 one_byte_string_class.SetTraceAllocation(true); |
| 1138 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1139 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1139 EXPECT_VALID(result); | 1140 EXPECT_VALID(result); |
| 1140 | 1141 |
| 1141 { | 1142 { |
| 1142 StackZone zone(thread); | 1143 StackZone zone(thread); |
| 1143 HANDLESCOPE(thread); | 1144 HANDLESCOPE(thread); |
| 1144 Profile profile(isolate); | 1145 Profile profile(isolate); |
| 1145 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1146 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1146 profile.Build(thread, &filter, Profile::kNoTags); | 1147 profile.Build(thread, &filter, Profile::kNoTags); |
| 1147 // We should now have two allocation samples. | 1148 // We should now have two allocation samples. |
| 1148 EXPECT_EQ(2, profile.sample_count()); | 1149 EXPECT_EQ(2, profile.sample_count()); |
| 1149 } | 1150 } |
| 1150 } | 1151 } |
| 1151 | 1152 |
| 1152 | 1153 |
| 1153 TEST_CASE(Profiler_StringInterpolation) { | 1154 TEST_CASE(Profiler_StringInterpolation) { |
| 1154 DisableNativeProfileScope dnps; | 1155 DisableNativeProfileScope dnps; |
| 1155 DisableBackgroundCompilationScope dbcs; | 1156 DisableBackgroundCompilationScope dbcs; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1168 NewString("a"), NewString("b"), | 1169 NewString("a"), NewString("b"), |
| 1169 }; | 1170 }; |
| 1170 | 1171 |
| 1171 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1172 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1172 EXPECT_VALID(result); | 1173 EXPECT_VALID(result); |
| 1173 | 1174 |
| 1174 { | 1175 { |
| 1175 StackZone zone(thread); | 1176 StackZone zone(thread); |
| 1176 HANDLESCOPE(thread); | 1177 HANDLESCOPE(thread); |
| 1177 Profile profile(isolate); | 1178 Profile profile(isolate); |
| 1178 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1179 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1179 profile.Build(thread, &filter, Profile::kNoTags); | 1180 profile.Build(thread, &filter, Profile::kNoTags); |
| 1180 // We should have no allocation samples. | 1181 // We should have no allocation samples. |
| 1181 EXPECT_EQ(0, profile.sample_count()); | 1182 EXPECT_EQ(0, profile.sample_count()); |
| 1182 } | 1183 } |
| 1183 | 1184 |
| 1184 one_byte_string_class.SetTraceAllocation(true); | 1185 one_byte_string_class.SetTraceAllocation(true); |
| 1185 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1186 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1186 EXPECT_VALID(result); | 1187 EXPECT_VALID(result); |
| 1187 | 1188 |
| 1188 { | 1189 { |
| 1189 StackZone zone(thread); | 1190 StackZone zone(thread); |
| 1190 HANDLESCOPE(thread); | 1191 HANDLESCOPE(thread); |
| 1191 Profile profile(isolate); | 1192 Profile profile(isolate); |
| 1192 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1193 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1193 profile.Build(thread, &filter, Profile::kNoTags); | 1194 profile.Build(thread, &filter, Profile::kNoTags); |
| 1194 // We should still only have one allocation sample. | 1195 // We should still only have one allocation sample. |
| 1195 EXPECT_EQ(1, profile.sample_count()); | 1196 EXPECT_EQ(1, profile.sample_count()); |
| 1196 ProfileTrieWalker walker(&profile); | 1197 ProfileTrieWalker walker(&profile); |
| 1197 | 1198 |
| 1198 walker.Reset(Profile::kExclusiveCode); | 1199 walker.Reset(Profile::kExclusiveCode); |
| 1199 EXPECT(walker.Down()); | 1200 EXPECT(walker.Down()); |
| 1200 EXPECT_STREQ("OneByteString_allocate", walker.CurrentName()); | 1201 EXPECT_STREQ("OneByteString_allocate", walker.CurrentName()); |
| 1201 EXPECT(walker.Down()); | 1202 EXPECT(walker.Down()); |
| 1202 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName()); | 1203 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName()); |
| 1203 EXPECT(walker.Down()); | 1204 EXPECT(walker.Down()); |
| 1204 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName()); | 1205 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName()); |
| 1205 EXPECT(walker.Down()); | 1206 EXPECT(walker.Down()); |
| 1206 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName()); | 1207 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName()); |
| 1207 EXPECT(walker.Down()); | 1208 EXPECT(walker.Down()); |
| 1208 EXPECT_STREQ("foo", walker.CurrentName()); | 1209 EXPECT_STREQ("foo", walker.CurrentName()); |
| 1209 EXPECT(!walker.Down()); | 1210 EXPECT(!walker.Down()); |
| 1210 } | 1211 } |
| 1211 | 1212 |
| 1212 one_byte_string_class.SetTraceAllocation(false); | 1213 one_byte_string_class.SetTraceAllocation(false); |
| 1213 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1214 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1214 EXPECT_VALID(result); | 1215 EXPECT_VALID(result); |
| 1215 | 1216 |
| 1216 { | 1217 { |
| 1217 StackZone zone(thread); | 1218 StackZone zone(thread); |
| 1218 HANDLESCOPE(thread); | 1219 HANDLESCOPE(thread); |
| 1219 Profile profile(isolate); | 1220 Profile profile(isolate); |
| 1220 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1221 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1221 profile.Build(thread, &filter, Profile::kNoTags); | 1222 profile.Build(thread, &filter, Profile::kNoTags); |
| 1222 // We should still only have one allocation sample. | 1223 // We should still only have one allocation sample. |
| 1223 EXPECT_EQ(1, profile.sample_count()); | 1224 EXPECT_EQ(1, profile.sample_count()); |
| 1224 } | 1225 } |
| 1225 | 1226 |
| 1226 one_byte_string_class.SetTraceAllocation(true); | 1227 one_byte_string_class.SetTraceAllocation(true); |
| 1227 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); | 1228 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 1228 EXPECT_VALID(result); | 1229 EXPECT_VALID(result); |
| 1229 | 1230 |
| 1230 { | 1231 { |
| 1231 StackZone zone(thread); | 1232 StackZone zone(thread); |
| 1232 HANDLESCOPE(thread); | 1233 HANDLESCOPE(thread); |
| 1233 Profile profile(isolate); | 1234 Profile profile(isolate); |
| 1234 AllocationFilter filter(isolate, one_byte_string_class.id()); | 1235 AllocationFilter filter(isolate->main_port(), one_byte_string_class.id()); |
| 1235 profile.Build(thread, &filter, Profile::kNoTags); | 1236 profile.Build(thread, &filter, Profile::kNoTags); |
| 1236 // We should now have two allocation samples. | 1237 // We should now have two allocation samples. |
| 1237 EXPECT_EQ(2, profile.sample_count()); | 1238 EXPECT_EQ(2, profile.sample_count()); |
| 1238 } | 1239 } |
| 1239 } | 1240 } |
| 1240 | 1241 |
| 1241 | 1242 |
| 1242 TEST_CASE(Profiler_FunctionInline) { | 1243 TEST_CASE(Profiler_FunctionInline) { |
| 1243 DisableNativeProfileScope dnps; | 1244 DisableNativeProfileScope dnps; |
| 1244 DisableBackgroundCompilationScope dbcs; | 1245 DisableBackgroundCompilationScope dbcs; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL); | 1285 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL); |
| 1285 EXPECT_VALID(result); | 1286 EXPECT_VALID(result); |
| 1286 // At this point B.boo should be optimized and inlined B.foo and B.choo. | 1287 // At this point B.boo should be optimized and inlined B.foo and B.choo. |
| 1287 | 1288 |
| 1288 { | 1289 { |
| 1289 Thread* thread = Thread::Current(); | 1290 Thread* thread = Thread::Current(); |
| 1290 Isolate* isolate = thread->isolate(); | 1291 Isolate* isolate = thread->isolate(); |
| 1291 StackZone zone(thread); | 1292 StackZone zone(thread); |
| 1292 HANDLESCOPE(thread); | 1293 HANDLESCOPE(thread); |
| 1293 Profile profile(isolate); | 1294 Profile profile(isolate); |
| 1294 AllocationFilter filter(isolate, class_a.id()); | 1295 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1295 profile.Build(thread, &filter, Profile::kNoTags); | 1296 profile.Build(thread, &filter, Profile::kNoTags); |
| 1296 // We should have no allocation samples. | 1297 // We should have no allocation samples. |
| 1297 EXPECT_EQ(0, profile.sample_count()); | 1298 EXPECT_EQ(0, profile.sample_count()); |
| 1298 } | 1299 } |
| 1299 | 1300 |
| 1300 // Turn on allocation tracing for A. | 1301 // Turn on allocation tracing for A. |
| 1301 class_a.SetTraceAllocation(true); | 1302 class_a.SetTraceAllocation(true); |
| 1302 | 1303 |
| 1303 // Allocate 50,000 instances of A. | 1304 // Allocate 50,000 instances of A. |
| 1304 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL); | 1305 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL); |
| 1305 EXPECT_VALID(result); | 1306 EXPECT_VALID(result); |
| 1306 | 1307 |
| 1307 { | 1308 { |
| 1308 Thread* thread = Thread::Current(); | 1309 Thread* thread = Thread::Current(); |
| 1309 Isolate* isolate = thread->isolate(); | 1310 Isolate* isolate = thread->isolate(); |
| 1310 StackZone zone(thread); | 1311 StackZone zone(thread); |
| 1311 HANDLESCOPE(thread); | 1312 HANDLESCOPE(thread); |
| 1312 Profile profile(isolate); | 1313 Profile profile(isolate); |
| 1313 AllocationFilter filter(isolate, class_a.id()); | 1314 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1314 profile.Build(thread, &filter, Profile::kNoTags); | 1315 profile.Build(thread, &filter, Profile::kNoTags); |
| 1315 // We should have 50,000 allocation samples. | 1316 // We should have 50,000 allocation samples. |
| 1316 EXPECT_EQ(50000, profile.sample_count()); | 1317 EXPECT_EQ(50000, profile.sample_count()); |
| 1317 ProfileTrieWalker walker(&profile); | 1318 ProfileTrieWalker walker(&profile); |
| 1318 // We have two code objects: mainA and B.boo. | 1319 // We have two code objects: mainA and B.boo. |
| 1319 walker.Reset(Profile::kExclusiveCode); | 1320 walker.Reset(Profile::kExclusiveCode); |
| 1320 EXPECT(walker.Down()); | 1321 EXPECT(walker.Down()); |
| 1321 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1322 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| 1322 EXPECT(walker.Down()); | 1323 EXPECT(walker.Down()); |
| 1323 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); | 1324 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 EXPECT(!walker.Down()); | 1422 EXPECT(!walker.Down()); |
| 1422 } | 1423 } |
| 1423 | 1424 |
| 1424 // Test code transition tags. | 1425 // Test code transition tags. |
| 1425 { | 1426 { |
| 1426 Thread* thread = Thread::Current(); | 1427 Thread* thread = Thread::Current(); |
| 1427 Isolate* isolate = thread->isolate(); | 1428 Isolate* isolate = thread->isolate(); |
| 1428 StackZone zone(thread); | 1429 StackZone zone(thread); |
| 1429 HANDLESCOPE(thread); | 1430 HANDLESCOPE(thread); |
| 1430 Profile profile(isolate); | 1431 Profile profile(isolate); |
| 1431 AllocationFilter filter(isolate, class_a.id()); | 1432 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1432 profile.Build(thread, &filter, Profile::kNoTags, | 1433 profile.Build(thread, &filter, Profile::kNoTags, |
| 1433 ProfilerService::kCodeTransitionTagsBit); | 1434 ProfilerService::kCodeTransitionTagsBit); |
| 1434 // We should have 50,000 allocation samples. | 1435 // We should have 50,000 allocation samples. |
| 1435 EXPECT_EQ(50000, profile.sample_count()); | 1436 EXPECT_EQ(50000, profile.sample_count()); |
| 1436 ProfileTrieWalker walker(&profile); | 1437 ProfileTrieWalker walker(&profile); |
| 1437 // We have two code objects: mainA and B.boo. | 1438 // We have two code objects: mainA and B.boo. |
| 1438 walker.Reset(Profile::kExclusiveCode); | 1439 walker.Reset(Profile::kExclusiveCode); |
| 1439 EXPECT(walker.Down()); | 1440 EXPECT(walker.Down()); |
| 1440 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1441 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| 1441 EXPECT(walker.Down()); | 1442 EXPECT(walker.Down()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 EXPECT(!func.is_inlinable()); | 1595 EXPECT(!func.is_inlinable()); |
| 1595 func = GetFunction(root_library, "maybeAlloc"); | 1596 func = GetFunction(root_library, "maybeAlloc"); |
| 1596 EXPECT(!func.is_inlinable()); | 1597 EXPECT(!func.is_inlinable()); |
| 1597 | 1598 |
| 1598 { | 1599 { |
| 1599 Thread* thread = Thread::Current(); | 1600 Thread* thread = Thread::Current(); |
| 1600 Isolate* isolate = thread->isolate(); | 1601 Isolate* isolate = thread->isolate(); |
| 1601 StackZone zone(thread); | 1602 StackZone zone(thread); |
| 1602 HANDLESCOPE(thread); | 1603 HANDLESCOPE(thread); |
| 1603 Profile profile(isolate); | 1604 Profile profile(isolate); |
| 1604 AllocationFilter filter(isolate, class_a.id()); | 1605 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1605 profile.Build(thread, &filter, Profile::kNoTags); | 1606 profile.Build(thread, &filter, Profile::kNoTags); |
| 1606 // We should have no allocation samples. | 1607 // We should have no allocation samples. |
| 1607 EXPECT_EQ(0, profile.sample_count()); | 1608 EXPECT_EQ(0, profile.sample_count()); |
| 1608 } | 1609 } |
| 1609 | 1610 |
| 1610 // Turn on allocation tracing for A. | 1611 // Turn on allocation tracing for A. |
| 1611 class_a.SetTraceAllocation(true); | 1612 class_a.SetTraceAllocation(true); |
| 1612 | 1613 |
| 1613 result = Dart_Invoke(lib, NewString("mainAlloc"), 0, NULL); | 1614 result = Dart_Invoke(lib, NewString("mainAlloc"), 0, NULL); |
| 1614 EXPECT_VALID(result); | 1615 EXPECT_VALID(result); |
| 1615 | 1616 |
| 1616 { | 1617 { |
| 1617 Thread* thread = Thread::Current(); | 1618 Thread* thread = Thread::Current(); |
| 1618 Isolate* isolate = thread->isolate(); | 1619 Isolate* isolate = thread->isolate(); |
| 1619 StackZone zone(thread); | 1620 StackZone zone(thread); |
| 1620 HANDLESCOPE(thread); | 1621 HANDLESCOPE(thread); |
| 1621 Profile profile(isolate); | 1622 Profile profile(isolate); |
| 1622 AllocationFilter filter(isolate, class_a.id()); | 1623 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1623 profile.Build(thread, &filter, Profile::kNoTags); | 1624 profile.Build(thread, &filter, Profile::kNoTags); |
| 1624 EXPECT_EQ(1, profile.sample_count()); | 1625 EXPECT_EQ(1, profile.sample_count()); |
| 1625 ProfileTrieWalker walker(&profile); | 1626 ProfileTrieWalker walker(&profile); |
| 1626 | 1627 |
| 1627 // Inline expansion should show us the complete call chain: | 1628 // Inline expansion should show us the complete call chain: |
| 1628 walker.Reset(Profile::kExclusiveFunction); | 1629 walker.Reset(Profile::kExclusiveFunction); |
| 1629 EXPECT(walker.Down()); | 1630 EXPECT(walker.Down()); |
| 1630 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1631 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| 1631 EXPECT(walker.Down()); | 1632 EXPECT(walker.Down()); |
| 1632 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); | 1633 EXPECT_STREQ("[Stub] Allocate A", walker.CurrentName()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1712 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1712 EXPECT_VALID(result); | 1713 EXPECT_VALID(result); |
| 1713 | 1714 |
| 1714 | 1715 |
| 1715 { | 1716 { |
| 1716 Thread* thread = Thread::Current(); | 1717 Thread* thread = Thread::Current(); |
| 1717 Isolate* isolate = thread->isolate(); | 1718 Isolate* isolate = thread->isolate(); |
| 1718 StackZone zone(thread); | 1719 StackZone zone(thread); |
| 1719 HANDLESCOPE(thread); | 1720 HANDLESCOPE(thread); |
| 1720 Profile profile(isolate); | 1721 Profile profile(isolate); |
| 1721 AllocationFilter filter(isolate, class_a.id()); | 1722 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1722 profile.Build(thread, &filter, Profile::kNoTags); | 1723 profile.Build(thread, &filter, Profile::kNoTags); |
| 1723 // We should have 1 allocation sample. | 1724 // We should have 1 allocation sample. |
| 1724 EXPECT_EQ(1, profile.sample_count()); | 1725 EXPECT_EQ(1, profile.sample_count()); |
| 1725 ProfileTrieWalker walker(&profile); | 1726 ProfileTrieWalker walker(&profile); |
| 1726 | 1727 |
| 1727 walker.Reset(Profile::kExclusiveCode); | 1728 walker.Reset(Profile::kExclusiveCode); |
| 1728 // Move down from the root. | 1729 // Move down from the root. |
| 1729 EXPECT(walker.Down()); | 1730 EXPECT(walker.Down()); |
| 1730 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1731 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| 1731 EXPECT(walker.Down()); | 1732 EXPECT(walker.Down()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 // Allocate one time. | 1814 // Allocate one time. |
| 1814 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1815 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1815 EXPECT_VALID(result); | 1816 EXPECT_VALID(result); |
| 1816 | 1817 |
| 1817 { | 1818 { |
| 1818 Thread* thread = Thread::Current(); | 1819 Thread* thread = Thread::Current(); |
| 1819 Isolate* isolate = thread->isolate(); | 1820 Isolate* isolate = thread->isolate(); |
| 1820 StackZone zone(thread); | 1821 StackZone zone(thread); |
| 1821 HANDLESCOPE(thread); | 1822 HANDLESCOPE(thread); |
| 1822 Profile profile(isolate); | 1823 Profile profile(isolate); |
| 1823 AllocationFilter filter(isolate, class_a.id()); | 1824 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1824 profile.Build(thread, &filter, Profile::kNoTags); | 1825 profile.Build(thread, &filter, Profile::kNoTags); |
| 1825 // We should have one allocation samples. | 1826 // We should have one allocation samples. |
| 1826 EXPECT_EQ(1, profile.sample_count()); | 1827 EXPECT_EQ(1, profile.sample_count()); |
| 1827 ProfileTrieWalker walker(&profile); | 1828 ProfileTrieWalker walker(&profile); |
| 1828 | 1829 |
| 1829 // Exclusive function: B.boo -> main. | 1830 // Exclusive function: B.boo -> main. |
| 1830 walker.Reset(Profile::kExclusiveFunction); | 1831 walker.Reset(Profile::kExclusiveFunction); |
| 1831 // Move down from the root. | 1832 // Move down from the root. |
| 1832 EXPECT(walker.Down()); | 1833 EXPECT(walker.Down()); |
| 1833 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1834 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 // Still optimized. | 1908 // Still optimized. |
| 1908 const Code& code = Code::Handle(main.CurrentCode()); | 1909 const Code& code = Code::Handle(main.CurrentCode()); |
| 1909 EXPECT(code.is_optimized()); | 1910 EXPECT(code.is_optimized()); |
| 1910 | 1911 |
| 1911 { | 1912 { |
| 1912 Thread* thread = Thread::Current(); | 1913 Thread* thread = Thread::Current(); |
| 1913 Isolate* isolate = thread->isolate(); | 1914 Isolate* isolate = thread->isolate(); |
| 1914 StackZone zone(thread); | 1915 StackZone zone(thread); |
| 1915 HANDLESCOPE(thread); | 1916 HANDLESCOPE(thread); |
| 1916 Profile profile(isolate); | 1917 Profile profile(isolate); |
| 1917 AllocationFilter filter(isolate, class_a.id()); | 1918 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 1918 profile.Build(thread, &filter, Profile::kNoTags); | 1919 profile.Build(thread, &filter, Profile::kNoTags); |
| 1919 // We should have one allocation samples. | 1920 // We should have one allocation samples. |
| 1920 EXPECT_EQ(1, profile.sample_count()); | 1921 EXPECT_EQ(1, profile.sample_count()); |
| 1921 ProfileTrieWalker walker(&profile); | 1922 ProfileTrieWalker walker(&profile); |
| 1922 | 1923 |
| 1923 // Exclusive function: B.boo -> main. | 1924 // Exclusive function: B.boo -> main. |
| 1924 walker.Reset(Profile::kExclusiveFunction); | 1925 walker.Reset(Profile::kExclusiveFunction); |
| 1925 // Move down from the root. | 1926 // Move down from the root. |
| 1926 EXPECT(walker.Down()); | 1927 EXPECT(walker.Down()); |
| 1927 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 1928 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 // Allocate one time. | 1995 // Allocate one time. |
| 1995 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1996 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1996 EXPECT_VALID(result); | 1997 EXPECT_VALID(result); |
| 1997 | 1998 |
| 1998 { | 1999 { |
| 1999 Thread* thread = Thread::Current(); | 2000 Thread* thread = Thread::Current(); |
| 2000 Isolate* isolate = thread->isolate(); | 2001 Isolate* isolate = thread->isolate(); |
| 2001 StackZone zone(thread); | 2002 StackZone zone(thread); |
| 2002 HANDLESCOPE(thread); | 2003 HANDLESCOPE(thread); |
| 2003 Profile profile(isolate); | 2004 Profile profile(isolate); |
| 2004 AllocationFilter filter(isolate, class_a.id()); | 2005 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 2005 profile.Build(thread, &filter, Profile::kNoTags); | 2006 profile.Build(thread, &filter, Profile::kNoTags); |
| 2006 // We should have one allocation samples. | 2007 // We should have one allocation samples. |
| 2007 EXPECT_EQ(1, profile.sample_count()); | 2008 EXPECT_EQ(1, profile.sample_count()); |
| 2008 ProfileTrieWalker walker(&profile); | 2009 ProfileTrieWalker walker(&profile); |
| 2009 | 2010 |
| 2010 // Exclusive function: B.boo -> main. | 2011 // Exclusive function: B.boo -> main. |
| 2011 walker.Reset(Profile::kExclusiveFunction); | 2012 walker.Reset(Profile::kExclusiveFunction); |
| 2012 // Move down from the root. | 2013 // Move down from the root. |
| 2013 EXPECT(walker.Down()); | 2014 EXPECT(walker.Down()); |
| 2014 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 2015 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 // Still optimized. | 2120 // Still optimized. |
| 2120 const Code& code = Code::Handle(main.CurrentCode()); | 2121 const Code& code = Code::Handle(main.CurrentCode()); |
| 2121 EXPECT(code.is_optimized()); | 2122 EXPECT(code.is_optimized()); |
| 2122 | 2123 |
| 2123 { | 2124 { |
| 2124 Thread* thread = Thread::Current(); | 2125 Thread* thread = Thread::Current(); |
| 2125 Isolate* isolate = thread->isolate(); | 2126 Isolate* isolate = thread->isolate(); |
| 2126 StackZone zone(thread); | 2127 StackZone zone(thread); |
| 2127 HANDLESCOPE(thread); | 2128 HANDLESCOPE(thread); |
| 2128 Profile profile(isolate); | 2129 Profile profile(isolate); |
| 2129 AllocationFilter filter(isolate, class_a.id()); | 2130 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 2130 profile.Build(thread, &filter, Profile::kNoTags); | 2131 profile.Build(thread, &filter, Profile::kNoTags); |
| 2131 // We should have one allocation samples. | 2132 // We should have one allocation samples. |
| 2132 EXPECT_EQ(1, profile.sample_count()); | 2133 EXPECT_EQ(1, profile.sample_count()); |
| 2133 ProfileTrieWalker walker(&profile); | 2134 ProfileTrieWalker walker(&profile); |
| 2134 | 2135 |
| 2135 // Exclusive function: B.boo -> main. | 2136 // Exclusive function: B.boo -> main. |
| 2136 walker.Reset(Profile::kExclusiveFunction); | 2137 walker.Reset(Profile::kExclusiveFunction); |
| 2137 // Move down from the root. | 2138 // Move down from the root. |
| 2138 EXPECT(walker.Down()); | 2139 EXPECT(walker.Down()); |
| 2139 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 2140 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 // Allocate one time. | 2228 // Allocate one time. |
| 2228 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2229 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 2229 EXPECT_VALID(result); | 2230 EXPECT_VALID(result); |
| 2230 | 2231 |
| 2231 { | 2232 { |
| 2232 Thread* thread = Thread::Current(); | 2233 Thread* thread = Thread::Current(); |
| 2233 Isolate* isolate = thread->isolate(); | 2234 Isolate* isolate = thread->isolate(); |
| 2234 StackZone zone(thread); | 2235 StackZone zone(thread); |
| 2235 HANDLESCOPE(thread); | 2236 HANDLESCOPE(thread); |
| 2236 Profile profile(isolate); | 2237 Profile profile(isolate); |
| 2237 AllocationFilter filter(isolate, class_a.id()); | 2238 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 2238 profile.Build(thread, &filter, Profile::kNoTags); | 2239 profile.Build(thread, &filter, Profile::kNoTags); |
| 2239 // We should have one allocation samples. | 2240 // We should have one allocation samples. |
| 2240 EXPECT_EQ(1, profile.sample_count()); | 2241 EXPECT_EQ(1, profile.sample_count()); |
| 2241 ProfileTrieWalker walker(&profile); | 2242 ProfileTrieWalker walker(&profile); |
| 2242 | 2243 |
| 2243 // Exclusive function: B.boo -> main. | 2244 // Exclusive function: B.boo -> main. |
| 2244 walker.Reset(Profile::kExclusiveFunction); | 2245 walker.Reset(Profile::kExclusiveFunction); |
| 2245 // Move down from the root. | 2246 // Move down from the root. |
| 2246 EXPECT(walker.Down()); | 2247 EXPECT(walker.Down()); |
| 2247 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 2248 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2361 // Still optimized. | 2362 // Still optimized. |
| 2362 const Code& code = Code::Handle(main.CurrentCode()); | 2363 const Code& code = Code::Handle(main.CurrentCode()); |
| 2363 EXPECT(code.is_optimized()); | 2364 EXPECT(code.is_optimized()); |
| 2364 | 2365 |
| 2365 { | 2366 { |
| 2366 Thread* thread = Thread::Current(); | 2367 Thread* thread = Thread::Current(); |
| 2367 Isolate* isolate = thread->isolate(); | 2368 Isolate* isolate = thread->isolate(); |
| 2368 StackZone zone(thread); | 2369 StackZone zone(thread); |
| 2369 HANDLESCOPE(thread); | 2370 HANDLESCOPE(thread); |
| 2370 Profile profile(isolate); | 2371 Profile profile(isolate); |
| 2371 AllocationFilter filter(isolate, class_a.id()); | 2372 AllocationFilter filter(isolate->main_port(), class_a.id()); |
| 2372 profile.Build(thread, &filter, Profile::kNoTags); | 2373 profile.Build(thread, &filter, Profile::kNoTags); |
| 2373 // We should have one allocation samples. | 2374 // We should have one allocation samples. |
| 2374 EXPECT_EQ(1, profile.sample_count()); | 2375 EXPECT_EQ(1, profile.sample_count()); |
| 2375 ProfileTrieWalker walker(&profile); | 2376 ProfileTrieWalker walker(&profile); |
| 2376 | 2377 |
| 2377 // Exclusive function: B.boo -> main. | 2378 // Exclusive function: B.boo -> main. |
| 2378 walker.Reset(Profile::kExclusiveFunction); | 2379 walker.Reset(Profile::kExclusiveFunction); |
| 2379 // Move down from the root. | 2380 // Move down from the root. |
| 2380 EXPECT(walker.Down()); | 2381 EXPECT(walker.Down()); |
| 2381 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); | 2382 EXPECT_STREQ("DRT_AllocateObject", walker.CurrentName()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 EXPECT(!walker.Down()); | 2421 EXPECT(!walker.Down()); |
| 2421 } | 2422 } |
| 2422 } | 2423 } |
| 2423 | 2424 |
| 2424 | 2425 |
| 2425 static void InsertFakeSample(SampleBuffer* sample_buffer, uword* pc_offsets) { | 2426 static void InsertFakeSample(SampleBuffer* sample_buffer, uword* pc_offsets) { |
| 2426 ASSERT(sample_buffer != NULL); | 2427 ASSERT(sample_buffer != NULL); |
| 2427 Isolate* isolate = Isolate::Current(); | 2428 Isolate* isolate = Isolate::Current(); |
| 2428 Sample* sample = sample_buffer->ReserveSample(); | 2429 Sample* sample = sample_buffer->ReserveSample(); |
| 2429 ASSERT(sample != NULL); | 2430 ASSERT(sample != NULL); |
| 2430 sample->Init(isolate, OS::GetCurrentMonotonicMicros(), | 2431 sample->Init(isolate->main_port(), OS::GetCurrentMonotonicMicros(), |
| 2431 OSThread::Current()->trace_id()); | 2432 OSThread::Current()->trace_id()); |
| 2432 sample->set_thread_task(Thread::kMutatorTask); | 2433 sample->set_thread_task(Thread::kMutatorTask); |
| 2433 | 2434 |
| 2434 intptr_t i = 0; | 2435 intptr_t i = 0; |
| 2435 while (pc_offsets[i] != 0) { | 2436 while (pc_offsets[i] != 0) { |
| 2436 // When we collect a real stack trace, all PCs collected aside from the | 2437 // When we collect a real stack trace, all PCs collected aside from the |
| 2437 // executing one (i == 0) are actually return addresses. Return addresses | 2438 // executing one (i == 0) are actually return addresses. Return addresses |
| 2438 // are one byte beyond the call instruction that is executing. The profiler | 2439 // are one byte beyond the call instruction that is executing. The profiler |
| 2439 // accounts for this and subtracts one from these addresses when querying | 2440 // accounts for this and subtracts one from these addresses when querying |
| 2440 // inline and token position ranges. To be consistent with real stack | 2441 // inline and token position ranges. To be consistent with real stack |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2593 EXPECT_SUBSTRING("\"positions\":[\"TempMove\",39]", js.ToCString()); | 2594 EXPECT_SUBSTRING("\"positions\":[\"TempMove\",39]", js.ToCString()); |
| 2594 // Verify exclusive ticks in main. | 2595 // Verify exclusive ticks in main. |
| 2595 EXPECT_SUBSTRING("\"exclusiveTicks\":[1,0]", js.ToCString()); | 2596 EXPECT_SUBSTRING("\"exclusiveTicks\":[1,0]", js.ToCString()); |
| 2596 // Verify inclusive ticks in main. | 2597 // Verify inclusive ticks in main. |
| 2597 EXPECT_SUBSTRING("\"inclusiveTicks\":[1,2]", js.ToCString()); | 2598 EXPECT_SUBSTRING("\"inclusiveTicks\":[1,2]", js.ToCString()); |
| 2598 } | 2599 } |
| 2599 | 2600 |
| 2600 #endif // !PRODUCT | 2601 #endif // !PRODUCT |
| 2601 | 2602 |
| 2602 } // namespace dart | 2603 } // namespace dart |
| OLD | NEW |