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

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

Issue 1215773002: Fix allocation stub switching (Closed) Base URL: git@github.com:dart-lang/sdk.git@allocation_profile_test
Patch Set: Created 5 years, 6 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/object.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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 walker.Reset(Profile::kInclusiveFunction); 195 walker.Reset(Profile::kInclusiveFunction);
196 // Move down from the root. 196 // Move down from the root.
197 EXPECT(walker.Down()); 197 EXPECT(walker.Down());
198 EXPECT_STREQ("main", walker.CurrentName()); 198 EXPECT_STREQ("main", walker.CurrentName());
199 EXPECT(walker.Down()); 199 EXPECT(walker.Down());
200 EXPECT_STREQ("B.boo", walker.CurrentName()); 200 EXPECT_STREQ("B.boo", walker.CurrentName());
201 EXPECT(!walker.Down()); 201 EXPECT(!walker.Down());
202 } 202 }
203 } 203 }
204 204
205
206 TEST_CASE(Profiler_ToggleRecordAllocation) {
207 const char* kScript =
208 "class A {\n"
209 " var a;\n"
210 " var b;\n"
211 "}\n"
212 "class B {\n"
213 " static boo() {\n"
214 " return new A();\n"
215 " }\n"
216 "}\n"
217 "main() {\n"
218 " return B.boo();\n"
219 "}\n";
220
221 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
222 EXPECT_VALID(lib);
223 Library& root_library = Library::Handle();
224 root_library ^= Api::UnwrapHandle(lib);
225
226 const Class& class_a = Class::Handle(GetClass(root_library, "A"));
227 EXPECT(!class_a.IsNull());
228
229 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
230 EXPECT_VALID(result);
231
232
233 {
234 Isolate* isolate = Isolate::Current();
235 StackZone zone(isolate);
236 HANDLESCOPE(isolate);
237 Profile profile(isolate);
238 AllocationFilter filter(isolate, class_a.id());
239 profile.Build(&filter, Profile::kNoTags);
240 // We should have no allocation samples.
241 EXPECT_EQ(0, profile.sample_count());
242 }
243
244 // Turn on allocation tracing for A.
245 class_a.SetTraceAllocation(true);
246
247 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
248 EXPECT_VALID(result);
249
250 {
251 Isolate* isolate = Isolate::Current();
252 StackZone zone(isolate);
253 HANDLESCOPE(isolate);
254 Profile profile(isolate);
255 AllocationFilter filter(isolate, class_a.id());
256 profile.Build(&filter, Profile::kNoTags);
257 // We should have one allocation sample.
258 EXPECT_EQ(1, profile.sample_count());
259 ProfileTrieWalker walker(&profile);
260
261 // Exclusive code: B.boo -> main.
262 walker.Reset(Profile::kExclusiveCode);
263 // Move down from the root.
264 EXPECT(walker.Down());
265 EXPECT_STREQ("B.boo", walker.CurrentName());
266 EXPECT(walker.Down());
267 EXPECT_STREQ("main", walker.CurrentName());
268 EXPECT(!walker.Down());
269
270 // Inclusive code: main -> B.boo.
271 walker.Reset(Profile::kInclusiveCode);
272 // Move down from the root.
273 EXPECT(walker.Down());
274 EXPECT_STREQ("main", walker.CurrentName());
275 EXPECT(walker.Down());
276 EXPECT_STREQ("B.boo", walker.CurrentName());
277 EXPECT(!walker.Down());
278
279 // Exclusive function: boo -> main.
280 walker.Reset(Profile::kExclusiveFunction);
281 // Move down from the root.
282 EXPECT(walker.Down());
283 EXPECT_STREQ("boo", walker.CurrentName());
284 EXPECT(walker.Down());
285 EXPECT_STREQ("main", walker.CurrentName());
286 EXPECT(!walker.Down());
287
288 // Inclusive function: main -> boo.
289 walker.Reset(Profile::kInclusiveFunction);
290 // Move down from the root.
291 EXPECT(walker.Down());
292 EXPECT_STREQ("main", walker.CurrentName());
293 EXPECT(walker.Down());
294 EXPECT_STREQ("boo", walker.CurrentName());
295 EXPECT(!walker.Down());
296 }
297
298 // Turn off allocation tracing for A.
299 class_a.SetTraceAllocation(false);
300
301 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
302 EXPECT_VALID(result);
303
304 {
305 Isolate* isolate = Isolate::Current();
306 StackZone zone(isolate);
307 HANDLESCOPE(isolate);
308 Profile profile(isolate);
309 AllocationFilter filter(isolate, class_a.id());
310 profile.Build(&filter, Profile::kNoTags);
311 // We should still only have one allocation sample.
312 EXPECT_EQ(1, profile.sample_count());
313 }
314 }
315
205 } // namespace dart 316 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698