 Chromium Code Reviews
 Chromium Code Reviews Issue 1297693003:
  More allocation tracing unit tests  (Closed) 
  Base URL: git@github.com:dart-lang/sdk.git@master
    
  
    Issue 1297693003:
  More allocation tracing unit tests  (Closed) 
  Base URL: git@github.com:dart-lang/sdk.git@master| Index: runtime/vm/profiler_test.cc | 
| diff --git a/runtime/vm/profiler_test.cc b/runtime/vm/profiler_test.cc | 
| index f0472db3328d2b1bacd74eeda1efc90eeb1803c9..a306802cefedefca748d4a4da1f430c99c755407 100644 | 
| --- a/runtime/vm/profiler_test.cc | 
| +++ b/runtime/vm/profiler_test.cc | 
| @@ -693,6 +693,130 @@ TEST_CASE(Profiler_ArrayAllocation) { | 
| } | 
| +TEST_CASE(Profiler_ContextAllocation) { | 
| + DisableNativeProfileScope dnps; | 
| + const char* kScript = | 
| + "var msg1 = 'a';\n" | 
| + "foo() {\n" | 
| + " var msg = msg1 + msg1;\n" | 
| + " return (x) { return '$msg + $msg'; }(msg);\n" | 
| + "}\n"; | 
| + Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
| + EXPECT_VALID(lib); | 
| + Library& root_library = Library::Handle(); | 
| + root_library ^= Api::UnwrapHandle(lib); | 
| + Isolate* isolate = Isolate::Current(); | 
| + | 
| + const Class& context_class = | 
| + Class::Handle(Object::context_class()); | 
| + EXPECT(!context_class.IsNull()); | 
| + | 
| + Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 
| + EXPECT_VALID(result); | 
| + | 
| + { | 
| + StackZone zone(isolate); | 
| + HANDLESCOPE(isolate); | 
| + Profile profile(isolate); | 
| + AllocationFilter filter(isolate, context_class.id()); | 
| + profile.Build(&filter, Profile::kNoTags); | 
| + // We should have no allocation samples. | 
| + EXPECT_EQ(0, profile.sample_count()); | 
| + } | 
| + | 
| + context_class.SetTraceAllocation(true); | 
| + result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 
| + EXPECT_VALID(result); | 
| + | 
| + { | 
| + StackZone zone(isolate); | 
| + HANDLESCOPE(isolate); | 
| + Profile profile(isolate); | 
| + AllocationFilter filter(isolate, context_class.id()); | 
| + profile.Build(&filter, Profile::kNoTags); | 
| + // We should have one allocation sample. | 
| + EXPECT_EQ(1, profile.sample_count()); | 
| + ProfileTrieWalker walker(&profile); | 
| + | 
| + walker.Reset(Profile::kExclusiveCode); | 
| + EXPECT(walker.Down()); | 
| + EXPECT_STREQ("foo", walker.CurrentName()); | 
| + EXPECT(!walker.Down()); | 
| + } | 
| + | 
| + context_class.SetTraceAllocation(false); | 
| + result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 
| + EXPECT_VALID(result); | 
| + | 
| + { | 
| + StackZone zone(isolate); | 
| + HANDLESCOPE(isolate); | 
| + Profile profile(isolate); | 
| + AllocationFilter filter(isolate, context_class.id()); | 
| + profile.Build(&filter, Profile::kNoTags); | 
| + // We should still only have one allocation sample. | 
| + EXPECT_EQ(1, profile.sample_count()); | 
| + } | 
| +} | 
| + | 
| + | 
| +TEST_CASE(Profiler_ClassAllocation) { | 
| + DisableNativeProfileScope dnps; | 
| + const char* kScript = | 
| + "var msg1 = 'a';\n" | 
| + "\n" | 
| + "foo() {\n" | 
| + " var msg = msg1 + msg1;\n" | 
| + " var msg2 = msg + msg;\n" | 
| + " return (x, y, z, w) { return '$x + $y + $z'; }(msg, msg2, msg, msg);\n" | 
| + "}\n"; | 
| + Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
| + EXPECT_VALID(lib); | 
| + Library& root_library = Library::Handle(); | 
| + root_library ^= Api::UnwrapHandle(lib); | 
| + Isolate* isolate = Isolate::Current(); | 
| + | 
| + const Class& class_class = | 
| + Class::Handle(Object::class_class()); | 
| + EXPECT(!class_class.IsNull()); | 
| + class_class.SetTraceAllocation(true); | 
| + | 
| + // Invoke "foo" which during compilation, triggers a closure class allocation. | 
| + Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 
| + EXPECT_VALID(result); | 
| + | 
| + { | 
| + StackZone zone(isolate); | 
| + HANDLESCOPE(isolate); | 
| + Profile profile(isolate); | 
| + AllocationFilter filter(isolate, class_class.id()); | 
| + profile.Build(&filter, Profile::kNoTags); | 
| + // We should have one allocation sample. | 
| + EXPECT_EQ(1, profile.sample_count()); | 
| + ProfileTrieWalker walker(&profile); | 
| + | 
| + walker.Reset(Profile::kExclusiveCode); | 
| + EXPECT(walker.Down()); | 
| + EXPECT_SUBSTRING("dart::Profiler::RecordAllocation", walker.CurrentName()); | 
| + EXPECT(!walker.Down()); | 
| + } | 
| + | 
| + class_class.SetTraceAllocation(false); | 
| + result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 
| 
Ivan Posva
2015/08/15 13:16:48
You need to trigger a second class allocation here
 
Cutch
2015/08/17 14:05:12
Done.
 | 
| + EXPECT_VALID(result); | 
| + | 
| + { | 
| + StackZone zone(isolate); | 
| + HANDLESCOPE(isolate); | 
| + Profile profile(isolate); | 
| + AllocationFilter filter(isolate, class_class.id()); | 
| + profile.Build(&filter, Profile::kNoTags); | 
| + // We should still only have one allocation sample. | 
| + EXPECT_EQ(1, profile.sample_count()); | 
| + } | 
| +} | 
| + | 
| + | 
| TEST_CASE(Profiler_TypedArrayAllocation) { | 
| DisableNativeProfileScope dnps; | 
| const char* kScript = |