Chromium Code Reviews| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 316 |
| 317 TEST_CASE(Profiler_CodeTicks) { | |
| 318 const char* kScript = | |
| 319 "class A {\n" | |
| 320 " var a;\n" | |
| 321 " var b;\n" | |
| 322 "}\n" | |
| 323 "class B {\n" | |
| 324 " static boo() {\n" | |
| 325 " return new A();\n" | |
| 326 " }\n" | |
| 327 "}\n" | |
| 328 "main() {\n" | |
| 329 " B.boo();\n" | |
| 330 "}\n"; | |
| 331 | |
| 332 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
| 333 EXPECT_VALID(lib); | |
| 334 Library& root_library = Library::Handle(); | |
| 335 root_library ^= Api::UnwrapHandle(lib); | |
| 336 | |
| 337 const Class& class_a = Class::Handle(GetClass(root_library, "A")); | |
| 338 EXPECT(!class_a.IsNull()); | |
| 339 | |
| 340 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
| 341 EXPECT_VALID(result); | |
| 342 | |
| 343 { | |
| 344 Isolate* isolate = Isolate::Current(); | |
| 345 StackZone zone(isolate); | |
| 346 HANDLESCOPE(isolate); | |
| 347 Profile profile(isolate); | |
| 348 AllocationFilter filter(isolate, class_a.id()); | |
| 349 profile.Build(&filter, Profile::kNoTags); | |
| 350 // We should have no allocation samples. | |
| 351 EXPECT_EQ(0, profile.sample_count()); | |
| 352 } | |
| 353 | |
| 354 // Turn on allocation tracing for A. | |
| 355 class_a.SetTraceAllocation(true); | |
| 356 | |
| 357 // Allocate three times. | |
| 358 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
| 359 EXPECT_VALID(result); | |
| 360 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
| 361 EXPECT_VALID(result); | |
| 362 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
| 363 EXPECT_VALID(result); | |
| 364 | |
| 365 { | |
| 366 Isolate* isolate = Isolate::Current(); | |
| 367 StackZone zone(isolate); | |
| 368 HANDLESCOPE(isolate); | |
| 369 Profile profile(isolate); | |
| 370 AllocationFilter filter(isolate, class_a.id()); | |
| 371 profile.Build(&filter, Profile::kNoTags); | |
| 372 // We should have one allocation sample. | |
| 373 EXPECT_EQ(3, profile.sample_count()); | |
| 374 ProfileTrieWalker walker(&profile); | |
| 375 | |
| 376 // Exclusive code: B.boo -> main. | |
| 377 walker.Reset(Profile::kExclusiveCode); | |
|
rmacnak
2015/07/28 00:11:44
Seems weird to create a walker for exclusive code
| |
| 378 // Move down from the root. | |
| 379 EXPECT(walker.Down()); | |
| 380 EXPECT_STREQ("B.boo", walker.CurrentName()); | |
| 381 EXPECT_EQ(3, walker.CurrentInclusiveTicks()); | |
| 382 EXPECT_EQ(3, walker.CurrentExclusiveTicks()); | |
| 383 EXPECT(walker.Down()); | |
| 384 EXPECT_STREQ("main", walker.CurrentName()); | |
| 385 EXPECT_EQ(3, walker.CurrentInclusiveTicks()); | |
| 386 EXPECT_EQ(0, walker.CurrentExclusiveTicks()); | |
| 387 EXPECT(!walker.Down()); | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 | |
| 317 TEST_CASE(Profiler_IntrinsicAllocation) { | 392 TEST_CASE(Profiler_IntrinsicAllocation) { |
| 318 const char* kScript = "double foo(double a, double b) => a + b;"; | 393 const char* kScript = "double foo(double a, double b) => a + b;"; |
| 319 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 394 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 320 EXPECT_VALID(lib); | 395 EXPECT_VALID(lib); |
| 321 Library& root_library = Library::Handle(); | 396 Library& root_library = Library::Handle(); |
| 322 root_library ^= Api::UnwrapHandle(lib); | 397 root_library ^= Api::UnwrapHandle(lib); |
| 323 Isolate* isolate = Isolate::Current(); | 398 Isolate* isolate = Isolate::Current(); |
| 324 | 399 |
| 325 const Class& double_class = | 400 const Class& double_class = |
| 326 Class::Handle(isolate->object_store()->double_class()); | 401 Class::Handle(isolate->object_store()->double_class()); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 HANDLESCOPE(isolate); | 800 HANDLESCOPE(isolate); |
| 726 Profile profile(isolate); | 801 Profile profile(isolate); |
| 727 AllocationFilter filter(isolate, one_byte_string_class.id()); | 802 AllocationFilter filter(isolate, one_byte_string_class.id()); |
| 728 profile.Build(&filter, Profile::kNoTags); | 803 profile.Build(&filter, Profile::kNoTags); |
| 729 // We should now have two allocation samples. | 804 // We should now have two allocation samples. |
| 730 EXPECT_EQ(2, profile.sample_count()); | 805 EXPECT_EQ(2, profile.sample_count()); |
| 731 } | 806 } |
| 732 } | 807 } |
| 733 | 808 |
| 734 } // namespace dart | 809 } // namespace dart |
| OLD | NEW |