OLD | NEW |
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 Loading... |
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; | |
45 using i::TickSample; | 44 using i::TickSample; |
46 using i::Vector; | 45 using i::Vector; |
47 | 46 |
48 | 47 |
49 TEST(ProfileNodeFindOrAddChild) { | 48 TEST(ProfileNodeFindOrAddChild) { |
50 ProfileTree tree; | 49 ProfileTree tree; |
51 ProfileNode node(&tree, NULL); | 50 ProfileNode node(&tree, NULL); |
52 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); | 51 CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa"); |
53 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); | 52 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); |
54 CHECK_NE(NULL, childNode1); | 53 CHECK_NE(NULL, childNode1); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 sample2.frames_count = 3; | 477 sample2.frames_count = 3; |
479 generator.RecordTickSample(sample2); | 478 generator.RecordTickSample(sample2); |
480 TickSample sample3; | 479 TickSample sample3; |
481 sample3.pc = ToAddress(0x1510); | 480 sample3.pc = ToAddress(0x1510); |
482 sample3.tos = ToAddress(0x1500); | 481 sample3.tos = ToAddress(0x1500); |
483 sample3.stack[0] = ToAddress(0x1910); | 482 sample3.stack[0] = ToAddress(0x1910); |
484 sample3.stack[1] = ToAddress(0x1610); | 483 sample3.stack[1] = ToAddress(0x1610); |
485 sample3.frames_count = 2; | 484 sample3.frames_count = 2; |
486 generator.RecordTickSample(sample3); | 485 generator.RecordTickSample(sample3); |
487 | 486 |
488 CpuProfile* profile = profiles.StopProfiling("", 1); | 487 CpuProfile* profile = profiles.StopProfiling(""); |
489 CHECK_NE(NULL, profile); | 488 CHECK_NE(NULL, profile); |
490 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); | 489 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); |
491 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); | 490 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); |
492 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); | 491 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); |
493 ProfileNode* node1 = top_down_test_helper.Walk(entry1); | 492 ProfileNode* node1 = top_down_test_helper.Walk(entry1); |
494 CHECK_NE(NULL, node1); | 493 CHECK_NE(NULL, node1); |
495 CHECK_EQ(entry1, node1->entry()); | 494 CHECK_EQ(entry1, node1->entry()); |
496 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); | 495 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); |
497 CHECK_NE(NULL, node2); | 496 CHECK_NE(NULL, node2); |
498 CHECK_EQ(entry1, node2->entry()); | 497 CHECK_EQ(entry1, node2->entry()); |
499 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); | 498 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); |
500 CHECK_NE(NULL, node3); | 499 CHECK_NE(NULL, node3); |
501 CHECK_EQ(entry3, node3->entry()); | 500 CHECK_EQ(entry3, node3->entry()); |
502 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); | 501 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); |
503 CHECK_NE(NULL, node4); | 502 CHECK_NE(NULL, node4); |
504 CHECK_EQ(entry1, node4->entry()); | 503 CHECK_EQ(entry1, node4->entry()); |
505 } | 504 } |
506 | 505 |
507 | 506 |
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 | |
558 static void CheckNodeIds(ProfileNode* node, int* expectedId) { | 507 static void CheckNodeIds(ProfileNode* node, int* expectedId) { |
559 CHECK_EQ((*expectedId)++, node->id()); | 508 CHECK_EQ((*expectedId)++, node->id()); |
560 for (int i = 0; i < node->children()->length(); i++) { | 509 for (int i = 0; i < node->children()->length(); i++) { |
561 CheckNodeIds(node->children()->at(i), expectedId); | 510 CheckNodeIds(node->children()->at(i), expectedId); |
562 } | 511 } |
563 } | 512 } |
564 | 513 |
565 | 514 |
566 TEST(SampleIds) { | 515 TEST(SampleIds) { |
567 TestSetup test_setup; | 516 TestSetup test_setup; |
(...skipping 23 matching lines...) Expand all Loading... |
591 sample2.stack[2] = ToAddress(0x1620); | 540 sample2.stack[2] = ToAddress(0x1620); |
592 sample2.frames_count = 3; | 541 sample2.frames_count = 3; |
593 generator.RecordTickSample(sample2); | 542 generator.RecordTickSample(sample2); |
594 TickSample sample3; | 543 TickSample sample3; |
595 sample3.pc = ToAddress(0x1510); | 544 sample3.pc = ToAddress(0x1510); |
596 sample3.stack[0] = ToAddress(0x1910); | 545 sample3.stack[0] = ToAddress(0x1910); |
597 sample3.stack[1] = ToAddress(0x1610); | 546 sample3.stack[1] = ToAddress(0x1610); |
598 sample3.frames_count = 2; | 547 sample3.frames_count = 2; |
599 generator.RecordTickSample(sample3); | 548 generator.RecordTickSample(sample3); |
600 | 549 |
601 CpuProfile* profile = profiles.StopProfiling("", 1); | 550 CpuProfile* profile = profiles.StopProfiling(""); |
602 int nodeId = 1; | 551 int nodeId = 1; |
603 CheckNodeIds(profile->top_down()->root(), &nodeId); | 552 CheckNodeIds(profile->top_down()->root(), &nodeId); |
604 CHECK_EQ(7, nodeId - 1); | 553 CHECK_EQ(7, nodeId - 1); |
605 | 554 |
606 CHECK_EQ(3, profile->samples_count()); | 555 CHECK_EQ(3, profile->samples_count()); |
607 int expected_id[] = {3, 5, 7}; | 556 int expected_id[] = {3, 5, 7}; |
608 for (int i = 0; i < 3; i++) { | 557 for (int i = 0; i < 3; i++) { |
609 CHECK_EQ(expected_id[i], profile->sample(i)->id()); | 558 CHECK_EQ(expected_id[i], profile->sample(i)->id()); |
610 } | 559 } |
611 } | 560 } |
612 | 561 |
613 | 562 |
614 TEST(NoSamples) { | 563 TEST(NoSamples) { |
615 TestSetup test_setup; | 564 TestSetup test_setup; |
616 CpuProfilesCollection profiles; | 565 CpuProfilesCollection profiles; |
617 profiles.StartProfiling("", 1, false); | 566 profiles.StartProfiling("", 1, false); |
618 ProfileGenerator generator(&profiles); | 567 ProfileGenerator generator(&profiles); |
619 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); | 568 CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); |
620 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); | 569 generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200); |
621 | 570 |
622 // We are building the following calls tree: | 571 // We are building the following calls tree: |
623 // (root)#1 -> aaa #2 -> aaa #3 - sample1 | 572 // (root)#1 -> aaa #2 -> aaa #3 - sample1 |
624 TickSample sample1; | 573 TickSample sample1; |
625 sample1.pc = ToAddress(0x1600); | 574 sample1.pc = ToAddress(0x1600); |
626 sample1.stack[0] = ToAddress(0x1510); | 575 sample1.stack[0] = ToAddress(0x1510); |
627 sample1.frames_count = 1; | 576 sample1.frames_count = 1; |
628 generator.RecordTickSample(sample1); | 577 generator.RecordTickSample(sample1); |
629 | 578 |
630 CpuProfile* profile = profiles.StopProfiling("", 1); | 579 CpuProfile* profile = profiles.StopProfiling(""); |
631 int nodeId = 1; | 580 int nodeId = 1; |
632 CheckNodeIds(profile->top_down()->root(), &nodeId); | 581 CheckNodeIds(profile->top_down()->root(), &nodeId); |
633 CHECK_EQ(3, nodeId - 1); | 582 CHECK_EQ(3, nodeId - 1); |
634 | 583 |
635 CHECK_EQ(0, profile->samples_count()); | 584 CHECK_EQ(0, profile->samples_count()); |
636 } | 585 } |
637 | 586 |
638 | 587 |
639 // --- P r o f i l e r E x t e n s i o n --- | 588 // --- P r o f i l e r E x t e n s i o n --- |
640 | 589 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 824 |
876 profiler->processor()->StopSynchronously(); | 825 profiler->processor()->StopSynchronously(); |
877 | 826 |
878 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); | 827 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line")); |
879 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); | 828 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); |
880 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); | 829 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); |
881 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); | 830 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); |
882 | 831 |
883 profiler->StopProfiling("LineNumber"); | 832 profiler->StopProfiling("LineNumber"); |
884 } | 833 } |
OLD | NEW |