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

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

Issue 1424703004: Getting rid of Isolate::current_zone() usage. Pass thread instead of isolate where it makes sense. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix build Created 5 years, 1 month 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_service.cc ('k') | runtime/vm/service.h » ('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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 EXPECT_VALID(result); 203 EXPECT_VALID(result);
204 204
205 205
206 { 206 {
207 Thread* thread = Thread::Current(); 207 Thread* thread = Thread::Current();
208 Isolate* isolate = thread->isolate(); 208 Isolate* isolate = thread->isolate();
209 StackZone zone(thread); 209 StackZone zone(thread);
210 HANDLESCOPE(thread); 210 HANDLESCOPE(thread);
211 Profile profile(isolate); 211 Profile profile(isolate);
212 AllocationFilter filter(isolate, class_a.id()); 212 AllocationFilter filter(isolate, class_a.id());
213 profile.Build(&filter, Profile::kNoTags); 213 profile.Build(thread, &filter, Profile::kNoTags);
214 // We should have 1 allocation sample. 214 // We should have 1 allocation sample.
215 EXPECT_EQ(1, profile.sample_count()); 215 EXPECT_EQ(1, profile.sample_count());
216 ProfileTrieWalker walker(&profile); 216 ProfileTrieWalker walker(&profile);
217 217
218 // Exclusive code: B.boo -> main. 218 // Exclusive code: B.boo -> main.
219 walker.Reset(Profile::kExclusiveCode); 219 walker.Reset(Profile::kExclusiveCode);
220 // Move down from the root. 220 // Move down from the root.
221 EXPECT(walker.Down()); 221 EXPECT(walker.Down());
222 EXPECT_STREQ("B.boo", walker.CurrentName()); 222 EXPECT_STREQ("B.boo", walker.CurrentName());
223 EXPECT(walker.Down()); 223 EXPECT(walker.Down());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_VALID(result); 282 EXPECT_VALID(result);
283 283
284 284
285 { 285 {
286 Thread* thread = Thread::Current(); 286 Thread* thread = Thread::Current();
287 Isolate* isolate = thread->isolate(); 287 Isolate* isolate = thread->isolate();
288 StackZone zone(thread); 288 StackZone zone(thread);
289 HANDLESCOPE(thread); 289 HANDLESCOPE(thread);
290 Profile profile(isolate); 290 Profile profile(isolate);
291 AllocationFilter filter(isolate, class_a.id()); 291 AllocationFilter filter(isolate, class_a.id());
292 profile.Build(&filter, Profile::kNoTags); 292 profile.Build(thread, &filter, Profile::kNoTags);
293 // We should have no allocation samples. 293 // We should have no allocation samples.
294 EXPECT_EQ(0, profile.sample_count()); 294 EXPECT_EQ(0, profile.sample_count());
295 } 295 }
296 296
297 // Turn on allocation tracing for A. 297 // Turn on allocation tracing for A.
298 class_a.SetTraceAllocation(true); 298 class_a.SetTraceAllocation(true);
299 299
300 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 300 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
301 EXPECT_VALID(result); 301 EXPECT_VALID(result);
302 302
303 { 303 {
304 Thread* thread = Thread::Current(); 304 Thread* thread = Thread::Current();
305 Isolate* isolate = thread->isolate(); 305 Isolate* isolate = thread->isolate();
306 StackZone zone(thread); 306 StackZone zone(thread);
307 HANDLESCOPE(thread); 307 HANDLESCOPE(thread);
308 Profile profile(isolate); 308 Profile profile(isolate);
309 AllocationFilter filter(isolate, class_a.id()); 309 AllocationFilter filter(isolate, class_a.id());
310 profile.Build(&filter, Profile::kNoTags); 310 profile.Build(thread, &filter, Profile::kNoTags);
311 // We should have one allocation sample. 311 // We should have one allocation sample.
312 EXPECT_EQ(1, profile.sample_count()); 312 EXPECT_EQ(1, profile.sample_count());
313 ProfileTrieWalker walker(&profile); 313 ProfileTrieWalker walker(&profile);
314 314
315 // Exclusive code: B.boo -> main. 315 // Exclusive code: B.boo -> main.
316 walker.Reset(Profile::kExclusiveCode); 316 walker.Reset(Profile::kExclusiveCode);
317 // Move down from the root. 317 // Move down from the root.
318 EXPECT(walker.Down()); 318 EXPECT(walker.Down());
319 EXPECT_STREQ("B.boo", walker.CurrentName()); 319 EXPECT_STREQ("B.boo", walker.CurrentName());
320 EXPECT(walker.Down()); 320 EXPECT(walker.Down());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 355 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
356 EXPECT_VALID(result); 356 EXPECT_VALID(result);
357 357
358 { 358 {
359 Thread* thread = Thread::Current(); 359 Thread* thread = Thread::Current();
360 Isolate* isolate = thread->isolate(); 360 Isolate* isolate = thread->isolate();
361 StackZone zone(thread); 361 StackZone zone(thread);
362 HANDLESCOPE(thread); 362 HANDLESCOPE(thread);
363 Profile profile(isolate); 363 Profile profile(isolate);
364 AllocationFilter filter(isolate, class_a.id()); 364 AllocationFilter filter(isolate, class_a.id());
365 profile.Build(&filter, Profile::kNoTags); 365 profile.Build(thread, &filter, Profile::kNoTags);
366 // We should still only have one allocation sample. 366 // We should still only have one allocation sample.
367 EXPECT_EQ(1, profile.sample_count()); 367 EXPECT_EQ(1, profile.sample_count());
368 } 368 }
369 } 369 }
370 370
371 371
372 TEST_CASE(Profiler_CodeTicks) { 372 TEST_CASE(Profiler_CodeTicks) {
373 DisableNativeProfileScope dnps; 373 DisableNativeProfileScope dnps;
374 const char* kScript = 374 const char* kScript =
375 "class A {\n" 375 "class A {\n"
(...skipping 20 matching lines...) Expand all
396 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 396 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
397 EXPECT_VALID(result); 397 EXPECT_VALID(result);
398 398
399 { 399 {
400 Thread* thread = Thread::Current(); 400 Thread* thread = Thread::Current();
401 Isolate* isolate = thread->isolate(); 401 Isolate* isolate = thread->isolate();
402 StackZone zone(thread); 402 StackZone zone(thread);
403 HANDLESCOPE(thread); 403 HANDLESCOPE(thread);
404 Profile profile(isolate); 404 Profile profile(isolate);
405 AllocationFilter filter(isolate, class_a.id()); 405 AllocationFilter filter(isolate, class_a.id());
406 profile.Build(&filter, Profile::kNoTags); 406 profile.Build(thread, &filter, Profile::kNoTags);
407 // We should have no allocation samples. 407 // We should have no allocation samples.
408 EXPECT_EQ(0, profile.sample_count()); 408 EXPECT_EQ(0, profile.sample_count());
409 } 409 }
410 410
411 // Turn on allocation tracing for A. 411 // Turn on allocation tracing for A.
412 class_a.SetTraceAllocation(true); 412 class_a.SetTraceAllocation(true);
413 413
414 // Allocate three times. 414 // Allocate three times.
415 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 415 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
416 EXPECT_VALID(result); 416 EXPECT_VALID(result);
417 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 417 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
418 EXPECT_VALID(result); 418 EXPECT_VALID(result);
419 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 419 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
420 EXPECT_VALID(result); 420 EXPECT_VALID(result);
421 421
422 { 422 {
423 Thread* thread = Thread::Current(); 423 Thread* thread = Thread::Current();
424 Isolate* isolate = thread->isolate(); 424 Isolate* isolate = thread->isolate();
425 StackZone zone(thread); 425 StackZone zone(thread);
426 HANDLESCOPE(thread); 426 HANDLESCOPE(thread);
427 Profile profile(isolate); 427 Profile profile(isolate);
428 AllocationFilter filter(isolate, class_a.id()); 428 AllocationFilter filter(isolate, class_a.id());
429 profile.Build(&filter, Profile::kNoTags); 429 profile.Build(thread, &filter, Profile::kNoTags);
430 // We should have three allocation samples. 430 // We should have three allocation samples.
431 EXPECT_EQ(3, profile.sample_count()); 431 EXPECT_EQ(3, profile.sample_count());
432 ProfileTrieWalker walker(&profile); 432 ProfileTrieWalker walker(&profile);
433 433
434 // Exclusive code: B.boo -> main. 434 // Exclusive code: B.boo -> main.
435 walker.Reset(Profile::kExclusiveCode); 435 walker.Reset(Profile::kExclusiveCode);
436 // Move down from the root. 436 // Move down from the root.
437 EXPECT(walker.Down()); 437 EXPECT(walker.Down());
438 EXPECT_STREQ("B.boo", walker.CurrentName()); 438 EXPECT_STREQ("B.boo", walker.CurrentName());
439 EXPECT_EQ(3, walker.CurrentNodeTickCount()); 439 EXPECT_EQ(3, walker.CurrentNodeTickCount());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 491 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
492 EXPECT_VALID(result); 492 EXPECT_VALID(result);
493 493
494 { 494 {
495 Thread* thread = Thread::Current(); 495 Thread* thread = Thread::Current();
496 Isolate* isolate = thread->isolate(); 496 Isolate* isolate = thread->isolate();
497 StackZone zone(thread); 497 StackZone zone(thread);
498 HANDLESCOPE(thread); 498 HANDLESCOPE(thread);
499 Profile profile(isolate); 499 Profile profile(isolate);
500 AllocationFilter filter(isolate, class_a.id()); 500 AllocationFilter filter(isolate, class_a.id());
501 profile.Build(&filter, Profile::kNoTags); 501 profile.Build(thread, &filter, Profile::kNoTags);
502 // We should have no allocation samples. 502 // We should have no allocation samples.
503 EXPECT_EQ(0, profile.sample_count()); 503 EXPECT_EQ(0, profile.sample_count());
504 } 504 }
505 505
506 // Turn on allocation tracing for A. 506 // Turn on allocation tracing for A.
507 class_a.SetTraceAllocation(true); 507 class_a.SetTraceAllocation(true);
508 508
509 // Allocate three times. 509 // Allocate three times.
510 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 510 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
511 EXPECT_VALID(result); 511 EXPECT_VALID(result);
512 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 512 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
513 EXPECT_VALID(result); 513 EXPECT_VALID(result);
514 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 514 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
515 EXPECT_VALID(result); 515 EXPECT_VALID(result);
516 516
517 { 517 {
518 Thread* thread = Thread::Current(); 518 Thread* thread = Thread::Current();
519 Isolate* isolate = thread->isolate(); 519 Isolate* isolate = thread->isolate();
520 StackZone zone(thread); 520 StackZone zone(thread);
521 HANDLESCOPE(thread); 521 HANDLESCOPE(thread);
522 Profile profile(isolate); 522 Profile profile(isolate);
523 AllocationFilter filter(isolate, class_a.id()); 523 AllocationFilter filter(isolate, class_a.id());
524 profile.Build(&filter, Profile::kNoTags); 524 profile.Build(thread, &filter, Profile::kNoTags);
525 // We should have three allocation samples. 525 // We should have three allocation samples.
526 EXPECT_EQ(3, profile.sample_count()); 526 EXPECT_EQ(3, profile.sample_count());
527 ProfileTrieWalker walker(&profile); 527 ProfileTrieWalker walker(&profile);
528 528
529 // Exclusive function: B.boo -> main. 529 // Exclusive function: B.boo -> main.
530 walker.Reset(Profile::kExclusiveFunction); 530 walker.Reset(Profile::kExclusiveFunction);
531 // Move down from the root. 531 // Move down from the root.
532 EXPECT(walker.Down()); 532 EXPECT(walker.Down());
533 EXPECT_STREQ("B.boo", walker.CurrentName()); 533 EXPECT_STREQ("B.boo", walker.CurrentName());
534 EXPECT_EQ(3, walker.CurrentNodeTickCount()); 534 EXPECT_EQ(3, walker.CurrentNodeTickCount());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 Dart_Handle args[2] = { Dart_NewDouble(1.0), Dart_NewDouble(2.0), }; 575 Dart_Handle args[2] = { Dart_NewDouble(1.0), Dart_NewDouble(2.0), };
576 576
577 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 577 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
578 EXPECT_VALID(result); 578 EXPECT_VALID(result);
579 579
580 { 580 {
581 StackZone zone(thread); 581 StackZone zone(thread);
582 HANDLESCOPE(thread); 582 HANDLESCOPE(thread);
583 Profile profile(isolate); 583 Profile profile(isolate);
584 AllocationFilter filter(isolate, double_class.id()); 584 AllocationFilter filter(isolate, double_class.id());
585 profile.Build(&filter, Profile::kNoTags); 585 profile.Build(thread, &filter, Profile::kNoTags);
586 // We should have no allocation samples. 586 // We should have no allocation samples.
587 EXPECT_EQ(0, profile.sample_count()); 587 EXPECT_EQ(0, profile.sample_count());
588 } 588 }
589 589
590 double_class.SetTraceAllocation(true); 590 double_class.SetTraceAllocation(true);
591 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 591 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
592 EXPECT_VALID(result); 592 EXPECT_VALID(result);
593 593
594 { 594 {
595 StackZone zone(thread); 595 StackZone zone(thread);
596 HANDLESCOPE(thread); 596 HANDLESCOPE(thread);
597 Profile profile(isolate); 597 Profile profile(isolate);
598 AllocationFilter filter(isolate, double_class.id()); 598 AllocationFilter filter(isolate, double_class.id());
599 profile.Build(&filter, Profile::kNoTags); 599 profile.Build(thread, &filter, Profile::kNoTags);
600 // We should have one allocation sample. 600 // We should have one allocation sample.
601 EXPECT_EQ(1, profile.sample_count()); 601 EXPECT_EQ(1, profile.sample_count());
602 ProfileTrieWalker walker(&profile); 602 ProfileTrieWalker walker(&profile);
603 603
604 walker.Reset(Profile::kExclusiveCode); 604 walker.Reset(Profile::kExclusiveCode);
605 EXPECT(walker.Down()); 605 EXPECT(walker.Down());
606 EXPECT_STREQ("_Double._add", walker.CurrentName()); 606 EXPECT_STREQ("_Double._add", walker.CurrentName());
607 EXPECT(walker.Down()); 607 EXPECT(walker.Down());
608 EXPECT_STREQ("_Double.+", walker.CurrentName()); 608 EXPECT_STREQ("_Double.+", walker.CurrentName());
609 EXPECT(walker.Down()); 609 EXPECT(walker.Down());
610 EXPECT_STREQ("foo", walker.CurrentName()); 610 EXPECT_STREQ("foo", walker.CurrentName());
611 EXPECT(!walker.Down()); 611 EXPECT(!walker.Down());
612 } 612 }
613 613
614 double_class.SetTraceAllocation(false); 614 double_class.SetTraceAllocation(false);
615 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 615 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
616 EXPECT_VALID(result); 616 EXPECT_VALID(result);
617 617
618 { 618 {
619 StackZone zone(thread); 619 StackZone zone(thread);
620 HANDLESCOPE(thread); 620 HANDLESCOPE(thread);
621 Profile profile(isolate); 621 Profile profile(isolate);
622 AllocationFilter filter(isolate, double_class.id()); 622 AllocationFilter filter(isolate, double_class.id());
623 profile.Build(&filter, Profile::kNoTags); 623 profile.Build(thread, &filter, Profile::kNoTags);
624 // We should still only have one allocation sample. 624 // We should still only have one allocation sample.
625 EXPECT_EQ(1, profile.sample_count()); 625 EXPECT_EQ(1, profile.sample_count());
626 } 626 }
627 } 627 }
628 628
629 629
630 TEST_CASE(Profiler_ArrayAllocation) { 630 TEST_CASE(Profiler_ArrayAllocation) {
631 DisableNativeProfileScope dnps; 631 DisableNativeProfileScope dnps;
632 const char* kScript = 632 const char* kScript =
633 "List foo() => new List(4);\n" 633 "List foo() => new List(4);\n"
634 "List bar() => new List();\n"; 634 "List bar() => new List();\n";
635 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 635 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
636 EXPECT_VALID(lib); 636 EXPECT_VALID(lib);
637 Library& root_library = Library::Handle(); 637 Library& root_library = Library::Handle();
638 root_library ^= Api::UnwrapHandle(lib); 638 root_library ^= Api::UnwrapHandle(lib);
639 Isolate* isolate = thread->isolate(); 639 Isolate* isolate = thread->isolate();
640 640
641 const Class& array_class = 641 const Class& array_class =
642 Class::Handle(isolate->object_store()->array_class()); 642 Class::Handle(isolate->object_store()->array_class());
643 EXPECT(!array_class.IsNull()); 643 EXPECT(!array_class.IsNull());
644 644
645 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 645 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
646 EXPECT_VALID(result); 646 EXPECT_VALID(result);
647 647
648 { 648 {
649 StackZone zone(thread); 649 StackZone zone(thread);
650 HANDLESCOPE(thread); 650 HANDLESCOPE(thread);
651 Profile profile(isolate); 651 Profile profile(isolate);
652 AllocationFilter filter(isolate, array_class.id()); 652 AllocationFilter filter(isolate, array_class.id());
653 profile.Build(&filter, Profile::kNoTags); 653 profile.Build(thread, &filter, Profile::kNoTags);
654 // We should have no allocation samples. 654 // We should have no allocation samples.
655 EXPECT_EQ(0, profile.sample_count()); 655 EXPECT_EQ(0, profile.sample_count());
656 } 656 }
657 657
658 array_class.SetTraceAllocation(true); 658 array_class.SetTraceAllocation(true);
659 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 659 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
660 EXPECT_VALID(result); 660 EXPECT_VALID(result);
661 661
662 { 662 {
663 StackZone zone(thread); 663 StackZone zone(thread);
664 HANDLESCOPE(thread); 664 HANDLESCOPE(thread);
665 Profile profile(isolate); 665 Profile profile(isolate);
666 AllocationFilter filter(isolate, array_class.id()); 666 AllocationFilter filter(isolate, array_class.id());
667 profile.Build(&filter, Profile::kNoTags); 667 profile.Build(thread, &filter, Profile::kNoTags);
668 // We should have one allocation sample. 668 // We should have one allocation sample.
669 EXPECT_EQ(1, profile.sample_count()); 669 EXPECT_EQ(1, profile.sample_count());
670 ProfileTrieWalker walker(&profile); 670 ProfileTrieWalker walker(&profile);
671 671
672 walker.Reset(Profile::kExclusiveCode); 672 walker.Reset(Profile::kExclusiveCode);
673 EXPECT(walker.Down()); 673 EXPECT(walker.Down());
674 EXPECT_STREQ("_List._List", walker.CurrentName()); 674 EXPECT_STREQ("_List._List", walker.CurrentName());
675 EXPECT(walker.Down()); 675 EXPECT(walker.Down());
676 EXPECT_STREQ("List.List", walker.CurrentName()); 676 EXPECT_STREQ("List.List", walker.CurrentName());
677 EXPECT(walker.Down()); 677 EXPECT(walker.Down());
678 EXPECT_STREQ("foo", walker.CurrentName()); 678 EXPECT_STREQ("foo", walker.CurrentName());
679 EXPECT(!walker.Down()); 679 EXPECT(!walker.Down());
680 } 680 }
681 681
682 array_class.SetTraceAllocation(false); 682 array_class.SetTraceAllocation(false);
683 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 683 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
684 EXPECT_VALID(result); 684 EXPECT_VALID(result);
685 685
686 { 686 {
687 StackZone zone(thread); 687 StackZone zone(thread);
688 HANDLESCOPE(thread); 688 HANDLESCOPE(thread);
689 Profile profile(isolate); 689 Profile profile(isolate);
690 AllocationFilter filter(isolate, array_class.id()); 690 AllocationFilter filter(isolate, array_class.id());
691 profile.Build(&filter, Profile::kNoTags); 691 profile.Build(thread, &filter, Profile::kNoTags);
692 // We should still only have one allocation sample. 692 // We should still only have one allocation sample.
693 EXPECT_EQ(1, profile.sample_count()); 693 EXPECT_EQ(1, profile.sample_count());
694 } 694 }
695 695
696 // Clear the samples. 696 // Clear the samples.
697 ProfilerService::ClearSamples(); 697 ProfilerService::ClearSamples();
698 698
699 // Compile bar (many List objects allocated). 699 // Compile bar (many List objects allocated).
700 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 700 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
701 EXPECT_VALID(result); 701 EXPECT_VALID(result);
702 702
703 // Enable again. 703 // Enable again.
704 array_class.SetTraceAllocation(true); 704 array_class.SetTraceAllocation(true);
705 705
706 // Run bar. 706 // Run bar.
707 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 707 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
708 EXPECT_VALID(result); 708 EXPECT_VALID(result);
709 709
710 { 710 {
711 StackZone zone(thread); 711 StackZone zone(thread);
712 HANDLESCOPE(thread); 712 HANDLESCOPE(thread);
713 Profile profile(isolate); 713 Profile profile(isolate);
714 AllocationFilter filter(isolate, array_class.id()); 714 AllocationFilter filter(isolate, array_class.id());
715 profile.Build(&filter, Profile::kNoTags); 715 profile.Build(thread, &filter, Profile::kNoTags);
716 // We should still only have one allocation sample. 716 // We should still only have one allocation sample.
717 EXPECT_EQ(1, profile.sample_count()); 717 EXPECT_EQ(1, profile.sample_count());
718 ProfileTrieWalker walker(&profile); 718 ProfileTrieWalker walker(&profile);
719 719
720 walker.Reset(Profile::kExclusiveCode); 720 walker.Reset(Profile::kExclusiveCode);
721 EXPECT(walker.Down()); 721 EXPECT(walker.Down());
722 EXPECT_STREQ("_List._List", walker.CurrentName()); 722 EXPECT_STREQ("_List._List", walker.CurrentName());
723 EXPECT(walker.Down()); 723 EXPECT(walker.Down());
724 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName()); 724 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName());
725 EXPECT(walker.Down()); 725 EXPECT(walker.Down());
(...skipping 24 matching lines...) Expand all
750 EXPECT(!context_class.IsNull()); 750 EXPECT(!context_class.IsNull());
751 751
752 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 752 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
753 EXPECT_VALID(result); 753 EXPECT_VALID(result);
754 754
755 { 755 {
756 StackZone zone(thread); 756 StackZone zone(thread);
757 HANDLESCOPE(thread); 757 HANDLESCOPE(thread);
758 Profile profile(isolate); 758 Profile profile(isolate);
759 AllocationFilter filter(isolate, context_class.id()); 759 AllocationFilter filter(isolate, context_class.id());
760 profile.Build(&filter, Profile::kNoTags); 760 profile.Build(thread, &filter, Profile::kNoTags);
761 // We should have no allocation samples. 761 // We should have no allocation samples.
762 EXPECT_EQ(0, profile.sample_count()); 762 EXPECT_EQ(0, profile.sample_count());
763 } 763 }
764 764
765 context_class.SetTraceAllocation(true); 765 context_class.SetTraceAllocation(true);
766 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 766 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
767 EXPECT_VALID(result); 767 EXPECT_VALID(result);
768 768
769 { 769 {
770 StackZone zone(thread); 770 StackZone zone(thread);
771 HANDLESCOPE(thread); 771 HANDLESCOPE(thread);
772 Profile profile(isolate); 772 Profile profile(isolate);
773 AllocationFilter filter(isolate, context_class.id()); 773 AllocationFilter filter(isolate, context_class.id());
774 profile.Build(&filter, Profile::kNoTags); 774 profile.Build(thread, &filter, Profile::kNoTags);
775 // We should have one allocation sample. 775 // We should have one allocation sample.
776 EXPECT_EQ(1, profile.sample_count()); 776 EXPECT_EQ(1, profile.sample_count());
777 ProfileTrieWalker walker(&profile); 777 ProfileTrieWalker walker(&profile);
778 778
779 walker.Reset(Profile::kExclusiveCode); 779 walker.Reset(Profile::kExclusiveCode);
780 EXPECT(walker.Down()); 780 EXPECT(walker.Down());
781 EXPECT_STREQ("foo", walker.CurrentName()); 781 EXPECT_STREQ("foo", walker.CurrentName());
782 EXPECT(!walker.Down()); 782 EXPECT(!walker.Down());
783 } 783 }
784 784
785 context_class.SetTraceAllocation(false); 785 context_class.SetTraceAllocation(false);
786 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 786 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
787 EXPECT_VALID(result); 787 EXPECT_VALID(result);
788 788
789 { 789 {
790 StackZone zone(thread); 790 StackZone zone(thread);
791 HANDLESCOPE(thread); 791 HANDLESCOPE(thread);
792 Profile profile(isolate); 792 Profile profile(isolate);
793 AllocationFilter filter(isolate, context_class.id()); 793 AllocationFilter filter(isolate, context_class.id());
794 profile.Build(&filter, Profile::kNoTags); 794 profile.Build(thread, &filter, Profile::kNoTags);
795 // We should still only have one allocation sample. 795 // We should still only have one allocation sample.
796 EXPECT_EQ(1, profile.sample_count()); 796 EXPECT_EQ(1, profile.sample_count());
797 } 797 }
798 } 798 }
799 799
800 800
801 TEST_CASE(Profiler_ClassAllocation) { 801 TEST_CASE(Profiler_ClassAllocation) {
802 DisableNativeProfileScope dnps; 802 DisableNativeProfileScope dnps;
803 const char* kScript = 803 const char* kScript =
804 "var msg1 = 'a';\n" 804 "var msg1 = 'a';\n"
(...skipping 23 matching lines...) Expand all
828 // Invoke "foo" which during compilation, triggers a closure class allocation. 828 // Invoke "foo" which during compilation, triggers a closure class allocation.
829 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 829 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
830 EXPECT_VALID(result); 830 EXPECT_VALID(result);
831 831
832 { 832 {
833 StackZone zone(thread); 833 StackZone zone(thread);
834 HANDLESCOPE(thread); 834 HANDLESCOPE(thread);
835 Profile profile(isolate); 835 Profile profile(isolate);
836 AllocationFilter filter(isolate, class_class.id()); 836 AllocationFilter filter(isolate, class_class.id());
837 filter.set_enable_embedder_ticks(true); 837 filter.set_enable_embedder_ticks(true);
838 profile.Build(&filter, Profile::kNoTags); 838 profile.Build(thread, &filter, Profile::kNoTags);
839 // We should have one allocation sample. 839 // We should have one allocation sample.
840 EXPECT_EQ(1, profile.sample_count()); 840 EXPECT_EQ(1, profile.sample_count());
841 ProfileTrieWalker walker(&profile); 841 ProfileTrieWalker walker(&profile);
842 842
843 walker.Reset(Profile::kExclusiveCode); 843 walker.Reset(Profile::kExclusiveCode);
844 EXPECT(walker.Down()); 844 EXPECT(walker.Down());
845 #if defined(TARGET_OS_WINDOWS) 845 #if defined(TARGET_OS_WINDOWS)
846 // TODO(johnmccutchan): Hookup native symbol resolver on Windows. 846 // TODO(johnmccutchan): Hookup native symbol resolver on Windows.
847 EXPECT_SUBSTRING("[Native]", walker.CurrentName()); 847 EXPECT_SUBSTRING("[Native]", walker.CurrentName());
848 #else 848 #else
849 EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName()); 849 EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName());
850 #endif 850 #endif
851 EXPECT(!walker.Down()); 851 EXPECT(!walker.Down());
852 } 852 }
853 853
854 // Disable allocation tracing for Class. 854 // Disable allocation tracing for Class.
855 class_class.SetTraceAllocation(false); 855 class_class.SetTraceAllocation(false);
856 856
857 // Invoke "bar" which during compilation, triggers a closure class allocation. 857 // Invoke "bar" which during compilation, triggers a closure class allocation.
858 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); 858 result = Dart_Invoke(lib, NewString("bar"), 0, NULL);
859 EXPECT_VALID(result); 859 EXPECT_VALID(result);
860 860
861 { 861 {
862 StackZone zone(thread); 862 StackZone zone(thread);
863 HANDLESCOPE(thread); 863 HANDLESCOPE(thread);
864 Profile profile(isolate); 864 Profile profile(isolate);
865 AllocationFilter filter(isolate, class_class.id()); 865 AllocationFilter filter(isolate, class_class.id());
866 filter.set_enable_embedder_ticks(true); 866 filter.set_enable_embedder_ticks(true);
867 profile.Build(&filter, Profile::kNoTags); 867 profile.Build(thread, &filter, Profile::kNoTags);
868 // We should still only have one allocation sample. 868 // We should still only have one allocation sample.
869 EXPECT_EQ(1, profile.sample_count()); 869 EXPECT_EQ(1, profile.sample_count());
870 } 870 }
871 } 871 }
872 872
873 873
874 TEST_CASE(Profiler_TypedArrayAllocation) { 874 TEST_CASE(Profiler_TypedArrayAllocation) {
875 DisableNativeProfileScope dnps; 875 DisableNativeProfileScope dnps;
876 const char* kScript = 876 const char* kScript =
877 "import 'dart:typed_data';\n" 877 "import 'dart:typed_data';\n"
(...skipping 12 matching lines...) Expand all
890 EXPECT(!float32_list_class.IsNull()); 890 EXPECT(!float32_list_class.IsNull());
891 891
892 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 892 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
893 EXPECT_VALID(result); 893 EXPECT_VALID(result);
894 894
895 { 895 {
896 StackZone zone(thread); 896 StackZone zone(thread);
897 HANDLESCOPE(thread); 897 HANDLESCOPE(thread);
898 Profile profile(isolate); 898 Profile profile(isolate);
899 AllocationFilter filter(isolate, float32_list_class.id()); 899 AllocationFilter filter(isolate, float32_list_class.id());
900 profile.Build(&filter, Profile::kNoTags); 900 profile.Build(thread, &filter, Profile::kNoTags);
901 // We should have no allocation samples. 901 // We should have no allocation samples.
902 EXPECT_EQ(0, profile.sample_count()); 902 EXPECT_EQ(0, profile.sample_count());
903 } 903 }
904 904
905 float32_list_class.SetTraceAllocation(true); 905 float32_list_class.SetTraceAllocation(true);
906 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 906 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
907 EXPECT_VALID(result); 907 EXPECT_VALID(result);
908 908
909 { 909 {
910 StackZone zone(thread); 910 StackZone zone(thread);
911 HANDLESCOPE(thread); 911 HANDLESCOPE(thread);
912 Profile profile(isolate); 912 Profile profile(isolate);
913 AllocationFilter filter(isolate, float32_list_class.id()); 913 AllocationFilter filter(isolate, float32_list_class.id());
914 profile.Build(&filter, Profile::kNoTags); 914 profile.Build(thread, &filter, Profile::kNoTags);
915 // We should have one allocation sample. 915 // We should have one allocation sample.
916 EXPECT_EQ(1, profile.sample_count()); 916 EXPECT_EQ(1, profile.sample_count());
917 ProfileTrieWalker walker(&profile); 917 ProfileTrieWalker walker(&profile);
918 918
919 walker.Reset(Profile::kExclusiveCode); 919 walker.Reset(Profile::kExclusiveCode);
920 EXPECT(walker.Down()); 920 EXPECT(walker.Down());
921 EXPECT_STREQ("_Float32Array._new", walker.CurrentName()); 921 EXPECT_STREQ("_Float32Array._new", walker.CurrentName());
922 EXPECT(walker.Down()); 922 EXPECT(walker.Down());
923 EXPECT_STREQ("_Float32Array._Float32Array", walker.CurrentName()); 923 EXPECT_STREQ("_Float32Array._Float32Array", walker.CurrentName());
924 EXPECT(walker.Down()); 924 EXPECT(walker.Down());
925 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName()); 925 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName());
926 EXPECT(walker.Down()); 926 EXPECT(walker.Down());
927 EXPECT_STREQ("foo", walker.CurrentName()); 927 EXPECT_STREQ("foo", walker.CurrentName());
928 EXPECT(!walker.Down()); 928 EXPECT(!walker.Down());
929 } 929 }
930 930
931 float32_list_class.SetTraceAllocation(false); 931 float32_list_class.SetTraceAllocation(false);
932 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 932 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
933 EXPECT_VALID(result); 933 EXPECT_VALID(result);
934 934
935 { 935 {
936 StackZone zone(thread); 936 StackZone zone(thread);
937 HANDLESCOPE(thread); 937 HANDLESCOPE(thread);
938 Profile profile(isolate); 938 Profile profile(isolate);
939 AllocationFilter filter(isolate, float32_list_class.id()); 939 AllocationFilter filter(isolate, float32_list_class.id());
940 profile.Build(&filter, Profile::kNoTags); 940 profile.Build(thread, &filter, Profile::kNoTags);
941 // We should still only have one allocation sample. 941 // We should still only have one allocation sample.
942 EXPECT_EQ(1, profile.sample_count()); 942 EXPECT_EQ(1, profile.sample_count());
943 } 943 }
944 944
945 float32_list_class.SetTraceAllocation(true); 945 float32_list_class.SetTraceAllocation(true);
946 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); 946 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
947 EXPECT_VALID(result); 947 EXPECT_VALID(result);
948 948
949 { 949 {
950 StackZone zone(thread); 950 StackZone zone(thread);
951 HANDLESCOPE(thread); 951 HANDLESCOPE(thread);
952 Profile profile(isolate); 952 Profile profile(isolate);
953 AllocationFilter filter(isolate, float32_list_class.id()); 953 AllocationFilter filter(isolate, float32_list_class.id());
954 profile.Build(&filter, Profile::kNoTags); 954 profile.Build(thread, &filter, Profile::kNoTags);
955 // We should now have two allocation samples. 955 // We should now have two allocation samples.
956 EXPECT_EQ(2, profile.sample_count()); 956 EXPECT_EQ(2, profile.sample_count());
957 } 957 }
958 } 958 }
959 959
960 960
961 TEST_CASE(Profiler_StringAllocation) { 961 TEST_CASE(Profiler_StringAllocation) {
962 DisableNativeProfileScope dnps; 962 DisableNativeProfileScope dnps;
963 const char* kScript = "String foo(String a, String b) => a + b;"; 963 const char* kScript = "String foo(String a, String b) => a + b;";
964 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 964 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
965 EXPECT_VALID(lib); 965 EXPECT_VALID(lib);
966 Library& root_library = Library::Handle(); 966 Library& root_library = Library::Handle();
967 root_library ^= Api::UnwrapHandle(lib); 967 root_library ^= Api::UnwrapHandle(lib);
968 Isolate* isolate = thread->isolate(); 968 Isolate* isolate = thread->isolate();
969 969
970 const Class& one_byte_string_class = 970 const Class& one_byte_string_class =
971 Class::Handle(isolate->object_store()->one_byte_string_class()); 971 Class::Handle(isolate->object_store()->one_byte_string_class());
972 EXPECT(!one_byte_string_class.IsNull()); 972 EXPECT(!one_byte_string_class.IsNull());
973 973
974 Dart_Handle args[2] = { NewString("a"), NewString("b"), }; 974 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
975 975
976 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 976 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
977 EXPECT_VALID(result); 977 EXPECT_VALID(result);
978 978
979 { 979 {
980 StackZone zone(thread); 980 StackZone zone(thread);
981 HANDLESCOPE(thread); 981 HANDLESCOPE(thread);
982 Profile profile(isolate); 982 Profile profile(isolate);
983 AllocationFilter filter(isolate, one_byte_string_class.id()); 983 AllocationFilter filter(isolate, one_byte_string_class.id());
984 profile.Build(&filter, Profile::kNoTags); 984 profile.Build(thread, &filter, Profile::kNoTags);
985 // We should have no allocation samples. 985 // We should have no allocation samples.
986 EXPECT_EQ(0, profile.sample_count()); 986 EXPECT_EQ(0, profile.sample_count());
987 } 987 }
988 988
989 one_byte_string_class.SetTraceAllocation(true); 989 one_byte_string_class.SetTraceAllocation(true);
990 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 990 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
991 EXPECT_VALID(result); 991 EXPECT_VALID(result);
992 992
993 { 993 {
994 StackZone zone(thread); 994 StackZone zone(thread);
995 HANDLESCOPE(thread); 995 HANDLESCOPE(thread);
996 Profile profile(isolate); 996 Profile profile(isolate);
997 AllocationFilter filter(isolate, one_byte_string_class.id()); 997 AllocationFilter filter(isolate, one_byte_string_class.id());
998 profile.Build(&filter, Profile::kNoTags); 998 profile.Build(thread, &filter, Profile::kNoTags);
999 // We should still only have one allocation sample. 999 // We should still only have one allocation sample.
1000 EXPECT_EQ(1, profile.sample_count()); 1000 EXPECT_EQ(1, profile.sample_count());
1001 ProfileTrieWalker walker(&profile); 1001 ProfileTrieWalker walker(&profile);
1002 1002
1003 walker.Reset(Profile::kExclusiveCode); 1003 walker.Reset(Profile::kExclusiveCode);
1004 EXPECT(walker.Down()); 1004 EXPECT(walker.Down());
1005 EXPECT_STREQ("_StringBase.+", walker.CurrentName()); 1005 EXPECT_STREQ("_StringBase.+", walker.CurrentName());
1006 EXPECT(walker.Down()); 1006 EXPECT(walker.Down());
1007 EXPECT_STREQ("foo", walker.CurrentName()); 1007 EXPECT_STREQ("foo", walker.CurrentName());
1008 EXPECT(!walker.Down()); 1008 EXPECT(!walker.Down());
1009 } 1009 }
1010 1010
1011 one_byte_string_class.SetTraceAllocation(false); 1011 one_byte_string_class.SetTraceAllocation(false);
1012 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1012 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1013 EXPECT_VALID(result); 1013 EXPECT_VALID(result);
1014 1014
1015 { 1015 {
1016 StackZone zone(thread); 1016 StackZone zone(thread);
1017 HANDLESCOPE(thread); 1017 HANDLESCOPE(thread);
1018 Profile profile(isolate); 1018 Profile profile(isolate);
1019 AllocationFilter filter(isolate, one_byte_string_class.id()); 1019 AllocationFilter filter(isolate, one_byte_string_class.id());
1020 profile.Build(&filter, Profile::kNoTags); 1020 profile.Build(thread, &filter, Profile::kNoTags);
1021 // We should still only have one allocation sample. 1021 // We should still only have one allocation sample.
1022 EXPECT_EQ(1, profile.sample_count()); 1022 EXPECT_EQ(1, profile.sample_count());
1023 } 1023 }
1024 1024
1025 one_byte_string_class.SetTraceAllocation(true); 1025 one_byte_string_class.SetTraceAllocation(true);
1026 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1026 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1027 EXPECT_VALID(result); 1027 EXPECT_VALID(result);
1028 1028
1029 { 1029 {
1030 StackZone zone(thread); 1030 StackZone zone(thread);
1031 HANDLESCOPE(thread); 1031 HANDLESCOPE(thread);
1032 Profile profile(isolate); 1032 Profile profile(isolate);
1033 AllocationFilter filter(isolate, one_byte_string_class.id()); 1033 AllocationFilter filter(isolate, one_byte_string_class.id());
1034 profile.Build(&filter, Profile::kNoTags); 1034 profile.Build(thread, &filter, Profile::kNoTags);
1035 // We should now have two allocation samples. 1035 // We should now have two allocation samples.
1036 EXPECT_EQ(2, profile.sample_count()); 1036 EXPECT_EQ(2, profile.sample_count());
1037 } 1037 }
1038 } 1038 }
1039 1039
1040 1040
1041 TEST_CASE(Profiler_StringInterpolation) { 1041 TEST_CASE(Profiler_StringInterpolation) {
1042 DisableNativeProfileScope dnps; 1042 DisableNativeProfileScope dnps;
1043 const char* kScript = "String foo(String a, String b) => '$a | $b';"; 1043 const char* kScript = "String foo(String a, String b) => '$a | $b';";
1044 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 1044 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1045 EXPECT_VALID(lib); 1045 EXPECT_VALID(lib);
1046 Library& root_library = Library::Handle(); 1046 Library& root_library = Library::Handle();
1047 root_library ^= Api::UnwrapHandle(lib); 1047 root_library ^= Api::UnwrapHandle(lib);
1048 Isolate* isolate = thread->isolate(); 1048 Isolate* isolate = thread->isolate();
1049 1049
1050 const Class& one_byte_string_class = 1050 const Class& one_byte_string_class =
1051 Class::Handle(isolate->object_store()->one_byte_string_class()); 1051 Class::Handle(isolate->object_store()->one_byte_string_class());
1052 EXPECT(!one_byte_string_class.IsNull()); 1052 EXPECT(!one_byte_string_class.IsNull());
1053 1053
1054 Dart_Handle args[2] = { NewString("a"), NewString("b"), }; 1054 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
1055 1055
1056 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1056 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1057 EXPECT_VALID(result); 1057 EXPECT_VALID(result);
1058 1058
1059 { 1059 {
1060 StackZone zone(thread); 1060 StackZone zone(thread);
1061 HANDLESCOPE(thread); 1061 HANDLESCOPE(thread);
1062 Profile profile(isolate); 1062 Profile profile(isolate);
1063 AllocationFilter filter(isolate, one_byte_string_class.id()); 1063 AllocationFilter filter(isolate, one_byte_string_class.id());
1064 profile.Build(&filter, Profile::kNoTags); 1064 profile.Build(thread, &filter, Profile::kNoTags);
1065 // We should have no allocation samples. 1065 // We should have no allocation samples.
1066 EXPECT_EQ(0, profile.sample_count()); 1066 EXPECT_EQ(0, profile.sample_count());
1067 } 1067 }
1068 1068
1069 one_byte_string_class.SetTraceAllocation(true); 1069 one_byte_string_class.SetTraceAllocation(true);
1070 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1070 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1071 EXPECT_VALID(result); 1071 EXPECT_VALID(result);
1072 1072
1073 { 1073 {
1074 StackZone zone(thread); 1074 StackZone zone(thread);
1075 HANDLESCOPE(thread); 1075 HANDLESCOPE(thread);
1076 Profile profile(isolate); 1076 Profile profile(isolate);
1077 AllocationFilter filter(isolate, one_byte_string_class.id()); 1077 AllocationFilter filter(isolate, one_byte_string_class.id());
1078 profile.Build(&filter, Profile::kNoTags); 1078 profile.Build(thread, &filter, Profile::kNoTags);
1079 // We should still only have one allocation sample. 1079 // We should still only have one allocation sample.
1080 EXPECT_EQ(1, profile.sample_count()); 1080 EXPECT_EQ(1, profile.sample_count());
1081 ProfileTrieWalker walker(&profile); 1081 ProfileTrieWalker walker(&profile);
1082 1082
1083 walker.Reset(Profile::kExclusiveCode); 1083 walker.Reset(Profile::kExclusiveCode);
1084 EXPECT(walker.Down()); 1084 EXPECT(walker.Down());
1085 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName()); 1085 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName());
1086 EXPECT(walker.Down()); 1086 EXPECT(walker.Down());
1087 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName()); 1087 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName());
1088 EXPECT(walker.Down()); 1088 EXPECT(walker.Down());
1089 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName()); 1089 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName());
1090 EXPECT(walker.Down()); 1090 EXPECT(walker.Down());
1091 EXPECT_STREQ("foo", walker.CurrentName()); 1091 EXPECT_STREQ("foo", walker.CurrentName());
1092 EXPECT(!walker.Down()); 1092 EXPECT(!walker.Down());
1093 } 1093 }
1094 1094
1095 one_byte_string_class.SetTraceAllocation(false); 1095 one_byte_string_class.SetTraceAllocation(false);
1096 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1096 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1097 EXPECT_VALID(result); 1097 EXPECT_VALID(result);
1098 1098
1099 { 1099 {
1100 StackZone zone(thread); 1100 StackZone zone(thread);
1101 HANDLESCOPE(thread); 1101 HANDLESCOPE(thread);
1102 Profile profile(isolate); 1102 Profile profile(isolate);
1103 AllocationFilter filter(isolate, one_byte_string_class.id()); 1103 AllocationFilter filter(isolate, one_byte_string_class.id());
1104 profile.Build(&filter, Profile::kNoTags); 1104 profile.Build(thread, &filter, Profile::kNoTags);
1105 // We should still only have one allocation sample. 1105 // We should still only have one allocation sample.
1106 EXPECT_EQ(1, profile.sample_count()); 1106 EXPECT_EQ(1, profile.sample_count());
1107 } 1107 }
1108 1108
1109 one_byte_string_class.SetTraceAllocation(true); 1109 one_byte_string_class.SetTraceAllocation(true);
1110 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); 1110 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
1111 EXPECT_VALID(result); 1111 EXPECT_VALID(result);
1112 1112
1113 { 1113 {
1114 StackZone zone(thread); 1114 StackZone zone(thread);
1115 HANDLESCOPE(thread); 1115 HANDLESCOPE(thread);
1116 Profile profile(isolate); 1116 Profile profile(isolate);
1117 AllocationFilter filter(isolate, one_byte_string_class.id()); 1117 AllocationFilter filter(isolate, one_byte_string_class.id());
1118 profile.Build(&filter, Profile::kNoTags); 1118 profile.Build(thread, &filter, Profile::kNoTags);
1119 // We should now have two allocation samples. 1119 // We should now have two allocation samples.
1120 EXPECT_EQ(2, profile.sample_count()); 1120 EXPECT_EQ(2, profile.sample_count());
1121 } 1121 }
1122 } 1122 }
1123 1123
1124 1124
1125 TEST_CASE(Profiler_FunctionInline) { 1125 TEST_CASE(Profiler_FunctionInline) {
1126 DisableNativeProfileScope dnps; 1126 DisableNativeProfileScope dnps;
1127 const char* kScript = 1127 const char* kScript =
1128 "class A {\n" 1128 "class A {\n"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 EXPECT_VALID(result); 1166 EXPECT_VALID(result);
1167 // At this point B.boo should be optimized and inlined B.foo and B.choo. 1167 // At this point B.boo should be optimized and inlined B.foo and B.choo.
1168 1168
1169 { 1169 {
1170 Thread* thread = Thread::Current(); 1170 Thread* thread = Thread::Current();
1171 Isolate* isolate = thread->isolate(); 1171 Isolate* isolate = thread->isolate();
1172 StackZone zone(thread); 1172 StackZone zone(thread);
1173 HANDLESCOPE(thread); 1173 HANDLESCOPE(thread);
1174 Profile profile(isolate); 1174 Profile profile(isolate);
1175 AllocationFilter filter(isolate, class_a.id()); 1175 AllocationFilter filter(isolate, class_a.id());
1176 profile.Build(&filter, Profile::kNoTags); 1176 profile.Build(thread, &filter, Profile::kNoTags);
1177 // We should have no allocation samples. 1177 // We should have no allocation samples.
1178 EXPECT_EQ(0, profile.sample_count()); 1178 EXPECT_EQ(0, profile.sample_count());
1179 } 1179 }
1180 1180
1181 // Turn on allocation tracing for A. 1181 // Turn on allocation tracing for A.
1182 class_a.SetTraceAllocation(true); 1182 class_a.SetTraceAllocation(true);
1183 1183
1184 // Allocate 50,000 instances of A. 1184 // Allocate 50,000 instances of A.
1185 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL); 1185 result = Dart_Invoke(lib, NewString("mainA"), 0, NULL);
1186 EXPECT_VALID(result); 1186 EXPECT_VALID(result);
1187 1187
1188 { 1188 {
1189 Thread* thread = Thread::Current(); 1189 Thread* thread = Thread::Current();
1190 Isolate* isolate = thread->isolate(); 1190 Isolate* isolate = thread->isolate();
1191 StackZone zone(thread); 1191 StackZone zone(thread);
1192 HANDLESCOPE(thread); 1192 HANDLESCOPE(thread);
1193 Profile profile(isolate); 1193 Profile profile(isolate);
1194 AllocationFilter filter(isolate, class_a.id()); 1194 AllocationFilter filter(isolate, class_a.id());
1195 profile.Build(&filter, Profile::kNoTags); 1195 profile.Build(thread, &filter, Profile::kNoTags);
1196 // We should have 50,000 allocation samples. 1196 // We should have 50,000 allocation samples.
1197 EXPECT_EQ(50000, profile.sample_count()); 1197 EXPECT_EQ(50000, profile.sample_count());
1198 ProfileTrieWalker walker(&profile); 1198 ProfileTrieWalker walker(&profile);
1199 // We have two code objects: mainA and B.boo. 1199 // We have two code objects: mainA and B.boo.
1200 walker.Reset(Profile::kExclusiveCode); 1200 walker.Reset(Profile::kExclusiveCode);
1201 EXPECT(walker.Down()); 1201 EXPECT(walker.Down());
1202 EXPECT_STREQ("B.boo", walker.CurrentName()); 1202 EXPECT_STREQ("B.boo", walker.CurrentName());
1203 EXPECT_EQ(1, walker.SiblingCount()); 1203 EXPECT_EQ(1, walker.SiblingCount());
1204 EXPECT_EQ(50000, walker.CurrentNodeTickCount()); 1204 EXPECT_EQ(50000, walker.CurrentNodeTickCount());
1205 EXPECT_EQ(50000, walker.CurrentInclusiveTicks()); 1205 EXPECT_EQ(50000, walker.CurrentInclusiveTicks());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 } 1287 }
1288 1288
1289 // Test code transition tags. 1289 // Test code transition tags.
1290 { 1290 {
1291 Thread* thread = Thread::Current(); 1291 Thread* thread = Thread::Current();
1292 Isolate* isolate = thread->isolate(); 1292 Isolate* isolate = thread->isolate();
1293 StackZone zone(thread); 1293 StackZone zone(thread);
1294 HANDLESCOPE(thread); 1294 HANDLESCOPE(thread);
1295 Profile profile(isolate); 1295 Profile profile(isolate);
1296 AllocationFilter filter(isolate, class_a.id()); 1296 AllocationFilter filter(isolate, class_a.id());
1297 profile.Build(&filter, 1297 profile.Build(thread,
1298 &filter,
1298 Profile::kNoTags, 1299 Profile::kNoTags,
1299 ProfilerService::kCodeTransitionTagsBit); 1300 ProfilerService::kCodeTransitionTagsBit);
1300 // We should have 50,000 allocation samples. 1301 // We should have 50,000 allocation samples.
1301 EXPECT_EQ(50000, profile.sample_count()); 1302 EXPECT_EQ(50000, profile.sample_count());
1302 ProfileTrieWalker walker(&profile); 1303 ProfileTrieWalker walker(&profile);
1303 // We have two code objects: mainA and B.boo. 1304 // We have two code objects: mainA and B.boo.
1304 walker.Reset(Profile::kExclusiveCode); 1305 walker.Reset(Profile::kExclusiveCode);
1305 EXPECT(walker.Down()); 1306 EXPECT(walker.Down());
1306 EXPECT_STREQ("B.boo", walker.CurrentName()); 1307 EXPECT_STREQ("B.boo", walker.CurrentName());
1307 EXPECT(walker.Down()); 1308 EXPECT(walker.Down());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 EXPECT_VALID(result); 1420 EXPECT_VALID(result);
1420 1421
1421 1422
1422 { 1423 {
1423 Thread* thread = Thread::Current(); 1424 Thread* thread = Thread::Current();
1424 Isolate* isolate = thread->isolate(); 1425 Isolate* isolate = thread->isolate();
1425 StackZone zone(thread); 1426 StackZone zone(thread);
1426 HANDLESCOPE(thread); 1427 HANDLESCOPE(thread);
1427 Profile profile(isolate); 1428 Profile profile(isolate);
1428 AllocationFilter filter(isolate, class_a.id()); 1429 AllocationFilter filter(isolate, class_a.id());
1429 profile.Build(&filter, Profile::kNoTags); 1430 profile.Build(thread, &filter, Profile::kNoTags);
1430 // We should have 1 allocation sample. 1431 // We should have 1 allocation sample.
1431 EXPECT_EQ(1, profile.sample_count()); 1432 EXPECT_EQ(1, profile.sample_count());
1432 ProfileTrieWalker walker(&profile); 1433 ProfileTrieWalker walker(&profile);
1433 1434
1434 walker.Reset(Profile::kExclusiveCode); 1435 walker.Reset(Profile::kExclusiveCode);
1435 // Move down from the root. 1436 // Move down from the root.
1436 EXPECT(walker.Down()); 1437 EXPECT(walker.Down());
1437 EXPECT_STREQ("B.boo", walker.CurrentName()); 1438 EXPECT_STREQ("B.boo", walker.CurrentName());
1438 EXPECT(walker.Down()); 1439 EXPECT(walker.Down());
1439 EXPECT_STREQ("orange", walker.CurrentName()); 1440 EXPECT_STREQ("orange", walker.CurrentName());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 EXPECT(walker.Down()); 1473 EXPECT(walker.Down());
1473 EXPECT_STREQ("go", walker.CurrentName()); 1474 EXPECT_STREQ("go", walker.CurrentName());
1474 EXPECT(walker.Down()); 1475 EXPECT(walker.Down());
1475 EXPECT_STREQ("main", walker.CurrentName()); 1476 EXPECT_STREQ("main", walker.CurrentName());
1476 EXPECT(!walker.Down()); 1477 EXPECT(!walker.Down());
1477 } 1478 }
1478 } 1479 }
1479 1480
1480 } // namespace dart 1481 } // namespace dart
1481 1482
OLDNEW
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698