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

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

Issue 21173004: Version 3.20.11.1 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/mjsunit/array-literal-transitions.js » ('j') | 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 23 matching lines...) Expand all
34 #include "../include/v8-profiler.h" 34 #include "../include/v8-profiler.h"
35 35
36 using i::CodeEntry; 36 using i::CodeEntry;
37 using i::CodeMap; 37 using i::CodeMap;
38 using i::CpuProfile; 38 using i::CpuProfile;
39 using i::CpuProfiler; 39 using i::CpuProfiler;
40 using i::CpuProfilesCollection; 40 using i::CpuProfilesCollection;
41 using i::ProfileNode; 41 using i::ProfileNode;
42 using i::ProfileTree; 42 using i::ProfileTree;
43 using i::ProfileGenerator; 43 using i::ProfileGenerator;
44 using i::SampleRateCalculator;
44 using i::TickSample; 45 using i::TickSample;
45 using i::Vector; 46 using i::Vector;
46 47
47 48
48 TEST(ProfileNodeFindOrAddChild) { 49 TEST(ProfileNodeFindOrAddChild) {
49 ProfileTree tree; 50 ProfileTree tree;
50 ProfileNode node(&tree, NULL); 51 ProfileNode node(&tree, NULL);
51 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); 52 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
52 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); 53 ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
53 CHECK_NE(NULL, childNode1); 54 CHECK_NE(NULL, childNode1);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 sample2.frames_count = 3; 478 sample2.frames_count = 3;
478 generator.RecordTickSample(sample2); 479 generator.RecordTickSample(sample2);
479 TickSample sample3; 480 TickSample sample3;
480 sample3.pc = ToAddress(0x1510); 481 sample3.pc = ToAddress(0x1510);
481 sample3.tos = ToAddress(0x1500); 482 sample3.tos = ToAddress(0x1500);
482 sample3.stack[0] = ToAddress(0x1910); 483 sample3.stack[0] = ToAddress(0x1910);
483 sample3.stack[1] = ToAddress(0x1610); 484 sample3.stack[1] = ToAddress(0x1610);
484 sample3.frames_count = 2; 485 sample3.frames_count = 2;
485 generator.RecordTickSample(sample3); 486 generator.RecordTickSample(sample3);
486 487
487 CpuProfile* profile = profiles.StopProfiling(""); 488 CpuProfile* profile = profiles.StopProfiling("", 1);
488 CHECK_NE(NULL, profile); 489 CHECK_NE(NULL, profile);
489 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); 490 ProfileTreeTestHelper top_down_test_helper(profile->top_down());
490 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); 491 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2));
491 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); 492 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3));
492 ProfileNode* node1 = top_down_test_helper.Walk(entry1); 493 ProfileNode* node1 = top_down_test_helper.Walk(entry1);
493 CHECK_NE(NULL, node1); 494 CHECK_NE(NULL, node1);
494 CHECK_EQ(entry1, node1->entry()); 495 CHECK_EQ(entry1, node1->entry());
495 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); 496 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1);
496 CHECK_NE(NULL, node2); 497 CHECK_NE(NULL, node2);
497 CHECK_EQ(entry1, node2->entry()); 498 CHECK_EQ(entry1, node2->entry());
498 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); 499 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3);
499 CHECK_NE(NULL, node3); 500 CHECK_NE(NULL, node3);
500 CHECK_EQ(entry3, node3->entry()); 501 CHECK_EQ(entry3, node3->entry());
501 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); 502 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1);
502 CHECK_NE(NULL, node4); 503 CHECK_NE(NULL, node4);
503 CHECK_EQ(entry1, node4->entry()); 504 CHECK_EQ(entry1, node4->entry());
504 } 505 }
505 506
506 507
508 TEST(SampleRateCalculator) {
509 const double kSamplingIntervalMs = i::Logger::kSamplingIntervalMs;
510
511 // Verify that ticking exactly in query intervals results in the
512 // initial sampling interval.
513 double time = 0.0;
514 SampleRateCalculator calc1;
515 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms());
516 calc1.UpdateMeasurements(time);
517 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms());
518 time += SampleRateCalculator::kWallTimeQueryIntervalMs;
519 calc1.UpdateMeasurements(time);
520 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms());
521 time += SampleRateCalculator::kWallTimeQueryIntervalMs;
522 calc1.UpdateMeasurements(time);
523 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms());
524 time += SampleRateCalculator::kWallTimeQueryIntervalMs;
525 calc1.UpdateMeasurements(time);
526 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms());
527
528 SampleRateCalculator calc2;
529 time = 0.0;
530 CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms());
531 calc2.UpdateMeasurements(time);
532 CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms());
533 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.5;
534 calc2.UpdateMeasurements(time);
535 // (1.0 + 2.0) / 2
536 CHECK_EQ(kSamplingIntervalMs * 1.5, calc2.ticks_per_ms());
537 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.75;
538 calc2.UpdateMeasurements(time);
539 // (1.0 + 2.0 + 2.0) / 3
540 CHECK_EQ(kSamplingIntervalMs * 5.0, floor(calc2.ticks_per_ms() * 3.0 + 0.5));
541
542 SampleRateCalculator calc3;
543 time = 0.0;
544 CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms());
545 calc3.UpdateMeasurements(time);
546 CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms());
547 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 2;
548 calc3.UpdateMeasurements(time);
549 // (1.0 + 0.5) / 2
550 CHECK_EQ(kSamplingIntervalMs * 0.75, calc3.ticks_per_ms());
551 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 1.5;
552 calc3.UpdateMeasurements(time);
553 // (1.0 + 0.5 + 0.5) / 3
554 CHECK_EQ(kSamplingIntervalMs * 2.0, floor(calc3.ticks_per_ms() * 3.0 + 0.5));
555 }
556
557
507 static void CheckNodeIds(ProfileNode* node, int* expectedId) { 558 static void CheckNodeIds(ProfileNode* node, int* expectedId) {
508 CHECK_EQ((*expectedId)++, node->id()); 559 CHECK_EQ((*expectedId)++, node->id());
509 for (int i = 0; i < node->children()->length(); i++) { 560 for (int i = 0; i < node->children()->length(); i++) {
510 CheckNodeIds(node->children()->at(i), expectedId); 561 CheckNodeIds(node->children()->at(i), expectedId);
511 } 562 }
512 } 563 }
513 564
514 565
515 TEST(SampleIds) { 566 TEST(SampleIds) {
516 TestSetup test_setup; 567 TestSetup test_setup;
(...skipping 23 matching lines...) Expand all
540 sample2.stack[2] = ToAddress(0x1620); 591 sample2.stack[2] = ToAddress(0x1620);
541 sample2.frames_count = 3; 592 sample2.frames_count = 3;
542 generator.RecordTickSample(sample2); 593 generator.RecordTickSample(sample2);
543 TickSample sample3; 594 TickSample sample3;
544 sample3.pc = ToAddress(0x1510); 595 sample3.pc = ToAddress(0x1510);
545 sample3.stack[0] = ToAddress(0x1910); 596 sample3.stack[0] = ToAddress(0x1910);
546 sample3.stack[1] = ToAddress(0x1610); 597 sample3.stack[1] = ToAddress(0x1610);
547 sample3.frames_count = 2; 598 sample3.frames_count = 2;
548 generator.RecordTickSample(sample3); 599 generator.RecordTickSample(sample3);
549 600
550 CpuProfile* profile = profiles.StopProfiling(""); 601 CpuProfile* profile = profiles.StopProfiling("", 1);
551 int nodeId = 1; 602 int nodeId = 1;
552 CheckNodeIds(profile->top_down()->root(), &nodeId); 603 CheckNodeIds(profile->top_down()->root(), &nodeId);
553 CHECK_EQ(7, nodeId - 1); 604 CHECK_EQ(7, nodeId - 1);
554 605
555 CHECK_EQ(3, profile->samples_count()); 606 CHECK_EQ(3, profile->samples_count());
556 int expected_id[] = {3, 5, 7}; 607 int expected_id[] = {3, 5, 7};
557 for (int i = 0; i < 3; i++) { 608 for (int i = 0; i < 3; i++) {
558 CHECK_EQ(expected_id[i], profile->sample(i)->id()); 609 CHECK_EQ(expected_id[i], profile->sample(i)->id());
559 } 610 }
560 } 611 }
561 612
562 613
563 TEST(NoSamples) { 614 TEST(NoSamples) {
564 TestSetup test_setup; 615 TestSetup test_setup;
565 CpuProfilesCollection profiles; 616 CpuProfilesCollection profiles;
566 profiles.StartProfiling("", 1, false); 617 profiles.StartProfiling("", 1, false);
567 ProfileGenerator generator(&profiles); 618 ProfileGenerator generator(&profiles);
568 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); 619 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
569 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); 620 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
570 621
571 // We are building the following calls tree: 622 // We are building the following calls tree:
572 // (root)#1 -> aaa #2 -> aaa #3 - sample1 623 // (root)#1 -> aaa #2 -> aaa #3 - sample1
573 TickSample sample1; 624 TickSample sample1;
574 sample1.pc = ToAddress(0x1600); 625 sample1.pc = ToAddress(0x1600);
575 sample1.stack[0] = ToAddress(0x1510); 626 sample1.stack[0] = ToAddress(0x1510);
576 sample1.frames_count = 1; 627 sample1.frames_count = 1;
577 generator.RecordTickSample(sample1); 628 generator.RecordTickSample(sample1);
578 629
579 CpuProfile* profile = profiles.StopProfiling(""); 630 CpuProfile* profile = profiles.StopProfiling("", 1);
580 int nodeId = 1; 631 int nodeId = 1;
581 CheckNodeIds(profile->top_down()->root(), &nodeId); 632 CheckNodeIds(profile->top_down()->root(), &nodeId);
582 CHECK_EQ(3, nodeId - 1); 633 CHECK_EQ(3, nodeId - 1);
583 634
584 CHECK_EQ(0, profile->samples_count()); 635 CHECK_EQ(0, profile->samples_count());
585 } 636 }
586 637
587 638
588 // --- P r o f i l e r E x t e n s i o n --- 639 // --- P r o f i l e r E x t e n s i o n ---
589 640
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 875
825 profiler->processor()->StopSynchronously(); 876 profiler->processor()->StopSynchronously();
826 877
827 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); 878 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line"));
828 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); 879 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line"));
829 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); 880 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line"));
830 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); 881 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line"));
831 882
832 profiler->StopProfiling("LineNumber"); 883 profiler->StopProfiling("LineNumber");
833 } 884 }
OLDNEW
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/mjsunit/array-literal-transitions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698