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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 static RawClass* GetClass(const Library& lib, const char* name) { | 142 static RawClass* GetClass(const Library& lib, const char* name) { |
143 const Class& cls = Class::Handle( | 143 const Class& cls = Class::Handle( |
144 lib.LookupClassAllowPrivate(String::Handle(Symbols::New(name)))); | 144 lib.LookupClassAllowPrivate(String::Handle(Symbols::New(name)))); |
145 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 145 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
146 return cls.raw(); | 146 return cls.raw(); |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 class AllocationFilter : public SampleFilter { | 150 class AllocationFilter : public SampleFilter { |
151 public: | 151 public: |
152 explicit AllocationFilter(Isolate* isolate, intptr_t cid) | 152 AllocationFilter(Isolate* isolate, |
153 : SampleFilter(isolate), | 153 intptr_t cid, |
| 154 int64_t time_origin_micros = -1, |
| 155 int64_t time_extent_micros = -1) |
| 156 : SampleFilter(isolate, |
| 157 time_origin_micros, |
| 158 time_extent_micros), |
154 cid_(cid), | 159 cid_(cid), |
155 enable_vm_ticks_(false) { | 160 enable_vm_ticks_(false) { |
156 } | 161 } |
157 | 162 |
158 bool FilterSample(Sample* sample) { | 163 bool FilterSample(Sample* sample) { |
159 if (!enable_vm_ticks_ && | 164 if (!enable_vm_ticks_ && |
160 (sample->vm_tag() == VMTag::kVMTagId)) { | 165 (sample->vm_tag() == VMTag::kVMTagId)) { |
161 // We don't want to see embedder ticks in the test. | 166 // We don't want to see embedder ticks in the test. |
162 return false; | 167 return false; |
163 } | 168 } |
(...skipping 25 matching lines...) Expand all Loading... |
189 "}\n" | 194 "}\n" |
190 "main() {\n" | 195 "main() {\n" |
191 " return B.boo();\n" | 196 " return B.boo();\n" |
192 "}\n"; | 197 "}\n"; |
193 | 198 |
194 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 199 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
195 EXPECT_VALID(lib); | 200 EXPECT_VALID(lib); |
196 Library& root_library = Library::Handle(); | 201 Library& root_library = Library::Handle(); |
197 root_library ^= Api::UnwrapHandle(lib); | 202 root_library ^= Api::UnwrapHandle(lib); |
198 | 203 |
| 204 const int64_t before_allocations_micros = Dart_TimelineGetMicros(); |
199 const Class& class_a = Class::Handle(GetClass(root_library, "A")); | 205 const Class& class_a = Class::Handle(GetClass(root_library, "A")); |
200 EXPECT(!class_a.IsNull()); | 206 EXPECT(!class_a.IsNull()); |
201 class_a.SetTraceAllocation(true); | 207 class_a.SetTraceAllocation(true); |
202 | 208 |
203 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 209 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
204 EXPECT_VALID(result); | 210 EXPECT_VALID(result); |
205 | 211 |
206 | 212 const int64_t after_allocations_micros = Dart_TimelineGetMicros(); |
| 213 const int64_t allocation_extent_micros = |
| 214 after_allocations_micros - before_allocations_micros; |
207 { | 215 { |
208 Thread* thread = Thread::Current(); | 216 Thread* thread = Thread::Current(); |
209 Isolate* isolate = thread->isolate(); | 217 Isolate* isolate = thread->isolate(); |
210 StackZone zone(thread); | 218 StackZone zone(thread); |
211 HANDLESCOPE(thread); | 219 HANDLESCOPE(thread); |
212 Profile profile(isolate); | 220 Profile profile(isolate); |
213 AllocationFilter filter(isolate, class_a.id()); | 221 // Filter for the class in the time range. |
| 222 AllocationFilter filter(isolate, |
| 223 class_a.id(), |
| 224 before_allocations_micros, |
| 225 allocation_extent_micros); |
214 profile.Build(thread, &filter, Profile::kNoTags); | 226 profile.Build(thread, &filter, Profile::kNoTags); |
215 // We should have 1 allocation sample. | 227 // We should have 1 allocation sample. |
216 EXPECT_EQ(1, profile.sample_count()); | 228 EXPECT_EQ(1, profile.sample_count()); |
217 ProfileTrieWalker walker(&profile); | 229 ProfileTrieWalker walker(&profile); |
218 | 230 |
219 // Exclusive code: B.boo -> main. | 231 // Exclusive code: B.boo -> main. |
220 walker.Reset(Profile::kExclusiveCode); | 232 walker.Reset(Profile::kExclusiveCode); |
221 // Move down from the root. | 233 // Move down from the root. |
222 EXPECT(walker.Down()); | 234 EXPECT(walker.Down()); |
223 EXPECT_STREQ("B.boo", walker.CurrentName()); | 235 EXPECT_STREQ("B.boo", walker.CurrentName()); |
(...skipping 21 matching lines...) Expand all Loading... |
245 | 257 |
246 // Inclusive function: main -> B.boo. | 258 // Inclusive function: main -> B.boo. |
247 walker.Reset(Profile::kInclusiveFunction); | 259 walker.Reset(Profile::kInclusiveFunction); |
248 // Move down from the root. | 260 // Move down from the root. |
249 EXPECT(walker.Down()); | 261 EXPECT(walker.Down()); |
250 EXPECT_STREQ("main", walker.CurrentName()); | 262 EXPECT_STREQ("main", walker.CurrentName()); |
251 EXPECT(walker.Down()); | 263 EXPECT(walker.Down()); |
252 EXPECT_STREQ("B.boo", walker.CurrentName()); | 264 EXPECT_STREQ("B.boo", walker.CurrentName()); |
253 EXPECT(!walker.Down()); | 265 EXPECT(!walker.Down()); |
254 } | 266 } |
| 267 |
| 268 // Query with a time filter where no allocations occurred. |
| 269 { |
| 270 Thread* thread = Thread::Current(); |
| 271 Isolate* isolate = thread->isolate(); |
| 272 StackZone zone(thread); |
| 273 HANDLESCOPE(thread); |
| 274 Profile profile(isolate); |
| 275 AllocationFilter filter(isolate, |
| 276 class_a.id(), |
| 277 Dart_TimelineGetMicros(), |
| 278 16000); |
| 279 profile.Build(thread, &filter, Profile::kNoTags); |
| 280 // We should have no allocation samples because none occured within |
| 281 // the specified time range. |
| 282 EXPECT_EQ(0, profile.sample_count()); |
| 283 } |
255 } | 284 } |
256 | 285 |
257 | 286 |
258 TEST_CASE(Profiler_ToggleRecordAllocation) { | 287 TEST_CASE(Profiler_ToggleRecordAllocation) { |
259 DisableNativeProfileScope dnps; | 288 DisableNativeProfileScope dnps; |
260 const char* kScript = | 289 const char* kScript = |
261 "class A {\n" | 290 "class A {\n" |
262 " var a;\n" | 291 " var a;\n" |
263 " var b;\n" | 292 " var b;\n" |
264 "}\n" | 293 "}\n" |
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 EXPECT(walker.Down()); | 1506 EXPECT(walker.Down()); |
1478 EXPECT_STREQ("go", walker.CurrentName()); | 1507 EXPECT_STREQ("go", walker.CurrentName()); |
1479 EXPECT(walker.Down()); | 1508 EXPECT(walker.Down()); |
1480 EXPECT_STREQ("main", walker.CurrentName()); | 1509 EXPECT_STREQ("main", walker.CurrentName()); |
1481 EXPECT(!walker.Down()); | 1510 EXPECT(!walker.Down()); |
1482 } | 1511 } |
1483 } | 1512 } |
1484 | 1513 |
1485 } // namespace dart | 1514 } // namespace dart |
1486 | 1515 |
OLD | NEW |