Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 2053523003: Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 }; 341 };
342 342
343 } // namespace 343 } // namespace
344 344
345 TEST(RecordTickSample) { 345 TEST(RecordTickSample) {
346 TestSetup test_setup; 346 TestSetup test_setup;
347 CpuProfilesCollection profiles(CcTest::i_isolate()); 347 CpuProfilesCollection profiles(CcTest::i_isolate());
348 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 348 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
349 profiles.StartProfiling("", false); 349 profiles.StartProfiling("", false);
350 ProfileGenerator generator(&profiles); 350 ProfileGenerator generator(&profiles);
351 CodeEntry* entry1 = 351 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
352 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa"); 352 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
353 CodeEntry* entry2 = 353 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
354 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
355 CodeEntry* entry3 =
356 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
357 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 354 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
358 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 355 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
359 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 356 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
360 357
361 // We are building the following calls tree: 358 // We are building the following calls tree:
362 // -> aaa - sample1 359 // -> aaa - sample1
363 // aaa -> bbb -> ccc - sample2 360 // aaa -> bbb -> ccc - sample2
364 // -> ccc -> aaa - sample3 361 // -> ccc -> aaa - sample3
365 TickSample sample1; 362 TickSample sample1;
366 sample1.pc = ToAddress(0x1600); 363 sample1.pc = ToAddress(0x1600);
(...skipping 27 matching lines...) Expand all
394 CHECK_EQ(entry1, node1->entry()); 391 CHECK_EQ(entry1, node1->entry());
395 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); 392 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1);
396 CHECK(node2); 393 CHECK(node2);
397 CHECK_EQ(entry1, node2->entry()); 394 CHECK_EQ(entry1, node2->entry());
398 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); 395 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3);
399 CHECK(node3); 396 CHECK(node3);
400 CHECK_EQ(entry3, node3->entry()); 397 CHECK_EQ(entry3, node3->entry());
401 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); 398 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1);
402 CHECK(node4); 399 CHECK(node4);
403 CHECK_EQ(entry1, node4->entry()); 400 CHECK_EQ(entry1, node4->entry());
401
402 delete entry1;
403 delete entry2;
404 delete entry3;
404 } 405 }
405 406
406 407
407 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { 408 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) {
408 CHECK_EQ((*expectedId)++, node->id()); 409 CHECK_EQ((*expectedId)++, node->id());
409 for (int i = 0; i < node->children()->length(); i++) { 410 for (int i = 0; i < node->children()->length(); i++) {
410 CheckNodeIds(node->children()->at(i), expectedId); 411 CheckNodeIds(node->children()->at(i), expectedId);
411 } 412 }
412 } 413 }
413 414
414 415
415 TEST(SampleIds) { 416 TEST(SampleIds) {
416 TestSetup test_setup; 417 TestSetup test_setup;
417 CpuProfilesCollection profiles(CcTest::i_isolate()); 418 CpuProfilesCollection profiles(CcTest::i_isolate());
418 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 419 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
419 profiles.StartProfiling("", true); 420 profiles.StartProfiling("", true);
420 ProfileGenerator generator(&profiles); 421 ProfileGenerator generator(&profiles);
421 CodeEntry* entry1 = 422 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
422 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa"); 423 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
423 CodeEntry* entry2 = 424 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
424 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
425 CodeEntry* entry3 =
426 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
427 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 425 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
428 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 426 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
429 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 427 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
430 428
431 // We are building the following calls tree: 429 // We are building the following calls tree:
432 // -> aaa #3 - sample1 430 // -> aaa #3 - sample1
433 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2 431 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
434 // -> ccc #6 -> aaa #7 - sample3 432 // -> ccc #6 -> aaa #7 - sample3
435 TickSample sample1; 433 TickSample sample1;
436 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow(); 434 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
(...skipping 20 matching lines...) Expand all
457 CpuProfile* profile = profiles.StopProfiling(""); 455 CpuProfile* profile = profiles.StopProfiling("");
458 unsigned nodeId = 1; 456 unsigned nodeId = 1;
459 CheckNodeIds(profile->top_down()->root(), &nodeId); 457 CheckNodeIds(profile->top_down()->root(), &nodeId);
460 CHECK_EQ(7u, nodeId - 1); 458 CHECK_EQ(7u, nodeId - 1);
461 459
462 CHECK_EQ(3, profile->samples_count()); 460 CHECK_EQ(3, profile->samples_count());
463 unsigned expected_id[] = {3, 5, 7}; 461 unsigned expected_id[] = {3, 5, 7};
464 for (int i = 0; i < 3; i++) { 462 for (int i = 0; i < 3; i++) {
465 CHECK_EQ(expected_id[i], profile->sample(i)->id()); 463 CHECK_EQ(expected_id[i], profile->sample(i)->id());
466 } 464 }
465
466 delete entry1;
467 delete entry2;
468 delete entry3;
467 } 469 }
468 470
469 471
470 TEST(NoSamples) { 472 TEST(NoSamples) {
471 TestSetup test_setup; 473 TestSetup test_setup;
472 CpuProfilesCollection profiles(CcTest::i_isolate()); 474 CpuProfilesCollection profiles(CcTest::i_isolate());
473 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 475 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
474 profiles.StartProfiling("", false); 476 profiles.StartProfiling("", false);
475 ProfileGenerator generator(&profiles); 477 ProfileGenerator generator(&profiles);
476 CodeEntry* entry1 = 478 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
477 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
478 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 479 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
479 480
480 // We are building the following calls tree: 481 // We are building the following calls tree:
481 // (root)#1 -> aaa #2 -> aaa #3 - sample1 482 // (root)#1 -> aaa #2 -> aaa #3 - sample1
482 TickSample sample1; 483 TickSample sample1;
483 sample1.pc = ToAddress(0x1600); 484 sample1.pc = ToAddress(0x1600);
484 sample1.stack[0] = ToAddress(0x1510); 485 sample1.stack[0] = ToAddress(0x1510);
485 sample1.frames_count = 1; 486 sample1.frames_count = 1;
486 generator.RecordTickSample(sample1); 487 generator.RecordTickSample(sample1);
487 488
488 CpuProfile* profile = profiles.StopProfiling(""); 489 CpuProfile* profile = profiles.StopProfiling("");
489 unsigned nodeId = 1; 490 unsigned nodeId = 1;
490 CheckNodeIds(profile->top_down()->root(), &nodeId); 491 CheckNodeIds(profile->top_down()->root(), &nodeId);
491 CHECK_EQ(3u, nodeId - 1); 492 CHECK_EQ(3u, nodeId - 1);
492 493
493 CHECK_EQ(0, profile->samples_count()); 494 CHECK_EQ(0, profile->samples_count());
495
496 delete entry1;
494 } 497 }
495 498
496 499
497 static const ProfileNode* PickChild(const ProfileNode* parent, 500 static const ProfileNode* PickChild(const ProfileNode* parent,
498 const char* name) { 501 const char* name) {
499 for (int i = 0; i < parent->children()->length(); ++i) { 502 for (int i = 0; i < parent->children()->length(); ++i) {
500 const ProfileNode* child = parent->children()->at(i); 503 const ProfileNode* child = parent->children()->at(i);
501 if (strcmp(child->entry()->name(), name) == 0) return child; 504 if (strcmp(child->entry()->name(), name) == 0) return child;
502 } 505 }
503 return NULL; 506 return NULL;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 // (root) 718 // (root)
716 // "" 719 // ""
717 // kDebuggerStatement 720 // kDebuggerStatement
718 current = PickChild(current, ""); 721 current = PickChild(current, "");
719 CHECK(const_cast<v8::CpuProfileNode*>(current)); 722 CHECK(const_cast<v8::CpuProfileNode*>(current));
720 723
721 current = PickChild(current, "Debugger"); 724 current = PickChild(current, "Debugger");
722 CHECK(const_cast<v8::CpuProfileNode*>(current)); 725 CHECK(const_cast<v8::CpuProfileNode*>(current));
723 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 726 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
724 } 727 }
OLDNEW
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698