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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 Sample* sample = sample_buffer->ReserveSample(); | 96 Sample* sample = sample_buffer->ReserveSample(); |
97 sample->Init(isolate, 0, 0); | 97 sample->Init(isolate, 0, 0); |
98 sample->set_metadata(99); | 98 sample->set_metadata(99); |
99 sample->set_is_allocation_sample(true); | 99 sample->set_is_allocation_sample(true); |
100 EXPECT_EQ(99, sample->allocation_cid()); | 100 EXPECT_EQ(99, sample->allocation_cid()); |
101 delete sample_buffer; | 101 delete sample_buffer; |
102 } | 102 } |
103 | 103 |
104 static RawClass* GetClass(const Library& lib, const char* name) { | 104 static RawClass* GetClass(const Library& lib, const char* name) { |
105 const Class& cls = Class::Handle( | 105 const Class& cls = Class::Handle( |
106 lib.LookupClass(String::Handle(Symbols::New(name)))); | 106 lib.LookupClassAllowPrivate(String::Handle(Symbols::New(name)))); |
107 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 107 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
108 return cls.raw(); | 108 return cls.raw(); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 class AllocationFilter : public SampleFilter { | 112 class AllocationFilter : public SampleFilter { |
113 public: | 113 public: |
114 explicit AllocationFilter(Isolate* isolate, intptr_t cid) | 114 explicit AllocationFilter(Isolate* isolate, intptr_t cid) |
115 : SampleFilter(isolate), | 115 : SampleFilter(isolate), |
116 cid_(cid) { | 116 cid_(cid) { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 EXPECT(walker.Down()); | 476 EXPECT(walker.Down()); |
477 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName()); | 477 EXPECT_STREQ("_GrowableList._GrowableList", walker.CurrentName()); |
478 EXPECT(walker.Down()); | 478 EXPECT(walker.Down()); |
479 EXPECT_STREQ("List.List", walker.CurrentName()); | 479 EXPECT_STREQ("List.List", walker.CurrentName()); |
480 EXPECT(walker.Down()); | 480 EXPECT(walker.Down()); |
481 EXPECT_STREQ("bar", walker.CurrentName()); | 481 EXPECT_STREQ("bar", walker.CurrentName()); |
482 EXPECT(!walker.Down()); | 482 EXPECT(!walker.Down()); |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
| 486 |
| 487 TEST_CASE(Profiler_TypedArrayAllocation) { |
| 488 const char* kScript = |
| 489 "import 'dart:typed_data';\n" |
| 490 "List foo() => new Float32List(4);\n"; |
| 491 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 492 EXPECT_VALID(lib); |
| 493 Library& root_library = Library::Handle(); |
| 494 root_library ^= Api::UnwrapHandle(lib); |
| 495 Isolate* isolate = Isolate::Current(); |
| 496 |
| 497 const Library& typed_data_library = |
| 498 Library::Handle(isolate->object_store()->typed_data_library()); |
| 499 |
| 500 const Class& float32_list_class = |
| 501 Class::Handle(GetClass(typed_data_library, "_Float32Array")); |
| 502 EXPECT(!float32_list_class.IsNull()); |
| 503 |
| 504 Dart_Handle result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 505 EXPECT_VALID(result); |
| 506 |
| 507 { |
| 508 StackZone zone(isolate); |
| 509 HANDLESCOPE(isolate); |
| 510 Profile profile(isolate); |
| 511 AllocationFilter filter(isolate, float32_list_class.id()); |
| 512 profile.Build(&filter, Profile::kNoTags); |
| 513 // We should have no allocation samples. |
| 514 EXPECT_EQ(0, profile.sample_count()); |
| 515 } |
| 516 |
| 517 float32_list_class.SetTraceAllocation(true); |
| 518 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 519 EXPECT_VALID(result); |
| 520 |
| 521 { |
| 522 StackZone zone(isolate); |
| 523 HANDLESCOPE(isolate); |
| 524 Profile profile(isolate); |
| 525 AllocationFilter filter(isolate, float32_list_class.id()); |
| 526 profile.Build(&filter, Profile::kNoTags); |
| 527 // We should have one allocation sample. |
| 528 EXPECT_EQ(1, profile.sample_count()); |
| 529 ProfileTrieWalker walker(&profile); |
| 530 |
| 531 walker.Reset(Profile::kExclusiveCode); |
| 532 EXPECT(walker.Down()); |
| 533 EXPECT_STREQ("_Float32Array._new", walker.CurrentName()); |
| 534 EXPECT(walker.Down()); |
| 535 EXPECT_STREQ("_Float32Array._Float32Array", walker.CurrentName()); |
| 536 EXPECT(walker.Down()); |
| 537 EXPECT_STREQ("Float32List.Float32List", walker.CurrentName()); |
| 538 EXPECT(walker.Down()); |
| 539 EXPECT_STREQ("foo", walker.CurrentName()); |
| 540 EXPECT(!walker.Down()); |
| 541 } |
| 542 } |
| 543 |
486 } // namespace dart | 544 } // namespace dart |
OLD | NEW |