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

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

Issue 1297693003: More allocation tracing unit tests (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/profiler.cc ('k') | 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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName()); 686 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName());
687 EXPECT(walker.Down()); 687 EXPECT(walker.Down());
688 EXPECT_STREQ("List.List", walker.CurrentName()); 688 EXPECT_STREQ("List.List", walker.CurrentName());
689 EXPECT(walker.Down()); 689 EXPECT(walker.Down());
690 EXPECT_STREQ("bar", walker.CurrentName()); 690 EXPECT_STREQ("bar", walker.CurrentName());
691 EXPECT(!walker.Down()); 691 EXPECT(!walker.Down());
692 } 692 }
693 } 693 }
694 694
695 695
696 TEST_CASE(Profiler_ContextAllocation) {
697 DisableNativeProfileScope dnps;
698 const char* kScript =
699 "var msg1 = 'a';\n"
700 "foo() {\n"
701 " var msg = msg1 + msg1;\n"
702 " return (x) { return '$msg + $msg'; }(msg);\n"
703 "}\n";
704 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
705 EXPECT_VALID(lib);
706 Library& root_library = Library::Handle();
707 root_library ^= Api::UnwrapHandle(lib);
708 Isolate* isolate = Isolate::Current();
709
710 const Class& context_class =
711 Class::Handle(Object::context_class());
712 EXPECT(!context_class.IsNull());
713
714 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
715 EXPECT_VALID(result);
716
717 {
718 StackZone zone(isolate);
719 HANDLESCOPE(isolate);
720 Profile profile(isolate);
721 AllocationFilter filter(isolate, context_class.id());
722 profile.Build(&filter, Profile::kNoTags);
723 // We should have no allocation samples.
724 EXPECT_EQ(0, profile.sample_count());
725 }
726
727 context_class.SetTraceAllocation(true);
728 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
729 EXPECT_VALID(result);
730
731 {
732 StackZone zone(isolate);
733 HANDLESCOPE(isolate);
734 Profile profile(isolate);
735 AllocationFilter filter(isolate, context_class.id());
736 profile.Build(&filter, Profile::kNoTags);
737 // We should have one allocation sample.
738 EXPECT_EQ(1, profile.sample_count());
739 ProfileTrieWalker walker(&profile);
740
741 walker.Reset(Profile::kExclusiveCode);
742 EXPECT(walker.Down());
743 EXPECT_STREQ("foo", walker.CurrentName());
744 EXPECT(!walker.Down());
745 }
746
747 context_class.SetTraceAllocation(false);
748 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
749 EXPECT_VALID(result);
750
751 {
752 StackZone zone(isolate);
753 HANDLESCOPE(isolate);
754 Profile profile(isolate);
755 AllocationFilter filter(isolate, context_class.id());
756 profile.Build(&filter, Profile::kNoTags);
757 // We should still only have one allocation sample.
758 EXPECT_EQ(1, profile.sample_count());
759 }
760 }
761
762
763 TEST_CASE(Profiler_ClassAllocation) {
764 DisableNativeProfileScope dnps;
765 const char* kScript =
766 "var msg1 = 'a';\n"
767 "\n"
768 "foo() {\n"
769 " var msg = msg1 + msg1;\n"
770 " var msg2 = msg + msg;\n"
771 " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n"
772 "}\n";
773 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
774 EXPECT_VALID(lib);
775 Library& root_library = Library::Handle();
776 root_library ^= Api::UnwrapHandle(lib);
777 Isolate* isolate = Isolate::Current();
778
779 const Class& class_class =
780 Class::Handle(Object::class_class());
781 EXPECT(!class_class.IsNull());
782 class_class.SetTraceAllocation(true);
783
784 // Invoke "foo" which during compilation, triggers a closure class allocation.
785 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
786 EXPECT_VALID(result);
787
788 {
789 StackZone zone(isolate);
790 HANDLESCOPE(isolate);
791 Profile profile(isolate);
792 AllocationFilter filter(isolate, class_class.id());
793 profile.Build(&filter, Profile::kNoTags);
794 // We should have one allocation sample.
795 EXPECT_EQ(1, profile.sample_count());
796 ProfileTrieWalker walker(&profile);
797
798 walker.Reset(Profile::kExclusiveCode);
799 EXPECT(walker.Down());
800 EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName());
801 EXPECT(!walker.Down());
802 }
803
804 class_class.SetTraceAllocation(false);
805 result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
Ivan Posva 2015/08/15 13:16:48 You need to trigger a second class allocation here
Cutch 2015/08/17 14:05:12 Done.
806 EXPECT_VALID(result);
807
808 {
809 StackZone zone(isolate);
810 HANDLESCOPE(isolate);
811 Profile profile(isolate);
812 AllocationFilter filter(isolate, class_class.id());
813 profile.Build(&filter, Profile::kNoTags);
814 // We should still only have one allocation sample.
815 EXPECT_EQ(1, profile.sample_count());
816 }
817 }
818
819
696 TEST_CASE(Profiler_TypedArrayAllocation) { 820 TEST_CASE(Profiler_TypedArrayAllocation) {
697 DisableNativeProfileScope dnps; 821 DisableNativeProfileScope dnps;
698 const char* kScript = 822 const char* kScript =
699 "import 'dart:typed_data';\n" 823 "import 'dart:typed_data';\n"
700 "List foo() => new Float32List(4);\n"; 824 "List foo() => new Float32List(4);\n";
701 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 825 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
702 EXPECT_VALID(lib); 826 EXPECT_VALID(lib);
703 Library& root_library = Library::Handle(); 827 Library& root_library = Library::Handle();
704 root_library ^= Api::UnwrapHandle(lib); 828 root_library ^= Api::UnwrapHandle(lib);
705 Isolate* isolate = Isolate::Current(); 829 Isolate* isolate = Isolate::Current();
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 EXPECT(walker.Down()); 1305 EXPECT(walker.Down());
1182 EXPECT_STREQ("B.choo", walker.CurrentName()); 1306 EXPECT_STREQ("B.choo", walker.CurrentName());
1183 EXPECT(walker.Down()); 1307 EXPECT(walker.Down());
1184 EXPECT_STREQ("[Inline End]", walker.CurrentName()); 1308 EXPECT_STREQ("[Inline End]", walker.CurrentName());
1185 EXPECT(!walker.Down()); 1309 EXPECT(!walker.Down());
1186 } 1310 }
1187 } 1311 }
1188 1312
1189 } // namespace dart 1313 } // namespace dart
1190 1314
OLDNEW
« no previous file with comments | « runtime/vm/profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698