OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 <cstring> | 5 #include <cstring> |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 | 8 |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 int64_t start, | 58 int64_t start, |
59 int64_t end) { | 59 int64_t end) { |
60 ASSERT(recorder != NULL); | 60 ASSERT(recorder != NULL); |
61 ASSERT(start < end); | 61 ASSERT(start < end); |
62 ASSERT(label != NULL); | 62 ASSERT(label != NULL); |
63 TimelineEvent* event = recorder->StartEvent(); | 63 TimelineEvent* event = recorder->StartEvent(); |
64 ASSERT(event != NULL); | 64 ASSERT(event != NULL); |
65 event->Duration(label, start, end); | 65 event->Duration(label, start, end); |
66 } | 66 } |
67 | 67 |
| 68 static void FakeBegin( |
| 69 TimelineEventRecorder* recorder, |
| 70 const char* label, |
| 71 int64_t start) { |
| 72 ASSERT(recorder != NULL); |
| 73 ASSERT(label != NULL); |
| 74 ASSERT(start >= 0); |
| 75 TimelineEvent* event = recorder->StartEvent(); |
| 76 ASSERT(event != NULL); |
| 77 event->Begin(label, start); |
| 78 } |
| 79 |
| 80 static void FakeEnd( |
| 81 TimelineEventRecorder* recorder, |
| 82 const char* label, |
| 83 int64_t end) { |
| 84 ASSERT(recorder != NULL); |
| 85 ASSERT(label != NULL); |
| 86 ASSERT(end >= 0); |
| 87 TimelineEvent* event = recorder->StartEvent(); |
| 88 ASSERT(event != NULL); |
| 89 event->End(label, end); |
| 90 } |
| 91 |
68 static void Clear(TimelineEventEndlessRecorder* recorder) { | 92 static void Clear(TimelineEventEndlessRecorder* recorder) { |
69 ASSERT(recorder != NULL); | 93 ASSERT(recorder != NULL); |
70 recorder->Clear(); | 94 recorder->Clear(); |
71 } | 95 } |
72 | 96 |
73 static void FinishBlock(TimelineEventBlock* block) { | 97 static void FinishBlock(TimelineEventBlock* block) { |
74 block->Finish(); | 98 block->Finish(); |
75 } | 99 } |
76 }; | 100 }; |
77 | 101 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 pauses.CalculatePauseTimesForThread(tid); | 626 pauses.CalculatePauseTimesForThread(tid); |
603 EXPECT(!pauses.has_error()); | 627 EXPECT(!pauses.has_error()); |
604 EXPECT_EQ(10, pauses.InclusiveTime("a")); | 628 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
605 EXPECT_EQ(10, pauses.ExclusiveTime("a")); | 629 EXPECT_EQ(10, pauses.ExclusiveTime("a")); |
606 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); | 630 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
607 EXPECT_EQ(8, pauses.MaxExclusiveTime("a")); | 631 EXPECT_EQ(8, pauses.MaxExclusiveTime("a")); |
608 } | 632 } |
609 TimelineTestHelper::Clear(recorder); | 633 TimelineTestHelper::Clear(recorder); |
610 } | 634 } |
611 | 635 |
| 636 |
| 637 TEST_CASE(TimelinePauses_BeginEnd) { |
| 638 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); |
| 639 ASSERT(recorder != NULL); |
| 640 Zone* zone = thread->zone(); |
| 641 Isolate* isolate = thread->isolate(); |
| 642 ThreadId tid = OSThread::GetCurrentThreadTraceId(); |
| 643 |
| 644 // Test case. |
| 645 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 646 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 647 |
| 648 { |
| 649 TimelinePauses pauses(zone, isolate, recorder); |
| 650 pauses.Setup(); |
| 651 pauses.CalculatePauseTimesForThread(tid); |
| 652 EXPECT(!pauses.has_error()); |
| 653 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 654 EXPECT_EQ(10, pauses.ExclusiveTime("a")); |
| 655 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 656 EXPECT_EQ(10, pauses.MaxExclusiveTime("a")); |
| 657 } |
| 658 TimelineTestHelper::Clear(recorder); |
| 659 |
| 660 // Test case. |
| 661 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 662 TimelineTestHelper::FakeBegin(recorder, "b", 0); |
| 663 TimelineTestHelper::FakeEnd(recorder, "b", 10); |
| 664 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 665 |
| 666 { |
| 667 TimelinePauses pauses(zone, isolate, recorder); |
| 668 pauses.Setup(); |
| 669 pauses.CalculatePauseTimesForThread(tid); |
| 670 EXPECT(!pauses.has_error()); |
| 671 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 672 EXPECT_EQ(0, pauses.ExclusiveTime("a")); |
| 673 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 674 EXPECT_EQ(0, pauses.MaxExclusiveTime("a")); |
| 675 EXPECT_EQ(10, pauses.InclusiveTime("b")); |
| 676 EXPECT_EQ(10, pauses.ExclusiveTime("b")); |
| 677 EXPECT_EQ(10, pauses.MaxInclusiveTime("b")); |
| 678 EXPECT_EQ(10, pauses.MaxExclusiveTime("b")); |
| 679 } |
| 680 TimelineTestHelper::Clear(recorder); |
| 681 |
| 682 // Test case. |
| 683 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 684 TimelineTestHelper::FakeBegin(recorder, "b", 1); |
| 685 TimelineTestHelper::FakeEnd(recorder, "b", 8); |
| 686 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 687 |
| 688 { |
| 689 TimelinePauses pauses(zone, isolate, recorder); |
| 690 pauses.Setup(); |
| 691 pauses.CalculatePauseTimesForThread(tid); |
| 692 EXPECT(!pauses.has_error()); |
| 693 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 694 EXPECT_EQ(3, pauses.ExclusiveTime("a")); |
| 695 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 696 EXPECT_EQ(3, pauses.MaxExclusiveTime("a")); |
| 697 EXPECT_EQ(7, pauses.InclusiveTime("b")); |
| 698 EXPECT_EQ(7, pauses.ExclusiveTime("b")); |
| 699 EXPECT_EQ(7, pauses.MaxInclusiveTime("b")); |
| 700 EXPECT_EQ(7, pauses.MaxExclusiveTime("b")); |
| 701 } |
| 702 TimelineTestHelper::Clear(recorder); |
| 703 |
| 704 // Test case. |
| 705 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 706 TimelineTestHelper::FakeDuration(recorder, "b", 0, 1); |
| 707 TimelineTestHelper::FakeDuration(recorder, "b", 1, 2); |
| 708 TimelineTestHelper::FakeDuration(recorder, "b", 2, 3); |
| 709 TimelineTestHelper::FakeBegin(recorder, "b", 3); |
| 710 TimelineTestHelper::FakeEnd(recorder, "b", 4); |
| 711 TimelineTestHelper::FakeDuration(recorder, "b", 4, 5); |
| 712 TimelineTestHelper::FakeDuration(recorder, "b", 5, 6); |
| 713 TimelineTestHelper::FakeDuration(recorder, "b", 6, 7); |
| 714 TimelineTestHelper::FakeBegin(recorder, "b", 7); |
| 715 TimelineTestHelper::FakeEnd(recorder, "b", 8); |
| 716 TimelineTestHelper::FakeBegin(recorder, "b", 8); |
| 717 TimelineTestHelper::FakeEnd(recorder, "b", 9); |
| 718 TimelineTestHelper::FakeDuration(recorder, "b", 9, 10); |
| 719 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 720 |
| 721 { |
| 722 TimelinePauses pauses(zone, isolate, recorder); |
| 723 pauses.Setup(); |
| 724 pauses.CalculatePauseTimesForThread(tid); |
| 725 EXPECT(!pauses.has_error()); |
| 726 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 727 EXPECT_EQ(0, pauses.ExclusiveTime("a")); |
| 728 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 729 EXPECT_EQ(0, pauses.MaxExclusiveTime("a")); |
| 730 EXPECT_EQ(10, pauses.InclusiveTime("b")); |
| 731 EXPECT_EQ(10, pauses.ExclusiveTime("b")); |
| 732 EXPECT_EQ(1, pauses.MaxInclusiveTime("b")); |
| 733 EXPECT_EQ(1, pauses.MaxExclusiveTime("b")); |
| 734 } |
| 735 TimelineTestHelper::Clear(recorder); |
| 736 |
| 737 // Test case. |
| 738 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 739 TimelineTestHelper::FakeBegin(recorder, "b", 0); |
| 740 TimelineTestHelper::FakeBegin(recorder, "c", 1); |
| 741 TimelineTestHelper::FakeEnd(recorder, "c", 4); |
| 742 TimelineTestHelper::FakeEnd(recorder, "b", 5); |
| 743 TimelineTestHelper::FakeBegin(recorder, "d", 5); |
| 744 TimelineTestHelper::FakeEnd(recorder, "d", 10); |
| 745 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 746 |
| 747 { |
| 748 TimelinePauses pauses(zone, isolate, recorder); |
| 749 pauses.Setup(); |
| 750 pauses.CalculatePauseTimesForThread(tid); |
| 751 EXPECT(!pauses.has_error()); |
| 752 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 753 EXPECT_EQ(0, pauses.ExclusiveTime("a")); |
| 754 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 755 EXPECT_EQ(0, pauses.MaxExclusiveTime("a")); |
| 756 EXPECT_EQ(5, pauses.InclusiveTime("b")); |
| 757 EXPECT_EQ(2, pauses.ExclusiveTime("b")); |
| 758 EXPECT_EQ(5, pauses.MaxInclusiveTime("b")); |
| 759 EXPECT_EQ(2, pauses.MaxExclusiveTime("b")); |
| 760 EXPECT_EQ(3, pauses.InclusiveTime("c")); |
| 761 EXPECT_EQ(3, pauses.ExclusiveTime("c")); |
| 762 EXPECT_EQ(3, pauses.MaxInclusiveTime("c")); |
| 763 EXPECT_EQ(3, pauses.MaxExclusiveTime("c")); |
| 764 EXPECT_EQ(5, pauses.InclusiveTime("d")); |
| 765 EXPECT_EQ(5, pauses.ExclusiveTime("d")); |
| 766 EXPECT_EQ(5, pauses.MaxInclusiveTime("d")); |
| 767 EXPECT_EQ(5, pauses.MaxExclusiveTime("d")); |
| 768 } |
| 769 TimelineTestHelper::Clear(recorder); |
| 770 |
| 771 // Test case. |
| 772 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 773 TimelineTestHelper::FakeBegin(recorder, "b", 1); |
| 774 TimelineTestHelper::FakeBegin(recorder, "c", 2); |
| 775 TimelineTestHelper::FakeBegin(recorder, "d", 3); |
| 776 TimelineTestHelper::FakeBegin(recorder, "e", 4); |
| 777 TimelineTestHelper::FakeEnd(recorder, "e", 6); |
| 778 TimelineTestHelper::FakeEnd(recorder, "d", 7); |
| 779 TimelineTestHelper::FakeEnd(recorder, "c", 8); |
| 780 TimelineTestHelper::FakeEnd(recorder, "b", 9); |
| 781 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 782 |
| 783 { |
| 784 TimelinePauses pauses(zone, isolate, recorder); |
| 785 pauses.Setup(); |
| 786 pauses.CalculatePauseTimesForThread(tid); |
| 787 EXPECT(!pauses.has_error()); |
| 788 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 789 EXPECT_EQ(2, pauses.ExclusiveTime("a")); |
| 790 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 791 EXPECT_EQ(2, pauses.MaxExclusiveTime("a")); |
| 792 EXPECT_EQ(8, pauses.InclusiveTime("b")); |
| 793 EXPECT_EQ(2, pauses.ExclusiveTime("b")); |
| 794 EXPECT_EQ(8, pauses.MaxInclusiveTime("b")); |
| 795 EXPECT_EQ(2, pauses.MaxExclusiveTime("b")); |
| 796 EXPECT_EQ(6, pauses.InclusiveTime("c")); |
| 797 EXPECT_EQ(2, pauses.ExclusiveTime("c")); |
| 798 EXPECT_EQ(6, pauses.MaxInclusiveTime("c")); |
| 799 EXPECT_EQ(2, pauses.MaxExclusiveTime("c")); |
| 800 EXPECT_EQ(4, pauses.InclusiveTime("d")); |
| 801 EXPECT_EQ(2, pauses.ExclusiveTime("d")); |
| 802 EXPECT_EQ(4, pauses.MaxInclusiveTime("d")); |
| 803 EXPECT_EQ(2, pauses.MaxExclusiveTime("d")); |
| 804 EXPECT_EQ(2, pauses.InclusiveTime("e")); |
| 805 EXPECT_EQ(2, pauses.ExclusiveTime("e")); |
| 806 EXPECT_EQ(2, pauses.MaxInclusiveTime("e")); |
| 807 EXPECT_EQ(2, pauses.MaxExclusiveTime("e")); |
| 808 } |
| 809 TimelineTestHelper::Clear(recorder); |
| 810 |
| 811 // Test case. |
| 812 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 813 TimelineTestHelper::FakeBegin(recorder, "a", 1); |
| 814 TimelineTestHelper::FakeEnd(recorder, "a", 9); |
| 815 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 816 |
| 817 { |
| 818 TimelinePauses pauses(zone, isolate, recorder); |
| 819 pauses.Setup(); |
| 820 pauses.CalculatePauseTimesForThread(tid); |
| 821 EXPECT(!pauses.has_error()); |
| 822 EXPECT_EQ(10, pauses.InclusiveTime("a")); |
| 823 EXPECT_EQ(10, pauses.ExclusiveTime("a")); |
| 824 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); |
| 825 EXPECT_EQ(8, pauses.MaxExclusiveTime("a")); |
| 826 } |
| 827 TimelineTestHelper::Clear(recorder); |
| 828 |
| 829 // Test case. |
| 830 TimelineTestHelper::FakeBegin(recorder, "a", 0); |
| 831 TimelineTestHelper::FakeBegin(recorder, "b", 1); |
| 832 // Pop "a" without popping "b" first. |
| 833 TimelineTestHelper::FakeEnd(recorder, "a", 10); |
| 834 |
| 835 { |
| 836 TimelinePauses pauses(zone, isolate, recorder); |
| 837 pauses.Setup(); |
| 838 pauses.CalculatePauseTimesForThread(tid); |
| 839 EXPECT(pauses.has_error()); |
| 840 } |
| 841 TimelineTestHelper::Clear(recorder); |
| 842 } |
| 843 |
612 } // namespace dart | 844 } // namespace dart |
OLD | NEW |