| Index: runtime/vm/profiler_test.cc | 
| diff --git a/runtime/vm/profiler_test.cc b/runtime/vm/profiler_test.cc | 
| index e35d2e952d8d05cc0b5db6d5c29c3cb2483683e3..b634c1b72ef94797af44840435f0a3f635004335 100644 | 
| --- a/runtime/vm/profiler_test.cc | 
| +++ b/runtime/vm/profiler_test.cc | 
| @@ -202,4 +202,115 @@ TEST_CASE(Profiler_TrivialRecordAllocation) { | 
| } | 
| } | 
|  | 
| + | 
| +TEST_CASE(Profiler_ToggleRecordAllocation) { | 
| +  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" | 
| +      "  return 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); | 
| + | 
| +  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. | 
| +    EXPECT_EQ(1, profile.sample_count()); | 
| +    ProfileTrieWalker walker(&profile); | 
| + | 
| +    // Exclusive code: B.boo -> main. | 
| +    walker.Reset(Profile::kExclusiveCode); | 
| +    // Move down from the root. | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("B.boo", walker.CurrentName()); | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("main", walker.CurrentName()); | 
| +    EXPECT(!walker.Down()); | 
| + | 
| +    // Inclusive code: main -> B.boo. | 
| +    walker.Reset(Profile::kInclusiveCode); | 
| +    // Move down from the root. | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("main", walker.CurrentName()); | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("B.boo", walker.CurrentName()); | 
| +    EXPECT(!walker.Down()); | 
| + | 
| +    // Exclusive function: boo -> main. | 
| +    walker.Reset(Profile::kExclusiveFunction); | 
| +    // Move down from the root. | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("boo", walker.CurrentName()); | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("main", walker.CurrentName()); | 
| +    EXPECT(!walker.Down()); | 
| + | 
| +    // Inclusive function: main -> boo. | 
| +    walker.Reset(Profile::kInclusiveFunction); | 
| +    // Move down from the root. | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("main", walker.CurrentName()); | 
| +    EXPECT(walker.Down()); | 
| +    EXPECT_STREQ("boo", walker.CurrentName()); | 
| +    EXPECT(!walker.Down()); | 
| +  } | 
| + | 
| +  // Turn off allocation tracing for A. | 
| +  class_a.SetTraceAllocation(false); | 
| + | 
| +  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 still only have one allocation sample. | 
| +    EXPECT_EQ(1, profile.sample_count()); | 
| +  } | 
| +} | 
| + | 
| }  // namespace dart | 
|  |