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

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

Issue 1261963002: Refactor function tick code and add test (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
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 EXPECT(walker.Down()); 399 EXPECT(walker.Down());
400 EXPECT_STREQ("B.boo", walker.CurrentName()); 400 EXPECT_STREQ("B.boo", walker.CurrentName());
401 EXPECT_EQ(3, walker.CurrentNodeTickCount()); 401 EXPECT_EQ(3, walker.CurrentNodeTickCount());
402 EXPECT_EQ(3, walker.CurrentInclusiveTicks()); 402 EXPECT_EQ(3, walker.CurrentInclusiveTicks());
403 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); 403 EXPECT_EQ(3, walker.CurrentExclusiveTicks());
404 EXPECT(!walker.Down()); 404 EXPECT(!walker.Down());
405 } 405 }
406 } 406 }
407 407
408 408
409 TEST_CASE(Profiler_FunctionTicks) {
410 const char* kScript =
411 "class A {\n"
412 " var a;\n"
413 " var b;\n"
414 "}\n"
415 "class B {\n"
416 " static boo() {\n"
417 " return new A();\n"
418 " }\n"
419 "}\n"
420 "main() {\n"
421 " B.boo();\n"
422 "}\n";
423
424 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
425 EXPECT_VALID(lib);
426 Library& root_library = Library::Handle();
427 root_library ^= Api::UnwrapHandle(lib);
428
429 const Class& class_a = Class::Handle(GetClass(root_library, "A"));
430 EXPECT(!class_a.IsNull());
431
432 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
433 EXPECT_VALID(result);
434
435 {
436 Isolate* isolate = Isolate::Current();
437 StackZone zone(isolate);
438 HANDLESCOPE(isolate);
439 Profile profile(isolate);
440 AllocationFilter filter(isolate, class_a.id());
441 profile.Build(&filter, Profile::kNoTags);
442 // We should have no allocation samples.
443 EXPECT_EQ(0, profile.sample_count());
444 }
445
446 // Turn on allocation tracing for A.
447 class_a.SetTraceAllocation(true);
448
449 // Allocate three times.
450 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
451 EXPECT_VALID(result);
452 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
453 EXPECT_VALID(result);
454 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
455 EXPECT_VALID(result);
456
457 {
458 Isolate* isolate = Isolate::Current();
459 StackZone zone(isolate);
460 HANDLESCOPE(isolate);
461 Profile profile(isolate);
462 AllocationFilter filter(isolate, class_a.id());
463 profile.Build(&filter, Profile::kNoTags);
464 // We should have one allocation sample.
rmacnak 2015/07/28 20:35:27 one -> three
465 EXPECT_EQ(3, profile.sample_count());
466 ProfileTrieWalker walker(&profile);
467
468 // Exclusive function: B.boo -> main.
469 walker.Reset(Profile::kExclusiveFunction);
470 // Move down from the root.
471 EXPECT(walker.Down());
472 EXPECT_STREQ("B.boo", walker.CurrentName());
473 EXPECT_EQ(3, walker.CurrentNodeTickCount());
474 EXPECT_EQ(3, walker.CurrentInclusiveTicks());
475 EXPECT_EQ(3, walker.CurrentExclusiveTicks());
476 EXPECT(walker.Down());
477 EXPECT_STREQ("main", walker.CurrentName());
478 EXPECT_EQ(3, walker.CurrentNodeTickCount());
479 EXPECT_EQ(3, walker.CurrentInclusiveTicks());
480 EXPECT_EQ(0, walker.CurrentExclusiveTicks());
481 EXPECT(!walker.Down());
482
483 // Inclusive function: main -> B.boo.
484 walker.Reset(Profile::kInclusiveFunction);
485 // Move down from the root.
486 EXPECT(walker.Down());
487 EXPECT_STREQ("main", walker.CurrentName());
488 EXPECT_EQ(3, walker.CurrentNodeTickCount());
489 EXPECT_EQ(3, walker.CurrentInclusiveTicks());
490 EXPECT_EQ(0, walker.CurrentExclusiveTicks());
491 EXPECT(walker.Down());
492 EXPECT_STREQ("B.boo", walker.CurrentName());
493 EXPECT_EQ(3, walker.CurrentNodeTickCount());
494 EXPECT_EQ(3, walker.CurrentInclusiveTicks());
495 EXPECT_EQ(3, walker.CurrentExclusiveTicks());
496 EXPECT(!walker.Down());
497 }
498 }
499
500
409 TEST_CASE(Profiler_IntrinsicAllocation) { 501 TEST_CASE(Profiler_IntrinsicAllocation) {
410 const char* kScript = "double foo(double a, double b) => a + b;"; 502 const char* kScript = "double foo(double a, double b) => a + b;";
411 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 503 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
412 EXPECT_VALID(lib); 504 EXPECT_VALID(lib);
413 Library& root_library = Library::Handle(); 505 Library& root_library = Library::Handle();
414 root_library ^= Api::UnwrapHandle(lib); 506 root_library ^= Api::UnwrapHandle(lib);
415 Isolate* isolate = Isolate::Current(); 507 Isolate* isolate = Isolate::Current();
416 508
417 const Class& double_class = 509 const Class& double_class =
418 Class::Handle(isolate->object_store()->double_class()); 510 Class::Handle(isolate->object_store()->double_class());
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 HANDLESCOPE(isolate); 909 HANDLESCOPE(isolate);
818 Profile profile(isolate); 910 Profile profile(isolate);
819 AllocationFilter filter(isolate, one_byte_string_class.id()); 911 AllocationFilter filter(isolate, one_byte_string_class.id());
820 profile.Build(&filter, Profile::kNoTags); 912 profile.Build(&filter, Profile::kNoTags);
821 // We should now have two allocation samples. 913 // We should now have two allocation samples.
822 EXPECT_EQ(2, profile.sample_count()); 914 EXPECT_EQ(2, profile.sample_count());
823 } 915 }
824 } 916 }
825 917
826 } // namespace dart 918 } // namespace dart
OLDNEW
« runtime/vm/profiler_service.cc ('K') | « runtime/vm/profiler_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698