OLD | NEW |
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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 StackZone zone(isolate); | 306 StackZone zone(isolate); |
307 HANDLESCOPE(isolate); | 307 HANDLESCOPE(isolate); |
308 Profile profile(isolate); | 308 Profile profile(isolate); |
309 AllocationFilter filter(isolate, class_a.id()); | 309 AllocationFilter filter(isolate, class_a.id()); |
310 profile.Build(&filter, Profile::kNoTags); | 310 profile.Build(&filter, Profile::kNoTags); |
311 // We should still only have one allocation sample. | 311 // We should still only have one allocation sample. |
312 EXPECT_EQ(1, profile.sample_count()); | 312 EXPECT_EQ(1, profile.sample_count()); |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
| 316 |
| 317 TEST_CASE(Profiler_IntrinsicAllocation) { |
| 318 const char* kScript = "double foo(double a, double b) => a + b;"; |
| 319 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 320 EXPECT_VALID(lib); |
| 321 Library& root_library = Library::Handle(); |
| 322 root_library ^= Api::UnwrapHandle(lib); |
| 323 Isolate* isolate = Isolate::Current(); |
| 324 |
| 325 const Class& double_class = |
| 326 Class::Handle(isolate->object_store()->double_class()); |
| 327 EXPECT(!double_class.IsNull()); |
| 328 |
| 329 Dart_Handle args[2] = { Dart_NewDouble(1.0), Dart_NewDouble(2.0), }; |
| 330 |
| 331 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 332 EXPECT_VALID(result); |
| 333 |
| 334 { |
| 335 StackZone zone(isolate); |
| 336 HANDLESCOPE(isolate); |
| 337 Profile profile(isolate); |
| 338 AllocationFilter filter(isolate, double_class.id()); |
| 339 profile.Build(&filter, Profile::kNoTags); |
| 340 // We should have no allocation samples. |
| 341 EXPECT_EQ(0, profile.sample_count()); |
| 342 } |
| 343 |
| 344 double_class.SetTraceAllocation(true); |
| 345 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 346 EXPECT_VALID(result); |
| 347 |
| 348 { |
| 349 StackZone zone(isolate); |
| 350 HANDLESCOPE(isolate); |
| 351 Profile profile(isolate); |
| 352 AllocationFilter filter(isolate, double_class.id()); |
| 353 profile.Build(&filter, Profile::kNoTags); |
| 354 // We should have one allocation sample. |
| 355 EXPECT_EQ(1, profile.sample_count()); |
| 356 ProfileTrieWalker walker(&profile); |
| 357 |
| 358 walker.Reset(Profile::kExclusiveCode); |
| 359 EXPECT(walker.Down()); |
| 360 EXPECT_STREQ("_Double._add", walker.CurrentName()); |
| 361 EXPECT(walker.Down()); |
| 362 EXPECT_STREQ("_Double.+", walker.CurrentName()); |
| 363 EXPECT(walker.Down()); |
| 364 EXPECT_STREQ("foo", walker.CurrentName()); |
| 365 EXPECT(!walker.Down()); |
| 366 } |
| 367 |
| 368 double_class.SetTraceAllocation(false); |
| 369 result = Dart_Invoke(lib, NewString("foo"), 2, &args[0]); |
| 370 EXPECT_VALID(result); |
| 371 |
| 372 { |
| 373 StackZone zone(isolate); |
| 374 HANDLESCOPE(isolate); |
| 375 Profile profile(isolate); |
| 376 AllocationFilter filter(isolate, double_class.id()); |
| 377 profile.Build(&filter, Profile::kNoTags); |
| 378 // We should still only have one allocation sample. |
| 379 EXPECT_EQ(1, profile.sample_count()); |
| 380 } |
| 381 } |
| 382 |
316 } // namespace dart | 383 } // namespace dart |
OLD | NEW |