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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 StackZone zone(isolate); | 373 StackZone zone(isolate); |
374 HANDLESCOPE(isolate); | 374 HANDLESCOPE(isolate); |
375 Profile profile(isolate); | 375 Profile profile(isolate); |
376 AllocationFilter filter(isolate, double_class.id()); | 376 AllocationFilter filter(isolate, double_class.id()); |
377 profile.Build(&filter, Profile::kNoTags); | 377 profile.Build(&filter, Profile::kNoTags); |
378 // We should still only have one allocation sample. | 378 // We should still only have one allocation sample. |
379 EXPECT_EQ(1, profile.sample_count()); | 379 EXPECT_EQ(1, profile.sample_count()); |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
| 383 |
| 384 TEST_CASE(Profiler_ArrayAllocation) { |
| 385 const char* kScript = |
| 386 "List foo() => new List(4);\n" |
| 387 "List bar() => new List();\n"; |
| 388 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 389 EXPECT_VALID(lib); |
| 390 Library& root_library = Library::Handle(); |
| 391 root_library ^= Api::UnwrapHandle(lib); |
| 392 Isolate* isolate = Isolate::Current(); |
| 393 |
| 394 const Class& array_class = |
| 395 Class::Handle(isolate->object_store()->array_class()); |
| 396 EXPECT(!array_class.IsNull()); |
| 397 |
| 398 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 399 EXPECT_VALID(result); |
| 400 |
| 401 { |
| 402 StackZone zone(isolate); |
| 403 HANDLESCOPE(isolate); |
| 404 Profile profile(isolate); |
| 405 AllocationFilter filter(isolate, array_class.id()); |
| 406 profile.Build(&filter, Profile::kNoTags); |
| 407 // We should have no allocation samples. |
| 408 EXPECT_EQ(0, profile.sample_count()); |
| 409 } |
| 410 |
| 411 array_class.SetTraceAllocation(true); |
| 412 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 413 EXPECT_VALID(result); |
| 414 |
| 415 { |
| 416 StackZone zone(isolate); |
| 417 HANDLESCOPE(isolate); |
| 418 Profile profile(isolate); |
| 419 AllocationFilter filter(isolate, array_class.id()); |
| 420 profile.Build(&filter, Profile::kNoTags); |
| 421 // We should have one allocation sample. |
| 422 EXPECT_EQ(1, profile.sample_count()); |
| 423 ProfileTrieWalker walker(&profile); |
| 424 |
| 425 walker.Reset(Profile::kExclusiveCode); |
| 426 EXPECT(walker.Down()); |
| 427 EXPECT_STREQ("_List._List", walker.CurrentName()); |
| 428 EXPECT(walker.Down()); |
| 429 EXPECT_STREQ("List.List", walker.CurrentName()); |
| 430 EXPECT(walker.Down()); |
| 431 EXPECT_STREQ("foo", walker.CurrentName()); |
| 432 EXPECT(!walker.Down()); |
| 433 } |
| 434 |
| 435 array_class.SetTraceAllocation(false); |
| 436 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 437 EXPECT_VALID(result); |
| 438 |
| 439 { |
| 440 StackZone zone(isolate); |
| 441 HANDLESCOPE(isolate); |
| 442 Profile profile(isolate); |
| 443 AllocationFilter filter(isolate, array_class.id()); |
| 444 profile.Build(&filter, Profile::kNoTags); |
| 445 // We should still only have one allocation sample. |
| 446 EXPECT_EQ(1, profile.sample_count()); |
| 447 } |
| 448 |
| 449 // Clear the samples. |
| 450 ProfilerService::ClearSamples(); |
| 451 |
| 452 // Compile bar (many List objects allocated). |
| 453 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
| 454 EXPECT_VALID(result); |
| 455 |
| 456 // Enable again. |
| 457 array_class.SetTraceAllocation(true); |
| 458 |
| 459 // Run bar. |
| 460 result = Dart_Invoke(lib, NewString("bar"), 0, NULL); |
| 461 EXPECT_VALID(result); |
| 462 |
| 463 { |
| 464 StackZone zone(isolate); |
| 465 HANDLESCOPE(isolate); |
| 466 Profile profile(isolate); |
| 467 AllocationFilter filter(isolate, array_class.id()); |
| 468 profile.Build(&filter, Profile::kNoTags); |
| 469 // We should still only have one allocation sample. |
| 470 EXPECT_EQ(1, profile.sample_count()); |
| 471 ProfileTrieWalker walker(&profile); |
| 472 |
| 473 walker.Reset(Profile::kExclusiveCode); |
| 474 EXPECT(walker.Down()); |
| 475 EXPECT_STREQ("_List._List", walker.CurrentName()); |
| 476 EXPECT(walker.Down()); |
| 477 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName()); |
| 478 EXPECT(walker.Down()); |
| 479 EXPECT_STREQ("List.List", walker.CurrentName()); |
| 480 EXPECT(walker.Down()); |
| 481 EXPECT_STREQ("bar", walker.CurrentName()); |
| 482 EXPECT(!walker.Down()); |
| 483 } |
| 484 } |
| 485 |
383 } // namespace dart | 486 } // namespace dart |
OLD | NEW |