Chromium Code Reviews| Index: src/heap.h |
| diff --git a/src/heap.h b/src/heap.h |
| index e75c7231ffdd9ea90349584f3a21336e50db9506..89a637bf9dd9778591e0b0831e91c627751f87a6 100644 |
| --- a/src/heap.h |
| +++ b/src/heap.h |
| @@ -547,10 +547,62 @@ enum ArrayStorageAllocationMode { |
| INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
| }; |
| +// TODO(ernstm): comments and unit test. Move into GCTracer? |
| +template<typename T, size_t MAX_SIZE> |
| +class RingBuffer { |
| + public: |
| + class const_iterator { |
| + public: |
| + const_iterator() : ring_buffer_(NULL) {} |
| + const_iterator(size_t index, const RingBuffer* ring_buffer) : |
| + index_(index), ring_buffer_(ring_buffer) {} |
| + operator bool() const { return ring_buffer_ != NULL; } |
| + const T* operator->() const { return ring_buffer_->elements_ + index_; } |
| + const T& operator*() const { return ring_buffer_->elements_[index_]; } |
| + const_iterator& operator++() { |
| + index_ = (index_ + 1) % MAX_SIZE; |
| + if (index_ == ring_buffer_->end_) |
| + *this = const_iterator(); |
| + |
| + return *this; |
| + } |
| + const_iterator& operator--() { |
| + if (index_ == ring_buffer_->begin_) |
| + *this = const_iterator(); |
| + else |
| + index_ = (index_ + MAX_SIZE - 1) % MAX_SIZE; |
| + |
| + return *this; |
| + } |
| + |
| + private: |
| + size_t index_; |
| + const RingBuffer* ring_buffer_; |
| + }; |
| + |
| + RingBuffer() : begin_(0), end_(0) {} |
| + |
| + const_iterator begin() const { return const_iterator(begin_, this); } |
| + const_iterator end() const { return const_iterator(end_, this); } |
| + const_iterator back() const { return --end(); } |
| + void push_back(const T& element) { |
| + elements_[end_] = element; |
| + end_ = (end_ + 1) % MAX_SIZE; |
| + if (end_ == begin_) |
| + ++begin_; |
| + } |
| + |
| + private: |
| + T elements_[MAX_SIZE]; |
| + size_t begin_; |
| + size_t end_; |
| +}; |
| + |
| // GCTracer collects and prints ONE line after each garbage collector |
| // invocation IFF --trace_gc is used. |
| +// TODO(ernstm): unit tests. move to separate file. |
| class GCTracer BASE_EMBEDDED { |
| public: |
| class Scope BASE_EMBEDDED { |
| @@ -585,7 +637,8 @@ class GCTracer BASE_EMBEDDED { |
| ~Scope() { |
| ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
| - tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; |
| + tracer_->pending_.scopes[scope_] += |
| + base::OS::TimeCurrentMillis() - start_time_; |
| } |
| private: |
| @@ -596,73 +649,113 @@ class GCTracer BASE_EMBEDDED { |
| DISALLOW_COPY_AND_ASSIGN(Scope); |
| }; |
| + |
| + struct Event { |
|
Hannes Payer (out of office)
2014/07/22 09:10:17
C++ style guide: Use a struct only for passive obj
ernstm
2014/07/22 14:09:29
Done.
|
| + Event(); |
| + |
| + Event(GarbageCollector collector, |
| + const char* gc_reason, |
| + const char* collector_reason); |
| + |
| + // Type of collector. |
| + GarbageCollector collector; |
| + |
| + const char* gc_reason; |
| + const char* collector_reason; |
| + |
| + // Timestamp set in the constructor. |
| + double start_time; |
| + |
| + // Timestamp set in the destructor. |
| + double end_time; |
| + |
| + // Size of objects in heap set in constructor. |
| + intptr_t start_object_size; |
| + |
| + // Size of objects in heap set in destructor. |
| + intptr_t end_object_size; |
| + |
| + // Size of memory allocated from OS set in constructor. |
| + intptr_t start_memory_size; |
| + |
| + // Size of memory allocated from OS set in destructor. |
| + intptr_t end_memory_size; |
| + |
| + // Total amount of space either wasted or contained in one of free lists |
| + // before the current GC. |
| + intptr_t start_holes_size; |
| + |
| + // Total amount of space either wasted or contained in one of free lists |
| + // after the current GC. |
| + intptr_t end_holes_size; |
| + |
| + // Number of incremental marking steps since creation of tracer. |
| + // (value at start of event) |
| + int incremental_marking_steps; |
| + |
| + // Cumulative duration of incremental marking steps since creation of |
| + // tracer. (value at start of event) |
| + double incremental_marking_duration; |
| + |
| + // Longest incremental marking step since start of marking. |
| + // (value at start of event) |
| + double longest_incremental_marking_step; |
| + |
| + // Amounts of time spent in different scopes during GC. |
| + double scopes[Scope::NUMBER_OF_SCOPES]; |
| + }; |
| + |
| + typedef RingBuffer<Event, 10> EventBuffer; |
| + |
| explicit GCTracer(Heap* heap); |
| // Start collecting data. |
| - void start(GarbageCollector collector, |
| + void Start(GarbageCollector collector, |
| const char* gc_reason, |
| const char* collector_reason); |
| // Stop collecting data and print results. |
| - void stop(); |
| + void Stop(); |
| + |
| + // The event with the most recent end_time (selected from all event buffer) |
| + EventBuffer::const_iterator Current() const; |
| + |
| + // The event before the current event (selected from all event buffers). |
| + EventBuffer::const_iterator Previous() const; |
| + |
| + // Log an incremental marking step. |
| + void AddIncrementalMarkingStep(double duration); |
| private: |
| // Returns a string matching the collector. |
| - const char* CollectorString() const; |
| + const char* CollectorString(GarbageCollector collector, |
| + bool short_name) const; |
| // Print one detailed trace line in name=value format. |
| + // TODO(ernstm): move to Heap. |
| void PrintNVP() const; |
| // Print one trace line. |
| + // TODO(ernstm): move to Heap. |
| void Print() const; |
| - // Timestamp set in the constructor. |
| - double start_time_; |
| - |
| - // Timestamp set in the destructor. |
| - double end_time_; |
| - |
| - // Size of objects in heap set in constructor. |
| - intptr_t start_object_size_; |
| - |
| - // Size of objects in heap set in destructor. |
| - intptr_t end_object_size_; |
| - |
| - // Size of memory allocated from OS set in constructor. |
| - intptr_t start_memory_size_; |
| - |
| - // Size of memory allocated from OS set in destructor. |
| - intptr_t end_memory_size_; |
| - |
| - // Type of collector. |
| - GarbageCollector collector_; |
| - |
| - // Amounts of time spent in different scopes during GC. |
| - double scopes_[Scope::NUMBER_OF_SCOPES]; |
| - |
| - // Total amount of space either wasted or contained in one of free lists |
| - // before the current GC. |
| - intptr_t in_free_list_or_wasted_before_gc_; |
| + // Pointer to the heap that owns this tracer. |
| + Heap* heap_; |
| - // Difference between space used in the heap at the beginning of the current |
| - // collection and the end of the previous collection. |
| - intptr_t allocated_since_last_gc_; |
| + // Pending tracer event that is filled during one Start/Stop cycle. |
| + Event pending_; |
| - // Amount of time spent in mutator that is time elapsed between end of the |
| - // previous collection and the beginning of the current one. |
| - double spent_in_mutator_; |
| + // Two RingBuffers of events. One each for SCAVENGER and MARK_COMPACTOR. |
| + EventBuffer event_buffers_[2]; |
|
Hannes Payer (out of office)
2014/07/22 09:10:17
Ah, now I see why you have to initialize the enum.
ernstm
2014/07/22 14:09:28
I've chosen the array, because the Previous() meth
ernstm
2014/07/22 14:10:26
Update: The latest version uses two separate membe
|
| - // Incremental marking steps counters. |
| - int steps_count_; |
| - double steps_took_; |
| - double longest_step_; |
| - int steps_count_since_last_gc_; |
| - double steps_took_since_last_gc_; |
| + // Cumulative number of incremental marking steps since creation of tracer. |
| + int incremental_marking_steps_; |
| - Heap* heap_; |
| + // Cumulative duration of incremental marking steps since creation of tracer. |
| + double incremental_marking_duration_; |
| - const char* gc_reason_; |
| - const char* collector_reason_; |
| + // Longest incremental marking step since start of marking. |
| + double longest_incremental_marking_step_; |
| DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| }; |
| @@ -1368,10 +1461,9 @@ class Heap { |
| } |
| // Update GC statistics that are tracked on the Heap. |
| - void UpdateGCStatistics(double start_time, |
| - double end_time, |
| - double spent_in_mutator, |
| - double marking_time); |
| + void UpdateCumulativeGCStatistics(double duration, |
| + double spent_in_mutator, |
| + double marking_time); |
| // Returns maximum GC pause. |
| double get_max_gc_pause() { return max_gc_pause_; } |
| @@ -2241,11 +2333,6 @@ class Heap { |
| // Minimal interval between two subsequent collections. |
| double min_in_mutator_; |
| - // Size of objects alive after last GC. |
| - intptr_t alive_after_last_gc_; |
| - |
| - double last_gc_end_timestamp_; |
| - |
| // Cumulative GC time spent in marking |
| double marking_time_; |