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

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

Issue 2079273003: Revert of Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 351 CodeEntry* entry1 =
352 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 352 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
353 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 353 CodeEntry* entry2 =
354 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
355 CodeEntry* entry3 =
356 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
354 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 357 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
355 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 358 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
356 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 359 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
357 360
358 // We are building the following calls tree: 361 // We are building the following calls tree:
359 // -> aaa - sample1 362 // -> aaa - sample1
360 // aaa -> bbb -> ccc - sample2 363 // aaa -> bbb -> ccc - sample2
361 // -> ccc -> aaa - sample3 364 // -> ccc -> aaa - sample3
362 TickSample sample1; 365 TickSample sample1;
363 sample1.pc = ToAddress(0x1600); 366 sample1.pc = ToAddress(0x1600);
(...skipping 27 matching lines...) Expand all
391 CHECK_EQ(entry1, node1->entry()); 394 CHECK_EQ(entry1, node1->entry());
392 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); 395 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1);
393 CHECK(node2); 396 CHECK(node2);
394 CHECK_EQ(entry1, node2->entry()); 397 CHECK_EQ(entry1, node2->entry());
395 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); 398 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3);
396 CHECK(node3); 399 CHECK(node3);
397 CHECK_EQ(entry3, node3->entry()); 400 CHECK_EQ(entry3, node3->entry());
398 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); 401 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1);
399 CHECK(node4); 402 CHECK(node4);
400 CHECK_EQ(entry1, node4->entry()); 403 CHECK_EQ(entry1, node4->entry());
401
402 delete entry1;
403 delete entry2;
404 delete entry3;
405 } 404 }
406 405
407 406
408 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { 407 static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) {
409 CHECK_EQ((*expectedId)++, node->id()); 408 CHECK_EQ((*expectedId)++, node->id());
410 for (int i = 0; i < node->children()->length(); i++) { 409 for (int i = 0; i < node->children()->length(); i++) {
411 CheckNodeIds(node->children()->at(i), expectedId); 410 CheckNodeIds(node->children()->at(i), expectedId);
412 } 411 }
413 } 412 }
414 413
415 414
416 TEST(SampleIds) { 415 TEST(SampleIds) {
417 TestSetup test_setup; 416 TestSetup test_setup;
418 CpuProfilesCollection profiles(CcTest::i_isolate()); 417 CpuProfilesCollection profiles(CcTest::i_isolate());
419 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 418 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
420 profiles.StartProfiling("", true); 419 profiles.StartProfiling("", true);
421 ProfileGenerator generator(&profiles); 420 ProfileGenerator generator(&profiles);
422 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 421 CodeEntry* entry1 =
423 CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb"); 422 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
424 CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc"); 423 CodeEntry* entry2 =
424 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
425 CodeEntry* entry3 =
426 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
425 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 427 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
426 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100); 428 generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
427 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50); 429 generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
428 430
429 // We are building the following calls tree: 431 // We are building the following calls tree:
430 // -> aaa #3 - sample1 432 // -> aaa #3 - sample1
431 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2 433 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
432 // -> ccc #6 -> aaa #7 - sample3 434 // -> ccc #6 -> aaa #7 - sample3
433 TickSample sample1; 435 TickSample sample1;
434 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow(); 436 sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
(...skipping 20 matching lines...) Expand all
455 CpuProfile* profile = profiles.StopProfiling(""); 457 CpuProfile* profile = profiles.StopProfiling("");
456 unsigned nodeId = 1; 458 unsigned nodeId = 1;
457 CheckNodeIds(profile->top_down()->root(), &nodeId); 459 CheckNodeIds(profile->top_down()->root(), &nodeId);
458 CHECK_EQ(7u, nodeId - 1); 460 CHECK_EQ(7u, nodeId - 1);
459 461
460 CHECK_EQ(3, profile->samples_count()); 462 CHECK_EQ(3, profile->samples_count());
461 unsigned expected_id[] = {3, 5, 7}; 463 unsigned expected_id[] = {3, 5, 7};
462 for (int i = 0; i < 3; i++) { 464 for (int i = 0; i < 3; i++) {
463 CHECK_EQ(expected_id[i], profile->sample(i)->id()); 465 CHECK_EQ(expected_id[i], profile->sample(i)->id());
464 } 466 }
465
466 delete entry1;
467 delete entry2;
468 delete entry3;
469 } 467 }
470 468
471 469
472 TEST(NoSamples) { 470 TEST(NoSamples) {
473 TestSetup test_setup; 471 TestSetup test_setup;
474 CpuProfilesCollection profiles(CcTest::i_isolate()); 472 CpuProfilesCollection profiles(CcTest::i_isolate());
475 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler()); 473 profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
476 profiles.StartProfiling("", false); 474 profiles.StartProfiling("", false);
477 ProfileGenerator generator(&profiles); 475 ProfileGenerator generator(&profiles);
478 CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 476 CodeEntry* entry1 =
477 profiles.NewCodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
479 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 478 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
480 479
481 // We are building the following calls tree: 480 // We are building the following calls tree:
482 // (root)#1 -> aaa #2 -> aaa #3 - sample1 481 // (root)#1 -> aaa #2 -> aaa #3 - sample1
483 TickSample sample1; 482 TickSample sample1;
484 sample1.pc = ToAddress(0x1600); 483 sample1.pc = ToAddress(0x1600);
485 sample1.stack[0] = ToAddress(0x1510); 484 sample1.stack[0] = ToAddress(0x1510);
486 sample1.frames_count = 1; 485 sample1.frames_count = 1;
487 generator.RecordTickSample(sample1); 486 generator.RecordTickSample(sample1);
488 487
489 CpuProfile* profile = profiles.StopProfiling(""); 488 CpuProfile* profile = profiles.StopProfiling("");
490 unsigned nodeId = 1; 489 unsigned nodeId = 1;
491 CheckNodeIds(profile->top_down()->root(), &nodeId); 490 CheckNodeIds(profile->top_down()->root(), &nodeId);
492 CHECK_EQ(3u, nodeId - 1); 491 CHECK_EQ(3u, nodeId - 1);
493 492
494 CHECK_EQ(0, profile->samples_count()); 493 CHECK_EQ(0, profile->samples_count());
495
496 delete entry1;
497 } 494 }
498 495
499 496
500 static const ProfileNode* PickChild(const ProfileNode* parent, 497 static const ProfileNode* PickChild(const ProfileNode* parent,
501 const char* name) { 498 const char* name) {
502 for (int i = 0; i < parent->children()->length(); ++i) { 499 for (int i = 0; i < parent->children()->length(); ++i) {
503 const ProfileNode* child = parent->children()->at(i); 500 const ProfileNode* child = parent->children()->at(i);
504 if (strcmp(child->entry()->name(), name) == 0) return child; 501 if (strcmp(child->entry()->name(), name) == 0) return child;
505 } 502 }
506 return NULL; 503 return NULL;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 // (root) 715 // (root)
719 // "" 716 // ""
720 // kDebuggerStatement 717 // kDebuggerStatement
721 current = PickChild(current, ""); 718 current = PickChild(current, "");
722 CHECK(const_cast<v8::CpuProfileNode*>(current)); 719 CHECK(const_cast<v8::CpuProfileNode*>(current));
723 720
724 current = PickChild(current, "Debugger"); 721 current = PickChild(current, "Debugger");
725 CHECK(const_cast<v8::CpuProfileNode*>(current)); 722 CHECK(const_cast<v8::CpuProfileNode*>(current));
726 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason())); 723 CHECK(!strcmp("DebuggerStatement", current->GetBailoutReason()));
727 } 724 }
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