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

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

Issue 1210283003: Extend allocation profile testing (Closed) Base URL: git@github.com:dart-lang/sdk.git@profile_model_public
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/profiler_service.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/profiler.h" 10 #include "vm/profiler.h"
11 #include "vm/profiler_service.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 class ProfileSampleBufferTestHelper { 16 class ProfileSampleBufferTestHelper {
16 public: 17 public:
17 static intptr_t IterateCount(const Isolate* isolate, 18 static intptr_t IterateCount(const Isolate* isolate,
18 const SampleBuffer& sample_buffer) { 19 const SampleBuffer& sample_buffer) {
19 intptr_t c = 0; 20 intptr_t c = 0;
20 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { 21 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 102 }
102 103
103 static RawClass* GetClass(const Library& lib, const char* name) { 104 static RawClass* GetClass(const Library& lib, const char* name) {
104 const Class& cls = Class::Handle( 105 const Class& cls = Class::Handle(
105 lib.LookupClass(String::Handle(Symbols::New(name)))); 106 lib.LookupClass(String::Handle(Symbols::New(name))));
106 EXPECT(!cls.IsNull()); // No ambiguity error expected. 107 EXPECT(!cls.IsNull()); // No ambiguity error expected.
107 return cls.raw(); 108 return cls.raw();
108 } 109 }
109 110
110 111
112 class AllocationFilter : public SampleFilter {
113 public:
114 explicit AllocationFilter(Isolate* isolate, intptr_t cid)
115 : SampleFilter(isolate),
116 cid_(cid) {
117 }
118
119 bool FilterSample(Sample* sample) {
120 return sample->is_allocation_sample() && (sample->allocation_cid() == cid_);
121 }
122
123 private:
124 intptr_t cid_;
125 };
126
127
111 TEST_CASE(Profiler_TrivialRecordAllocation) { 128 TEST_CASE(Profiler_TrivialRecordAllocation) {
112 const char* kScript = 129 const char* kScript =
113 "class A {\n" 130 "class A {\n"
114 " var a;\n" 131 " var a;\n"
115 " var b;\n" 132 " var b;\n"
116 "}\n" 133 "}\n"
134 "class B {\n"
135 " static boo() {\n"
136 " return new A();\n"
137 " }\n"
138 "}\n"
117 "main() {\n" 139 "main() {\n"
118 " var z = new A();\n" 140 " return B.boo();\n"
119 " return z;\n"
120 "}\n"; 141 "}\n";
121 142
122 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 143 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
123 EXPECT_VALID(lib); 144 EXPECT_VALID(lib);
124 Library& root_library = Library::Handle(); 145 Library& root_library = Library::Handle();
125 root_library ^= Api::UnwrapHandle(lib); 146 root_library ^= Api::UnwrapHandle(lib);
126 147
127 const Class& class_a = Class::Handle(GetClass(root_library, "A")); 148 const Class& class_a = Class::Handle(GetClass(root_library, "A"));
128 EXPECT(!class_a.IsNull()); 149 EXPECT(!class_a.IsNull());
129 class_a.SetTraceAllocation(true); 150 class_a.SetTraceAllocation(true);
130 151
131 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 152 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
132 EXPECT_VALID(result); 153 EXPECT_VALID(result);
154
155
156 {
157 Isolate* isolate = Isolate::Current();
158 StackZone zone(isolate);
159 HANDLESCOPE(isolate);
160 Profile profile(isolate);
161 AllocationFilter filter(isolate, class_a.id());
162 profile.Build(&filter, Profile::kNoTags);
163 // We should have 1 allocation sample.
164 EXPECT_EQ(1, profile.sample_count());
165 ProfileTrieWalker walker(&profile);
166
167 // Exclusive code: B.boo -> main.
168 walker.Reset(Profile::kExclusiveCode);
169 // Move down from the root.
170 EXPECT(walker.Down());
171 EXPECT_STREQ("B.boo", walker.CurrentName());
172 EXPECT(walker.Down());
173 EXPECT_STREQ("main", walker.CurrentName());
174 EXPECT(!walker.Down());
175
176 // Inclusive code: main -> B.boo.
177 walker.Reset(Profile::kInclusiveCode);
178 // Move down from the root.
179 EXPECT(walker.Down());
180 EXPECT_STREQ("main", walker.CurrentName());
181 EXPECT(walker.Down());
182 EXPECT_STREQ("B.boo", walker.CurrentName());
183 EXPECT(!walker.Down());
184
185 // Exclusive function: B.boo -> main.
186 walker.Reset(Profile::kExclusiveFunction);
187 // Move down from the root.
188 EXPECT(walker.Down());
189 EXPECT_STREQ("B.boo", walker.CurrentName());
190 EXPECT(walker.Down());
191 EXPECT_STREQ("main", walker.CurrentName());
192 EXPECT(!walker.Down());
193
194 // Inclusive function: main -> B.boo.
195 walker.Reset(Profile::kInclusiveFunction);
196 // Move down from the root.
197 EXPECT(walker.Down());
198 EXPECT_STREQ("main", walker.CurrentName());
199 EXPECT(walker.Down());
200 EXPECT_STREQ("B.boo", walker.CurrentName());
201 EXPECT(!walker.Down());
202 }
133 } 203 }
134 204
135 } // namespace dart 205 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698