| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests for heap profiler | 3 // Tests for heap profiler |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
| 9 #include "snapshot.h" | 9 #include "snapshot.h" |
| 10 #include "utils-inl.h" | 10 #include "utils-inl.h" |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 CHECK_GT(stream.size(), 0); | 685 CHECK_GT(stream.size(), 0); |
| 686 CHECK_EQ(0, stream.eos_signaled()); | 686 CHECK_EQ(0, stream.eos_signaled()); |
| 687 } | 687 } |
| 688 | 688 |
| 689 namespace { | 689 namespace { |
| 690 | 690 |
| 691 class TestStatsStream : public v8::OutputStream { | 691 class TestStatsStream : public v8::OutputStream { |
| 692 public: | 692 public: |
| 693 TestStatsStream() | 693 TestStatsStream() |
| 694 : eos_signaled_(0), | 694 : eos_signaled_(0), |
| 695 numbers_written_(0), | 695 updates_written_(0), |
| 696 entries_count_(0), | 696 entries_count_(0), |
| 697 entries_size_(0), | 697 entries_size_(0), |
| 698 intervals_count_(0), | 698 intervals_count_(0), |
| 699 first_interval_index_(-1) { } | 699 first_interval_index_(-1) { } |
| 700 TestStatsStream(const TestStatsStream& stream) | 700 TestStatsStream(const TestStatsStream& stream) |
| 701 : v8::OutputStream(stream), | 701 : v8::OutputStream(stream), |
| 702 eos_signaled_(stream.eos_signaled_), | 702 eos_signaled_(stream.eos_signaled_), |
| 703 numbers_written_(stream.numbers_written_), | 703 updates_written_(stream.updates_written_), |
| 704 entries_count_(stream.entries_count_), | 704 entries_count_(stream.entries_count_), |
| 705 entries_size_(stream.entries_size_), | 705 entries_size_(stream.entries_size_), |
| 706 intervals_count_(stream.intervals_count_), | 706 intervals_count_(stream.intervals_count_), |
| 707 first_interval_index_(stream.first_interval_index_) { } | 707 first_interval_index_(stream.first_interval_index_) { } |
| 708 virtual ~TestStatsStream() {} | 708 virtual ~TestStatsStream() {} |
| 709 virtual void EndOfStream() { ++eos_signaled_; } | 709 virtual void EndOfStream() { ++eos_signaled_; } |
| 710 virtual WriteResult WriteAsciiChunk(char* buffer, int chars_written) { | 710 virtual WriteResult WriteAsciiChunk(char* buffer, int chars_written) { |
| 711 ASSERT(false); | 711 ASSERT(false); |
| 712 return kAbort; | 712 return kAbort; |
| 713 } | 713 } |
| 714 virtual WriteResult WriteUint32Chunk(uint32_t* buffer, int numbers_written) { | 714 virtual WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* buffer, |
| 715 int updates_written) { |
| 715 ++intervals_count_; | 716 ++intervals_count_; |
| 716 ASSERT(numbers_written); | 717 ASSERT(updates_written); |
| 717 numbers_written_ += numbers_written; | 718 updates_written_ += updates_written; |
| 718 entries_count_ = 0; | 719 entries_count_ = 0; |
| 719 if (first_interval_index_ == -1 && numbers_written != 0) | 720 if (first_interval_index_ == -1 && updates_written != 0) |
| 720 first_interval_index_ = buffer[0]; | 721 first_interval_index_ = buffer[0].index; |
| 721 for (int i = 0; i < numbers_written; i += 3) { | 722 for (int i = 0; i < updates_written; ++i) { |
| 722 entries_count_ += buffer[i+1]; | 723 entries_count_ += buffer[i].count; |
| 723 entries_size_ += buffer[i+2]; | 724 entries_size_ += buffer[i].size; |
| 724 } | 725 } |
| 725 | 726 |
| 726 return kContinue; | 727 return kContinue; |
| 727 } | 728 } |
| 728 int eos_signaled() { return eos_signaled_; } | 729 int eos_signaled() { return eos_signaled_; } |
| 729 int numbers_written() { return numbers_written_; } | 730 int updates_written() { return updates_written_; } |
| 730 uint32_t entries_count() const { return entries_count_; } | 731 uint32_t entries_count() const { return entries_count_; } |
| 731 uint32_t entries_size() const { return entries_size_; } | 732 uint32_t entries_size() const { return entries_size_; } |
| 732 int intervals_count() const { return intervals_count_; } | 733 int intervals_count() const { return intervals_count_; } |
| 733 int first_interval_index() const { return first_interval_index_; } | 734 int first_interval_index() const { return first_interval_index_; } |
| 734 | 735 |
| 735 private: | 736 private: |
| 736 int eos_signaled_; | 737 int eos_signaled_; |
| 737 int numbers_written_; | 738 int updates_written_; |
| 738 uint32_t entries_count_; | 739 uint32_t entries_count_; |
| 739 uint32_t entries_size_; | 740 uint32_t entries_size_; |
| 740 int intervals_count_; | 741 int intervals_count_; |
| 741 int first_interval_index_; | 742 int first_interval_index_; |
| 742 }; | 743 }; |
| 743 | 744 |
| 744 } // namespace | 745 } // namespace |
| 745 | 746 |
| 746 static TestStatsStream GetHeapStatsUpdate() { | 747 static TestStatsStream GetHeapStatsUpdate() { |
| 747 TestStatsStream stream; | 748 TestStatsStream stream; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 759 // We have to call GC 5 times. In other case the garbage will be | 760 // We have to call GC 5 times. In other case the garbage will be |
| 760 // the reason of flakiness. | 761 // the reason of flakiness. |
| 761 for (int i = 0; i < 5; ++i) { | 762 for (int i = 0; i < 5; ++i) { |
| 762 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 763 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 763 } | 764 } |
| 764 | 765 |
| 765 { | 766 { |
| 766 // Single chunk of data expected in update. Initial data. | 767 // Single chunk of data expected in update. Initial data. |
| 767 TestStatsStream stats_update = GetHeapStatsUpdate(); | 768 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 768 CHECK_EQ(1, stats_update.intervals_count()); | 769 CHECK_EQ(1, stats_update.intervals_count()); |
| 769 CHECK_EQ(3, stats_update.numbers_written()); | 770 CHECK_EQ(1, stats_update.updates_written()); |
| 770 CHECK_LT(0, stats_update.entries_size()); | 771 CHECK_LT(0, stats_update.entries_size()); |
| 771 CHECK_EQ(0, stats_update.first_interval_index()); | 772 CHECK_EQ(0, stats_update.first_interval_index()); |
| 772 } | 773 } |
| 773 | 774 |
| 774 // No data expected in update because nothing has happened. | 775 // No data expected in update because nothing has happened. |
| 775 CHECK_EQ(0, GetHeapStatsUpdate().numbers_written()); | 776 CHECK_EQ(0, GetHeapStatsUpdate().updates_written()); |
| 776 { | 777 { |
| 777 v8::HandleScope inner_scope_1; | 778 v8::HandleScope inner_scope_1; |
| 778 v8_str("string1"); | 779 v8_str("string1"); |
| 779 { | 780 { |
| 780 // Single chunk of data with one new entry expected in update. | 781 // Single chunk of data with one new entry expected in update. |
| 781 TestStatsStream stats_update = GetHeapStatsUpdate(); | 782 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 782 CHECK_EQ(1, stats_update.intervals_count()); | 783 CHECK_EQ(1, stats_update.intervals_count()); |
| 783 CHECK_EQ(3, stats_update.numbers_written()); | 784 CHECK_EQ(1, stats_update.updates_written()); |
| 784 CHECK_LT(0, stats_update.entries_size()); | 785 CHECK_LT(0, stats_update.entries_size()); |
| 785 CHECK_EQ(1, stats_update.entries_count()); | 786 CHECK_EQ(1, stats_update.entries_count()); |
| 786 CHECK_EQ(2, stats_update.first_interval_index()); | 787 CHECK_EQ(2, stats_update.first_interval_index()); |
| 787 } | 788 } |
| 788 | 789 |
| 789 // No data expected in update because nothing happened. | 790 // No data expected in update because nothing happened. |
| 790 CHECK_EQ(0, GetHeapStatsUpdate().numbers_written()); | 791 CHECK_EQ(0, GetHeapStatsUpdate().updates_written()); |
| 791 | 792 |
| 792 { | 793 { |
| 793 v8::HandleScope inner_scope_2; | 794 v8::HandleScope inner_scope_2; |
| 794 v8_str("string2"); | 795 v8_str("string2"); |
| 795 | 796 |
| 796 uint32_t entries_size; | 797 uint32_t entries_size; |
| 797 { | 798 { |
| 798 v8::HandleScope inner_scope_3; | 799 v8::HandleScope inner_scope_3; |
| 799 v8_str("string3"); | 800 v8_str("string3"); |
| 800 v8_str("string4"); | 801 v8_str("string4"); |
| 801 | 802 |
| 802 { | 803 { |
| 803 // Single chunk of data with three new entries expected in update. | 804 // Single chunk of data with three new entries expected in update. |
| 804 TestStatsStream stats_update = GetHeapStatsUpdate(); | 805 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 805 CHECK_EQ(1, stats_update.intervals_count()); | 806 CHECK_EQ(1, stats_update.intervals_count()); |
| 806 CHECK_EQ(3, stats_update.numbers_written()); | 807 CHECK_EQ(1, stats_update.updates_written()); |
| 807 CHECK_LT(0, entries_size = stats_update.entries_size()); | 808 CHECK_LT(0, entries_size = stats_update.entries_size()); |
| 808 CHECK_EQ(3, stats_update.entries_count()); | 809 CHECK_EQ(3, stats_update.entries_count()); |
| 809 CHECK_EQ(4, stats_update.first_interval_index()); | 810 CHECK_EQ(4, stats_update.first_interval_index()); |
| 810 } | 811 } |
| 811 } | 812 } |
| 812 | 813 |
| 813 { | 814 { |
| 814 // Single chunk of data with two left entries expected in update. | 815 // Single chunk of data with two left entries expected in update. |
| 815 TestStatsStream stats_update = GetHeapStatsUpdate(); | 816 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 816 CHECK_EQ(1, stats_update.intervals_count()); | 817 CHECK_EQ(1, stats_update.intervals_count()); |
| 817 CHECK_EQ(3, stats_update.numbers_written()); | 818 CHECK_EQ(1, stats_update.updates_written()); |
| 818 CHECK_GT(entries_size, stats_update.entries_size()); | 819 CHECK_GT(entries_size, stats_update.entries_size()); |
| 819 CHECK_EQ(1, stats_update.entries_count()); | 820 CHECK_EQ(1, stats_update.entries_count()); |
| 820 // Two strings from forth interval were released. | 821 // Two strings from forth interval were released. |
| 821 CHECK_EQ(4, stats_update.first_interval_index()); | 822 CHECK_EQ(4, stats_update.first_interval_index()); |
| 822 } | 823 } |
| 823 } | 824 } |
| 824 | 825 |
| 825 { | 826 { |
| 826 // Single chunk of data with 0 left entries expected in update. | 827 // Single chunk of data with 0 left entries expected in update. |
| 827 TestStatsStream stats_update = GetHeapStatsUpdate(); | 828 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 828 CHECK_EQ(1, stats_update.intervals_count()); | 829 CHECK_EQ(1, stats_update.intervals_count()); |
| 829 CHECK_EQ(3, stats_update.numbers_written()); | 830 CHECK_EQ(1, stats_update.updates_written()); |
| 830 CHECK_EQ(0, stats_update.entries_size()); | 831 CHECK_EQ(0, stats_update.entries_size()); |
| 831 CHECK_EQ(0, stats_update.entries_count()); | 832 CHECK_EQ(0, stats_update.entries_count()); |
| 832 // The last string from forth interval was released. | 833 // The last string from forth interval was released. |
| 833 CHECK_EQ(4, stats_update.first_interval_index()); | 834 CHECK_EQ(4, stats_update.first_interval_index()); |
| 834 } | 835 } |
| 835 } | 836 } |
| 836 { | 837 { |
| 837 // Single chunk of data with 0 left entries expected in update. | 838 // Single chunk of data with 0 left entries expected in update. |
| 838 TestStatsStream stats_update = GetHeapStatsUpdate(); | 839 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 839 CHECK_EQ(1, stats_update.intervals_count()); | 840 CHECK_EQ(1, stats_update.intervals_count()); |
| 840 CHECK_EQ(3, stats_update.numbers_written()); | 841 CHECK_EQ(1, stats_update.updates_written()); |
| 841 CHECK_EQ(0, stats_update.entries_size()); | 842 CHECK_EQ(0, stats_update.entries_size()); |
| 842 CHECK_EQ(0, stats_update.entries_count()); | 843 CHECK_EQ(0, stats_update.entries_count()); |
| 843 // The only string from the second interval was released. | 844 // The only string from the second interval was released. |
| 844 CHECK_EQ(2, stats_update.first_interval_index()); | 845 CHECK_EQ(2, stats_update.first_interval_index()); |
| 845 } | 846 } |
| 846 | 847 |
| 847 v8::Local<v8::Array> array = v8::Array::New(); | 848 v8::Local<v8::Array> array = v8::Array::New(); |
| 848 CHECK_EQ(0, array->Length()); | 849 CHECK_EQ(0, array->Length()); |
| 849 // Force array's buffer allocation. | 850 // Force array's buffer allocation. |
| 850 array->Set(2, v8_num(7)); | 851 array->Set(2, v8_num(7)); |
| 851 | 852 |
| 852 uint32_t entries_size; | 853 uint32_t entries_size; |
| 853 { | 854 { |
| 854 // Single chunk of data with 2 entries expected in update. | 855 // Single chunk of data with 2 entries expected in update. |
| 855 TestStatsStream stats_update = GetHeapStatsUpdate(); | 856 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 856 CHECK_EQ(1, stats_update.intervals_count()); | 857 CHECK_EQ(1, stats_update.intervals_count()); |
| 857 CHECK_EQ(3, stats_update.numbers_written()); | 858 CHECK_EQ(1, stats_update.updates_written()); |
| 858 CHECK_LT(0, entries_size = stats_update.entries_size()); | 859 CHECK_LT(0, entries_size = stats_update.entries_size()); |
| 859 // They are the array and its buffer. | 860 // They are the array and its buffer. |
| 860 CHECK_EQ(2, stats_update.entries_count()); | 861 CHECK_EQ(2, stats_update.entries_count()); |
| 861 CHECK_EQ(8, stats_update.first_interval_index()); | 862 CHECK_EQ(8, stats_update.first_interval_index()); |
| 862 } | 863 } |
| 863 | 864 |
| 864 for (int i = 0; i < 100; ++i) | 865 for (int i = 0; i < 100; ++i) |
| 865 array->Set(i, v8_num(i)); | 866 array->Set(i, v8_num(i)); |
| 866 | 867 |
| 867 { | 868 { |
| 868 // Single chunk of data with 1 entry expected in update. | 869 // Single chunk of data with 1 entry expected in update. |
| 869 TestStatsStream stats_update = GetHeapStatsUpdate(); | 870 TestStatsStream stats_update = GetHeapStatsUpdate(); |
| 870 CHECK_EQ(1, stats_update.intervals_count()); | 871 CHECK_EQ(1, stats_update.intervals_count()); |
| 871 // The first interval was changed because old buffer was collected. | 872 // The first interval was changed because old buffer was collected. |
| 872 // The second interval was changed because new buffer was allocated. | 873 // The second interval was changed because new buffer was allocated. |
| 873 CHECK_EQ(6, stats_update.numbers_written()); | 874 CHECK_EQ(2, stats_update.updates_written()); |
| 874 CHECK_LT(entries_size, stats_update.entries_size()); | 875 CHECK_LT(entries_size, stats_update.entries_size()); |
| 875 CHECK_EQ(2, stats_update.entries_count()); | 876 CHECK_EQ(2, stats_update.entries_count()); |
| 876 CHECK_EQ(8, stats_update.first_interval_index()); | 877 CHECK_EQ(8, stats_update.first_interval_index()); |
| 877 } | 878 } |
| 878 | 879 |
| 879 v8::HeapProfiler::StopHeapObjectsTracking(); | 880 v8::HeapProfiler::StopHeapObjectsTracking(); |
| 880 } | 881 } |
| 881 | 882 |
| 882 | 883 |
| 883 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, | 884 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 // Dipose the persistent handles in a different order. | 1589 // Dipose the persistent handles in a different order. |
| 1589 p_AAA.Dispose(); | 1590 p_AAA.Dispose(); |
| 1590 CHECK_EQ(global_handle_count + 2, | 1591 CHECK_EQ(global_handle_count + 2, |
| 1591 v8::HeapProfiler::GetPersistentHandleCount()); | 1592 v8::HeapProfiler::GetPersistentHandleCount()); |
| 1592 p_CCC.Dispose(); | 1593 p_CCC.Dispose(); |
| 1593 CHECK_EQ(global_handle_count + 1, | 1594 CHECK_EQ(global_handle_count + 1, |
| 1594 v8::HeapProfiler::GetPersistentHandleCount()); | 1595 v8::HeapProfiler::GetPersistentHandleCount()); |
| 1595 p_BBB.Dispose(); | 1596 p_BBB.Dispose(); |
| 1596 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); | 1597 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); |
| 1597 } | 1598 } |
| OLD | NEW |