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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/profiler_service.cc ('K') | « runtime/vm/profiler_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/profiler_test.cc
diff --git a/runtime/vm/profiler_test.cc b/runtime/vm/profiler_test.cc
index f2bd9f5767911537bbd113e97f4a8a0ad5f4f8a6..9b6cfaf4fa63eb19b42e84d068a5d47950930efa 100644
--- a/runtime/vm/profiler_test.cc
+++ b/runtime/vm/profiler_test.cc
@@ -406,6 +406,98 @@ TEST_CASE(Profiler_CodeTicks) {
}
+TEST_CASE(Profiler_FunctionTicks) {
+ const char* kScript =
+ "class A {\n"
+ " var a;\n"
+ " var b;\n"
+ "}\n"
+ "class B {\n"
+ " static boo() {\n"
+ " return new A();\n"
+ " }\n"
+ "}\n"
+ "main() {\n"
+ " B.boo();\n"
+ "}\n";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ Library& root_library = Library::Handle();
+ root_library ^= Api::UnwrapHandle(lib);
+
+ const Class& class_a = Class::Handle(GetClass(root_library, "A"));
+ EXPECT(!class_a.IsNull());
+
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+
+ {
+ Isolate* isolate = Isolate::Current();
+ StackZone zone(isolate);
+ HANDLESCOPE(isolate);
+ Profile profile(isolate);
+ AllocationFilter filter(isolate, class_a.id());
+ profile.Build(&filter, Profile::kNoTags);
+ // We should have no allocation samples.
+ EXPECT_EQ(0, profile.sample_count());
+ }
+
+ // Turn on allocation tracing for A.
+ class_a.SetTraceAllocation(true);
+
+ // Allocate three times.
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+
+ {
+ Isolate* isolate = Isolate::Current();
+ StackZone zone(isolate);
+ HANDLESCOPE(isolate);
+ Profile profile(isolate);
+ AllocationFilter filter(isolate, class_a.id());
+ profile.Build(&filter, Profile::kNoTags);
+ // We should have one allocation sample.
rmacnak 2015/07/28 20:35:27 one -> three
+ EXPECT_EQ(3, profile.sample_count());
+ ProfileTrieWalker walker(&profile);
+
+ // Exclusive function: B.boo -> main.
+ walker.Reset(Profile::kExclusiveFunction);
+ // Move down from the root.
+ EXPECT(walker.Down());
+ EXPECT_STREQ("B.boo", walker.CurrentName());
+ EXPECT_EQ(3, walker.CurrentNodeTickCount());
+ EXPECT_EQ(3, walker.CurrentInclusiveTicks());
+ EXPECT_EQ(3, walker.CurrentExclusiveTicks());
+ EXPECT(walker.Down());
+ EXPECT_STREQ("main", walker.CurrentName());
+ EXPECT_EQ(3, walker.CurrentNodeTickCount());
+ EXPECT_EQ(3, walker.CurrentInclusiveTicks());
+ EXPECT_EQ(0, walker.CurrentExclusiveTicks());
+ EXPECT(!walker.Down());
+
+ // Inclusive function: main -> B.boo.
+ walker.Reset(Profile::kInclusiveFunction);
+ // Move down from the root.
+ EXPECT(walker.Down());
+ EXPECT_STREQ("main", walker.CurrentName());
+ EXPECT_EQ(3, walker.CurrentNodeTickCount());
+ EXPECT_EQ(3, walker.CurrentInclusiveTicks());
+ EXPECT_EQ(0, walker.CurrentExclusiveTicks());
+ EXPECT(walker.Down());
+ EXPECT_STREQ("B.boo", walker.CurrentName());
+ EXPECT_EQ(3, walker.CurrentNodeTickCount());
+ EXPECT_EQ(3, walker.CurrentInclusiveTicks());
+ EXPECT_EQ(3, walker.CurrentExclusiveTicks());
+ EXPECT(!walker.Down());
+ }
+}
+
+
TEST_CASE(Profiler_IntrinsicAllocation) {
const char* kScript = "double foo(double a, double b) => a + b;";
Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
« 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