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

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

Issue 1230063010: Test tracing of string allocations (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | no next file » | 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 StackZone zone(isolate); 562 StackZone zone(isolate);
563 HANDLESCOPE(isolate); 563 HANDLESCOPE(isolate);
564 Profile profile(isolate); 564 Profile profile(isolate);
565 AllocationFilter filter(isolate, float32_list_class.id()); 565 AllocationFilter filter(isolate, float32_list_class.id());
566 profile.Build(&filter, Profile::kNoTags); 566 profile.Build(&filter, Profile::kNoTags);
567 // We should now have two allocation samples. 567 // We should now have two allocation samples.
568 EXPECT_EQ(2, profile.sample_count()); 568 EXPECT_EQ(2, profile.sample_count());
569 } 569 }
570 } 570 }
571 571
572
573 TEST_CASE(Profiler_StringAllocation) {
574 const char* kScript = "String foo(String a, String b) => a + b;";
575 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
576 EXPECT_VALID(lib);
577 Library& root_library = Library::Handle();
578 root_library ^= Api::UnwrapHandle(lib);
579 Isolate* isolate = Isolate::Current();
580
581 const Class& one_byte_string_class =
582 Class::Handle(isolate->object_store()->one_byte_string_class());
583 EXPECT(!one_byte_string_class.IsNull());
584
585 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
586
587 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
588 EXPECT_VALID(result);
589
590 {
591 StackZone zone(isolate);
592 HANDLESCOPE(isolate);
593 Profile profile(isolate);
594 AllocationFilter filter(isolate, one_byte_string_class.id());
595 profile.Build(&filter, Profile::kNoTags);
596 // We should have no allocation samples.
597 EXPECT_EQ(0, profile.sample_count());
598 }
599
600 one_byte_string_class.SetTraceAllocation(true);
601 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
602 EXPECT_VALID(result);
603
604 {
605 StackZone zone(isolate);
606 HANDLESCOPE(isolate);
607 Profile profile(isolate);
608 AllocationFilter filter(isolate, one_byte_string_class.id());
609 profile.Build(&filter, Profile::kNoTags);
610 // We should still only have one allocation sample.
611 EXPECT_EQ(1, profile.sample_count());
612 ProfileTrieWalker walker(&profile);
613
614 walker.Reset(Profile::kExclusiveCode);
615 EXPECT(walker.Down());
616 EXPECT_STREQ("_StringBase.+", walker.CurrentName());
617 EXPECT(walker.Down());
618 EXPECT_STREQ("foo", walker.CurrentName());
619 EXPECT(!walker.Down());
620 }
621
622 one_byte_string_class.SetTraceAllocation(false);
623 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
624 EXPECT_VALID(result);
625
626 {
627 StackZone zone(isolate);
628 HANDLESCOPE(isolate);
629 Profile profile(isolate);
630 AllocationFilter filter(isolate, one_byte_string_class.id());
631 profile.Build(&filter, Profile::kNoTags);
632 // We should still only have one allocation sample.
633 EXPECT_EQ(1, profile.sample_count());
634 }
635
636 one_byte_string_class.SetTraceAllocation(true);
637 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
638 EXPECT_VALID(result);
639
640 {
641 StackZone zone(isolate);
642 HANDLESCOPE(isolate);
643 Profile profile(isolate);
644 AllocationFilter filter(isolate, one_byte_string_class.id());
645 profile.Build(&filter, Profile::kNoTags);
646 // We should now have two allocation samples.
647 EXPECT_EQ(2, profile.sample_count());
648 }
649 }
650
651
652 TEST_CASE(Profiler_StringInterpolation) {
653 const char* kScript = "String foo(String a, String b) => '$a | $b';";
654 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
655 EXPECT_VALID(lib);
656 Library& root_library = Library::Handle();
657 root_library ^= Api::UnwrapHandle(lib);
658 Isolate* isolate = Isolate::Current();
659
660 const Class& one_byte_string_class =
661 Class::Handle(isolate->object_store()->one_byte_string_class());
662 EXPECT(!one_byte_string_class.IsNull());
663
664 Dart_Handle args[2] = { NewString("a"), NewString("b"), };
665
666 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
667 EXPECT_VALID(result);
668
669 {
670 StackZone zone(isolate);
671 HANDLESCOPE(isolate);
672 Profile profile(isolate);
673 AllocationFilter filter(isolate, one_byte_string_class.id());
674 profile.Build(&filter, Profile::kNoTags);
675 // We should have no allocation samples.
676 EXPECT_EQ(0, profile.sample_count());
677 }
678
679 one_byte_string_class.SetTraceAllocation(true);
680 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
681 EXPECT_VALID(result);
682
683 {
684 StackZone zone(isolate);
685 HANDLESCOPE(isolate);
686 Profile profile(isolate);
687 AllocationFilter filter(isolate, one_byte_string_class.id());
688 profile.Build(&filter, Profile::kNoTags);
689 // We should still only have one allocation sample.
690 EXPECT_EQ(1, profile.sample_count());
691 ProfileTrieWalker walker(&profile);
692
693 walker.Reset(Profile::kExclusiveCode);
694 EXPECT(walker.Down());
695 EXPECT_STREQ("_OneByteString._allocate", walker.CurrentName());
696 EXPECT(walker.Down());
697 EXPECT_STREQ("_OneByteString._concatAll", walker.CurrentName());
698 EXPECT(walker.Down());
699 EXPECT_STREQ("_StringBase._interpolate", walker.CurrentName());
700 EXPECT(walker.Down());
701 EXPECT_STREQ("foo", walker.CurrentName());
702 EXPECT(!walker.Down());
703 }
704
705 one_byte_string_class.SetTraceAllocation(false);
706 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
707 EXPECT_VALID(result);
708
709 {
710 StackZone zone(isolate);
711 HANDLESCOPE(isolate);
712 Profile profile(isolate);
713 AllocationFilter filter(isolate, one_byte_string_class.id());
714 profile.Build(&filter, Profile::kNoTags);
715 // We should still only have one allocation sample.
716 EXPECT_EQ(1, profile.sample_count());
717 }
718
719 one_byte_string_class.SetTraceAllocation(true);
720 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]);
721 EXPECT_VALID(result);
722
723 {
724 StackZone zone(isolate);
725 HANDLESCOPE(isolate);
726 Profile profile(isolate);
727 AllocationFilter filter(isolate, one_byte_string_class.id());
728 profile.Build(&filter, Profile::kNoTags);
729 // We should now have two allocation samples.
730 EXPECT_EQ(2, profile.sample_count());
731 }
732 }
733
572 } // namespace dart 734 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698