Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/heap/gc-tracer.h" |
| 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include "src/counters.h" |
| 8 | #include "src/heap/heap-inl.h" |
| 9 | #include "src/isolate.h" |
| 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | static intptr_t CountTotalHolesSize(Heap* heap) { |
| 15 | intptr_t holes_size = 0; |
| 16 | OldSpaces spaces(heap); |
| 17 | for (OldSpace* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 18 | holes_size += space->Waste() + space->Available(); |
| 19 | } |
| 20 | return holes_size; |
| 21 | } |
| 22 | |
| 23 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope) |
| 25 | : tracer_(tracer), scope_(scope) { |
| 26 | start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 27 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 28 | if (FLAG_runtime_call_stats) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 29 | RuntimeCallStats::Enter(tracer_->heap_->isolate(), &timer_, |
| 30 | &RuntimeCallStats::GC); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 31 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | |
| 35 | GCTracer::Scope::~Scope() { |
| 36 | DCHECK(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
| 37 | tracer_->current_.scopes[scope_] += |
| 38 | tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 39 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 40 | if (FLAG_runtime_call_stats) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 41 | RuntimeCallStats::Leave(tracer_->heap_->isolate(), &timer_); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 42 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 45 | const char* GCTracer::Scope::Name(ScopeId id) { |
| 46 | #define CASE(scope) \ |
| 47 | case Scope::scope: \ |
| 48 | return "V8.GC_" #scope; |
| 49 | switch (id) { |
| 50 | TRACER_SCOPES(CASE) |
| 51 | case Scope::NUMBER_OF_SCOPES: |
| 52 | break; |
| 53 | } |
| 54 | #undef CASE |
| 55 | return "(unknown)"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | GCTracer::Event::Event(Type type, const char* gc_reason, |
| 59 | const char* collector_reason) |
| 60 | : type(type), |
| 61 | gc_reason(gc_reason), |
| 62 | collector_reason(collector_reason), |
| 63 | start_time(0.0), |
| 64 | end_time(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 65 | reduce_memory(false), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | start_object_size(0), |
| 67 | end_object_size(0), |
| 68 | start_memory_size(0), |
| 69 | end_memory_size(0), |
| 70 | start_holes_size(0), |
| 71 | end_holes_size(0), |
| 72 | cumulative_incremental_marking_steps(0), |
| 73 | incremental_marking_steps(0), |
| 74 | cumulative_incremental_marking_bytes(0), |
| 75 | incremental_marking_bytes(0), |
| 76 | cumulative_incremental_marking_duration(0.0), |
| 77 | incremental_marking_duration(0.0), |
| 78 | cumulative_pure_incremental_marking_duration(0.0), |
| 79 | pure_incremental_marking_duration(0.0), |
| 80 | longest_incremental_marking_step(0.0) { |
| 81 | for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { |
| 82 | scopes[i] = 0; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | const char* GCTracer::Event::TypeName(bool short_name) const { |
| 88 | switch (type) { |
| 89 | case SCAVENGER: |
| 90 | if (short_name) { |
| 91 | return "s"; |
| 92 | } else { |
| 93 | return "Scavenge"; |
| 94 | } |
| 95 | case MARK_COMPACTOR: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 96 | case INCREMENTAL_MARK_COMPACTOR: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | if (short_name) { |
| 98 | return "ms"; |
| 99 | } else { |
| 100 | return "Mark-sweep"; |
| 101 | } |
| 102 | case START: |
| 103 | if (short_name) { |
| 104 | return "st"; |
| 105 | } else { |
| 106 | return "Start"; |
| 107 | } |
| 108 | } |
| 109 | return "Unknown Event Type"; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | GCTracer::GCTracer(Heap* heap) |
| 114 | : heap_(heap), |
| 115 | cumulative_incremental_marking_steps_(0), |
| 116 | cumulative_incremental_marking_bytes_(0), |
| 117 | cumulative_incremental_marking_duration_(0.0), |
| 118 | cumulative_pure_incremental_marking_duration_(0.0), |
| 119 | longest_incremental_marking_step_(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 120 | cumulative_incremental_marking_finalization_steps_(0), |
| 121 | cumulative_incremental_marking_finalization_duration_(0.0), |
| 122 | longest_incremental_marking_finalization_step_(0.0), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 123 | cumulative_marking_duration_(0.0), |
| 124 | cumulative_sweeping_duration_(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 125 | allocation_time_ms_(0.0), |
| 126 | new_space_allocation_counter_bytes_(0), |
| 127 | old_generation_allocation_counter_bytes_(0), |
| 128 | allocation_duration_since_gc_(0.0), |
| 129 | new_space_allocation_in_bytes_since_gc_(0), |
| 130 | old_generation_allocation_in_bytes_since_gc_(0), |
| 131 | combined_mark_compact_speed_cache_(0.0), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 132 | start_counter_(0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | current_ = Event(Event::START, NULL, NULL); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 134 | current_.end_time = heap_->MonotonicallyIncreasingTimeInMs(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 135 | previous_ = previous_incremental_mark_compactor_event_ = current_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
| 139 | void GCTracer::Start(GarbageCollector collector, const char* gc_reason, |
| 140 | const char* collector_reason) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 141 | start_counter_++; |
| 142 | if (start_counter_ != 1) return; |
| 143 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | previous_ = current_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 145 | double start_time = heap_->MonotonicallyIncreasingTimeInMs(); |
| 146 | SampleAllocation(start_time, heap_->NewSpaceAllocationCounter(), |
| 147 | heap_->OldGenerationAllocationCounter()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 148 | if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) |
| 149 | previous_incremental_mark_compactor_event_ = current_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | |
| 151 | if (collector == SCAVENGER) { |
| 152 | current_ = Event(Event::SCAVENGER, gc_reason, collector_reason); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 153 | } else if (collector == MARK_COMPACTOR) { |
| 154 | if (heap_->incremental_marking()->WasActivated()) { |
| 155 | current_ = |
| 156 | Event(Event::INCREMENTAL_MARK_COMPACTOR, gc_reason, collector_reason); |
| 157 | } else { |
| 158 | current_ = Event(Event::MARK_COMPACTOR, gc_reason, collector_reason); |
| 159 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 162 | current_.reduce_memory = heap_->ShouldReduceMemory(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 163 | current_.start_time = start_time; |
| 164 | current_.start_object_size = heap_->SizeOfObjects(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 165 | current_.start_memory_size = heap_->memory_allocator()->Size(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 166 | current_.start_holes_size = CountTotalHolesSize(heap_); |
| 167 | current_.new_space_object_size = |
| 168 | heap_->new_space()->top() - heap_->new_space()->bottom(); |
| 169 | |
| 170 | current_.cumulative_incremental_marking_steps = |
| 171 | cumulative_incremental_marking_steps_; |
| 172 | current_.cumulative_incremental_marking_bytes = |
| 173 | cumulative_incremental_marking_bytes_; |
| 174 | current_.cumulative_incremental_marking_duration = |
| 175 | cumulative_incremental_marking_duration_; |
| 176 | current_.cumulative_pure_incremental_marking_duration = |
| 177 | cumulative_pure_incremental_marking_duration_; |
| 178 | current_.longest_incremental_marking_step = longest_incremental_marking_step_; |
| 179 | |
| 180 | for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { |
| 181 | current_.scopes[i] = 0; |
| 182 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 183 | int committed_memory = static_cast<int>(heap_->CommittedMemory() / KB); |
| 184 | int used_memory = static_cast<int>(current_.start_object_size / KB); |
| 185 | heap_->isolate()->counters()->aggregated_memory_heap_committed()->AddSample( |
| 186 | start_time, committed_memory); |
| 187 | heap_->isolate()->counters()->aggregated_memory_heap_used()->AddSample( |
| 188 | start_time, used_memory); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 189 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 190 | if (FLAG_runtime_call_stats) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 191 | RuntimeCallStats::Enter(heap_->isolate(), &timer_, &RuntimeCallStats::GC); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 192 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 195 | void GCTracer::Stop(GarbageCollector collector) { |
| 196 | start_counter_--; |
| 197 | if (start_counter_ != 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 198 | Output("[Finished reentrant %s during %s.]\n", |
| 199 | collector == SCAVENGER ? "Scavenge" : "Mark-sweep", |
| 200 | current_.TypeName(false)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | |
| 204 | DCHECK(start_counter_ >= 0); |
| 205 | DCHECK((collector == SCAVENGER && current_.type == Event::SCAVENGER) || |
| 206 | (collector == MARK_COMPACTOR && |
| 207 | (current_.type == Event::MARK_COMPACTOR || |
| 208 | current_.type == Event::INCREMENTAL_MARK_COMPACTOR))); |
| 209 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 210 | current_.end_time = heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 211 | current_.end_object_size = heap_->SizeOfObjects(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 212 | current_.end_memory_size = heap_->memory_allocator()->Size(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | current_.end_holes_size = CountTotalHolesSize(heap_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 214 | current_.survived_new_space_object_size = heap_->SurvivedNewSpaceObjectSize(); |
| 215 | |
| 216 | AddAllocation(current_.end_time); |
| 217 | |
| 218 | int committed_memory = static_cast<int>(heap_->CommittedMemory() / KB); |
| 219 | int used_memory = static_cast<int>(current_.end_object_size / KB); |
| 220 | heap_->isolate()->counters()->aggregated_memory_heap_committed()->AddSample( |
| 221 | current_.end_time, committed_memory); |
| 222 | heap_->isolate()->counters()->aggregated_memory_heap_used()->AddSample( |
| 223 | current_.end_time, used_memory); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 224 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 225 | double duration = current_.end_time - current_.start_time; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 226 | if (current_.type == Event::SCAVENGER) { |
| 227 | current_.incremental_marking_steps = |
| 228 | current_.cumulative_incremental_marking_steps - |
| 229 | previous_.cumulative_incremental_marking_steps; |
| 230 | current_.incremental_marking_bytes = |
| 231 | current_.cumulative_incremental_marking_bytes - |
| 232 | previous_.cumulative_incremental_marking_bytes; |
| 233 | current_.incremental_marking_duration = |
| 234 | current_.cumulative_incremental_marking_duration - |
| 235 | previous_.cumulative_incremental_marking_duration; |
| 236 | current_.pure_incremental_marking_duration = |
| 237 | current_.cumulative_pure_incremental_marking_duration - |
| 238 | previous_.cumulative_pure_incremental_marking_duration; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 239 | recorded_scavenges_total_.Push( |
| 240 | MakeBytesAndDuration(current_.new_space_object_size, duration)); |
| 241 | recorded_scavenges_survived_.Push(MakeBytesAndDuration( |
| 242 | current_.survived_new_space_object_size, duration)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 243 | } else if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | current_.incremental_marking_steps = |
| 245 | current_.cumulative_incremental_marking_steps - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 246 | previous_incremental_mark_compactor_event_ |
| 247 | .cumulative_incremental_marking_steps; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 248 | current_.incremental_marking_bytes = |
| 249 | current_.cumulative_incremental_marking_bytes - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 250 | previous_incremental_mark_compactor_event_ |
| 251 | .cumulative_incremental_marking_bytes; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 252 | current_.incremental_marking_duration = |
| 253 | current_.cumulative_incremental_marking_duration - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 254 | previous_incremental_mark_compactor_event_ |
| 255 | .cumulative_incremental_marking_duration; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 256 | current_.pure_incremental_marking_duration = |
| 257 | current_.cumulative_pure_incremental_marking_duration - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 258 | previous_incremental_mark_compactor_event_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 259 | .cumulative_pure_incremental_marking_duration; |
| 260 | longest_incremental_marking_step_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 261 | recorded_incremental_marking_steps_.Push( |
| 262 | MakeBytesAndDuration(current_.incremental_marking_bytes, |
| 263 | current_.pure_incremental_marking_duration)); |
| 264 | recorded_incremental_mark_compacts_.Push( |
| 265 | MakeBytesAndDuration(current_.start_object_size, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 266 | combined_mark_compact_speed_cache_ = 0.0; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 267 | } else { |
| 268 | DCHECK(current_.incremental_marking_bytes == 0); |
| 269 | DCHECK(current_.incremental_marking_duration == 0); |
| 270 | DCHECK(current_.pure_incremental_marking_duration == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | longest_incremental_marking_step_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 272 | recorded_mark_compacts_.Push( |
| 273 | MakeBytesAndDuration(current_.start_object_size, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 274 | combined_mark_compact_speed_cache_ = 0.0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // TODO(ernstm): move the code below out of GCTracer. |
| 278 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); |
| 280 | |
| 281 | heap_->UpdateCumulativeGCStatistics(duration, spent_in_mutator, |
| 282 | current_.scopes[Scope::MC_MARK]); |
| 283 | |
| 284 | if (current_.type == Event::SCAVENGER && FLAG_trace_gc_ignore_scavenger) |
| 285 | return; |
| 286 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 287 | if (FLAG_trace_gc_nvp) |
| 288 | PrintNVP(); |
| 289 | else |
| 290 | Print(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | if (FLAG_trace_gc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | heap_->PrintShortHeapStatistics(); |
| 294 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 295 | |
| 296 | longest_incremental_marking_finalization_step_ = 0.0; |
| 297 | cumulative_incremental_marking_finalization_steps_ = 0; |
| 298 | cumulative_incremental_marking_finalization_duration_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 299 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 300 | if (FLAG_runtime_call_stats) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 301 | RuntimeCallStats::Leave(heap_->isolate(), &timer_); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 302 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 306 | void GCTracer::SampleAllocation(double current_ms, |
| 307 | size_t new_space_counter_bytes, |
| 308 | size_t old_generation_counter_bytes) { |
| 309 | if (allocation_time_ms_ == 0) { |
| 310 | // It is the first sample. |
| 311 | allocation_time_ms_ = current_ms; |
| 312 | new_space_allocation_counter_bytes_ = new_space_counter_bytes; |
| 313 | old_generation_allocation_counter_bytes_ = old_generation_counter_bytes; |
| 314 | return; |
| 315 | } |
| 316 | // This assumes that counters are unsigned integers so that the subtraction |
| 317 | // below works even if the new counter is less then the old counter. |
| 318 | size_t new_space_allocated_bytes = |
| 319 | new_space_counter_bytes - new_space_allocation_counter_bytes_; |
| 320 | size_t old_generation_allocated_bytes = |
| 321 | old_generation_counter_bytes - old_generation_allocation_counter_bytes_; |
| 322 | double duration = current_ms - allocation_time_ms_; |
| 323 | allocation_time_ms_ = current_ms; |
| 324 | new_space_allocation_counter_bytes_ = new_space_counter_bytes; |
| 325 | old_generation_allocation_counter_bytes_ = old_generation_counter_bytes; |
| 326 | allocation_duration_since_gc_ += duration; |
| 327 | new_space_allocation_in_bytes_since_gc_ += new_space_allocated_bytes; |
| 328 | old_generation_allocation_in_bytes_since_gc_ += |
| 329 | old_generation_allocated_bytes; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | void GCTracer::AddAllocation(double current_ms) { |
| 334 | allocation_time_ms_ = current_ms; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 335 | if (allocation_duration_since_gc_ > 0) { |
| 336 | recorded_new_generation_allocations_.Push( |
| 337 | MakeBytesAndDuration(new_space_allocation_in_bytes_since_gc_, |
| 338 | allocation_duration_since_gc_)); |
| 339 | recorded_old_generation_allocations_.Push( |
| 340 | MakeBytesAndDuration(old_generation_allocation_in_bytes_since_gc_, |
| 341 | allocation_duration_since_gc_)); |
| 342 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | allocation_duration_since_gc_ = 0; |
| 344 | new_space_allocation_in_bytes_since_gc_ = 0; |
| 345 | old_generation_allocation_in_bytes_since_gc_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 349 | void GCTracer::AddContextDisposalTime(double time) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 350 | recorded_context_disposal_times_.Push(time); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 354 | void GCTracer::AddCompactionEvent(double duration, |
| 355 | intptr_t live_bytes_compacted) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 356 | recorded_compactions_.Push( |
| 357 | MakeBytesAndDuration(live_bytes_compacted, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
| 361 | void GCTracer::AddSurvivalRatio(double promotion_ratio) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 362 | recorded_survival_ratios_.Push(promotion_ratio); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 366 | void GCTracer::AddIncrementalMarkingStep(double duration, intptr_t bytes) { |
| 367 | cumulative_incremental_marking_steps_++; |
| 368 | cumulative_incremental_marking_bytes_ += bytes; |
| 369 | cumulative_incremental_marking_duration_ += duration; |
| 370 | longest_incremental_marking_step_ = |
| 371 | Max(longest_incremental_marking_step_, duration); |
| 372 | cumulative_marking_duration_ += duration; |
| 373 | if (bytes > 0) { |
| 374 | cumulative_pure_incremental_marking_duration_ += duration; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 379 | void GCTracer::AddIncrementalMarkingFinalizationStep(double duration) { |
| 380 | cumulative_incremental_marking_finalization_steps_++; |
| 381 | cumulative_incremental_marking_finalization_duration_ += duration; |
| 382 | longest_incremental_marking_finalization_step_ = |
| 383 | Max(longest_incremental_marking_finalization_step_, duration); |
| 384 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 385 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 386 | |
| 387 | void GCTracer::Output(const char* format, ...) const { |
| 388 | if (FLAG_trace_gc) { |
| 389 | va_list arguments; |
| 390 | va_start(arguments, format); |
| 391 | base::OS::VPrint(format, arguments); |
| 392 | va_end(arguments); |
| 393 | } |
| 394 | |
| 395 | const int kBufferSize = 256; |
| 396 | char raw_buffer[kBufferSize]; |
| 397 | Vector<char> buffer(raw_buffer, kBufferSize); |
| 398 | va_list arguments2; |
| 399 | va_start(arguments2, format); |
| 400 | VSNPrintF(buffer, format, arguments2); |
| 401 | va_end(arguments2); |
| 402 | |
| 403 | heap_->AddToRingBuffer(buffer.start()); |
| 404 | } |
| 405 | |
| 406 | |
| 407 | void GCTracer::Print() const { |
| 408 | if (FLAG_trace_gc) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 409 | PrintIsolate(heap_->isolate(), "%s", ""); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 410 | } |
| 411 | Output("%8.0f ms: ", heap_->isolate()->time_millis_since_init()); |
| 412 | |
| 413 | Output("%s %.1f (%.1f) -> %.1f (%.1f) MB, ", current_.TypeName(false), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | static_cast<double>(current_.start_object_size) / MB, |
| 415 | static_cast<double>(current_.start_memory_size) / MB, |
| 416 | static_cast<double>(current_.end_object_size) / MB, |
| 417 | static_cast<double>(current_.end_memory_size) / MB); |
| 418 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | double duration = current_.end_time - current_.start_time; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 420 | Output("%.1f / %.1f ms", duration, TotalExternalTime()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 422 | if (current_.type == Event::SCAVENGER) { |
| 423 | if (current_.incremental_marking_steps > 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 424 | Output(" (+ %.1f ms in %d steps since last GC)", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 425 | current_.incremental_marking_duration, |
| 426 | current_.incremental_marking_steps); |
| 427 | } |
| 428 | } else { |
| 429 | if (current_.incremental_marking_steps > 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 430 | Output( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | " (+ %.1f ms in %d steps since start of marking, " |
| 432 | "biggest step %.1f ms)", |
| 433 | current_.incremental_marking_duration, |
| 434 | current_.incremental_marking_steps, |
| 435 | current_.longest_incremental_marking_step); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | if (current_.gc_reason != NULL) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 440 | Output(" [%s]", current_.gc_reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | if (current_.collector_reason != NULL) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 444 | Output(" [%s]", current_.collector_reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 447 | Output(".\n"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
| 451 | void GCTracer::PrintNVP() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | double duration = current_.end_time - current_.start_time; |
| 453 | double spent_in_mutator = current_.start_time - previous_.end_time; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | intptr_t allocated_since_last_gc = |
| 455 | current_.start_object_size - previous_.end_object_size; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 457 | switch (current_.type) { |
| 458 | case Event::SCAVENGER: |
| 459 | PrintIsolate(heap_->isolate(), |
| 460 | "%8.0f ms: " |
| 461 | "pause=%.1f " |
| 462 | "mutator=%.1f " |
| 463 | "gc=%s " |
| 464 | "reduce_memory=%d " |
| 465 | "scavenge=%.2f " |
| 466 | "old_new=%.2f " |
| 467 | "weak=%.2f " |
| 468 | "roots=%.2f " |
| 469 | "code=%.2f " |
| 470 | "semispace=%.2f " |
| 471 | "object_groups=%.2f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 472 | "external_prologue=%.2f " |
| 473 | "external_epilogue=%.2f " |
| 474 | "external_weak_global_handles=%.2f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 475 | "steps_count=%d " |
| 476 | "steps_took=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 477 | "scavenge_throughput=%.f " |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 478 | "total_size_before=%" V8PRIdPTR |
| 479 | " " |
| 480 | "total_size_after=%" V8PRIdPTR |
| 481 | " " |
| 482 | "holes_size_before=%" V8PRIdPTR |
| 483 | " " |
| 484 | "holes_size_after=%" V8PRIdPTR |
| 485 | " " |
| 486 | "allocated=%" V8PRIdPTR |
| 487 | " " |
| 488 | "promoted=%" V8PRIdPTR |
| 489 | " " |
| 490 | "semi_space_copied=%" V8PRIdPTR |
| 491 | " " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 492 | "nodes_died_in_new=%d " |
| 493 | "nodes_copied_in_new=%d " |
| 494 | "nodes_promoted=%d " |
| 495 | "promotion_ratio=%.1f%% " |
| 496 | "average_survival_ratio=%.1f%% " |
| 497 | "promotion_rate=%.1f%% " |
| 498 | "semi_space_copy_rate=%.1f%% " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 499 | "new_space_allocation_throughput=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 500 | "context_disposal_rate=%.1f\n", |
| 501 | heap_->isolate()->time_millis_since_init(), duration, |
| 502 | spent_in_mutator, current_.TypeName(true), |
| 503 | current_.reduce_memory, |
| 504 | current_.scopes[Scope::SCAVENGER_SCAVENGE], |
| 505 | current_.scopes[Scope::SCAVENGER_OLD_TO_NEW_POINTERS], |
| 506 | current_.scopes[Scope::SCAVENGER_WEAK], |
| 507 | current_.scopes[Scope::SCAVENGER_ROOTS], |
| 508 | current_.scopes[Scope::SCAVENGER_CODE_FLUSH_CANDIDATES], |
| 509 | current_.scopes[Scope::SCAVENGER_SEMISPACE], |
| 510 | current_.scopes[Scope::SCAVENGER_OBJECT_GROUPS], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 511 | current_.scopes[Scope::SCAVENGER_EXTERNAL_PROLOGUE], |
| 512 | current_.scopes[Scope::SCAVENGER_EXTERNAL_EPILOGUE], |
| 513 | current_.scopes[Scope::EXTERNAL_WEAK_GLOBAL_HANDLES], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 514 | current_.incremental_marking_steps, |
| 515 | current_.incremental_marking_duration, |
| 516 | ScavengeSpeedInBytesPerMillisecond(), |
| 517 | current_.start_object_size, current_.end_object_size, |
| 518 | current_.start_holes_size, current_.end_holes_size, |
| 519 | allocated_since_last_gc, heap_->promoted_objects_size(), |
| 520 | heap_->semi_space_copied_object_size(), |
| 521 | heap_->nodes_died_in_new_space_, |
| 522 | heap_->nodes_copied_in_new_space_, heap_->nodes_promoted_, |
| 523 | heap_->promotion_ratio_, AverageSurvivalRatio(), |
| 524 | heap_->promotion_rate_, heap_->semi_space_copied_rate_, |
| 525 | NewSpaceAllocationThroughputInBytesPerMillisecond(), |
| 526 | ContextDisposalRateInMilliseconds()); |
| 527 | break; |
| 528 | case Event::MARK_COMPACTOR: |
| 529 | case Event::INCREMENTAL_MARK_COMPACTOR: |
| 530 | PrintIsolate( |
| 531 | heap_->isolate(), |
| 532 | "%8.0f ms: " |
| 533 | "pause=%.1f " |
| 534 | "mutator=%.1f " |
| 535 | "gc=%s " |
| 536 | "reduce_memory=%d " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 537 | "clear=%1.f " |
| 538 | "clear.code_flush=%.1f " |
| 539 | "clear.dependent_code=%.1f " |
| 540 | "clear.global_handles=%.1f " |
| 541 | "clear.maps=%.1f " |
| 542 | "clear.slots_buffer=%.1f " |
| 543 | "clear.store_buffer=%.1f " |
| 544 | "clear.string_table=%.1f " |
| 545 | "clear.weak_cells=%.1f " |
| 546 | "clear.weak_collections=%.1f " |
| 547 | "clear.weak_lists=%.1f " |
| 548 | "evacuate=%.1f " |
| 549 | "evacuate.candidates=%.1f " |
| 550 | "evacuate.clean_up=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 551 | "evacuate.copy=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 552 | "evacuate.update_pointers=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 553 | "evacuate.update_pointers.to_evacuated=%.1f " |
| 554 | "evacuate.update_pointers.to_new=%.1f " |
| 555 | "evacuate.update_pointers.weak=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 556 | "external.mc_prologue=%.1f " |
| 557 | "external.mc_epilogue=%.1f " |
| 558 | "external.mc_incremental_prologue=%.1f " |
| 559 | "external.mc_incremental_epilogue=%.1f " |
| 560 | "external.weak_global_handles=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 561 | "finish=%.1f " |
| 562 | "mark=%.1f " |
| 563 | "mark.finish_incremental=%.1f " |
| 564 | "mark.prepare_code_flush=%.1f " |
| 565 | "mark.roots=%.1f " |
| 566 | "mark.weak_closure=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 567 | "mark.weak_closure.ephemeral=%.1f " |
| 568 | "mark.weak_closure.weak_handles=%.1f " |
| 569 | "mark.weak_closure.weak_roots=%.1f " |
| 570 | "mark.weak_closure.harmony=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 571 | "sweep=%.1f " |
| 572 | "sweep.code=%.1f " |
| 573 | "sweep.map=%.1f " |
| 574 | "sweep.old=%.1f " |
| 575 | "incremental_finalize=%.1f " |
| 576 | "steps_count=%d " |
| 577 | "steps_took=%.1f " |
| 578 | "longest_step=%.1f " |
| 579 | "finalization_steps_count=%d " |
| 580 | "finalization_steps_took=%.1f " |
| 581 | "finalization_longest_step=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 582 | "incremental_marking_throughput=%.f " |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 583 | "total_size_before=%" V8PRIdPTR |
| 584 | " " |
| 585 | "total_size_after=%" V8PRIdPTR |
| 586 | " " |
| 587 | "holes_size_before=%" V8PRIdPTR |
| 588 | " " |
| 589 | "holes_size_after=%" V8PRIdPTR |
| 590 | " " |
| 591 | "allocated=%" V8PRIdPTR |
| 592 | " " |
| 593 | "promoted=%" V8PRIdPTR |
| 594 | " " |
| 595 | "semi_space_copied=%" V8PRIdPTR |
| 596 | " " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 597 | "nodes_died_in_new=%d " |
| 598 | "nodes_copied_in_new=%d " |
| 599 | "nodes_promoted=%d " |
| 600 | "promotion_ratio=%.1f%% " |
| 601 | "average_survival_ratio=%.1f%% " |
| 602 | "promotion_rate=%.1f%% " |
| 603 | "semi_space_copy_rate=%.1f%% " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 604 | "new_space_allocation_throughput=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 605 | "context_disposal_rate=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 606 | "compaction_speed=%.f\n", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 607 | heap_->isolate()->time_millis_since_init(), duration, |
| 608 | spent_in_mutator, current_.TypeName(true), current_.reduce_memory, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 609 | current_.scopes[Scope::MC_CLEAR], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 610 | current_.scopes[Scope::MC_CLEAR_CODE_FLUSH], |
| 611 | current_.scopes[Scope::MC_CLEAR_DEPENDENT_CODE], |
| 612 | current_.scopes[Scope::MC_CLEAR_GLOBAL_HANDLES], |
| 613 | current_.scopes[Scope::MC_CLEAR_MAPS], |
| 614 | current_.scopes[Scope::MC_CLEAR_SLOTS_BUFFER], |
| 615 | current_.scopes[Scope::MC_CLEAR_STORE_BUFFER], |
| 616 | current_.scopes[Scope::MC_CLEAR_STRING_TABLE], |
| 617 | current_.scopes[Scope::MC_CLEAR_WEAK_CELLS], |
| 618 | current_.scopes[Scope::MC_CLEAR_WEAK_COLLECTIONS], |
| 619 | current_.scopes[Scope::MC_CLEAR_WEAK_LISTS], |
| 620 | current_.scopes[Scope::MC_EVACUATE], |
| 621 | current_.scopes[Scope::MC_EVACUATE_CANDIDATES], |
| 622 | current_.scopes[Scope::MC_EVACUATE_CLEAN_UP], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 623 | current_.scopes[Scope::MC_EVACUATE_COPY], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 624 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 625 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED], |
| 626 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_NEW], |
| 627 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 628 | current_.scopes[Scope::MC_EXTERNAL_PROLOGUE], |
| 629 | current_.scopes[Scope::MC_EXTERNAL_EPILOGUE], |
| 630 | current_.scopes[Scope::MC_INCREMENTAL_EXTERNAL_PROLOGUE], |
| 631 | current_.scopes[Scope::MC_INCREMENTAL_EXTERNAL_EPILOGUE], |
| 632 | current_.scopes[Scope::EXTERNAL_WEAK_GLOBAL_HANDLES], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 633 | current_.scopes[Scope::MC_FINISH], current_.scopes[Scope::MC_MARK], |
| 634 | current_.scopes[Scope::MC_MARK_FINISH_INCREMENTAL], |
| 635 | current_.scopes[Scope::MC_MARK_PREPARE_CODE_FLUSH], |
| 636 | current_.scopes[Scope::MC_MARK_ROOTS], |
| 637 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 638 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_EPHEMERAL], |
| 639 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_WEAK_HANDLES], |
| 640 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_WEAK_ROOTS], |
| 641 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_HARMONY], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 642 | current_.scopes[Scope::MC_SWEEP], |
| 643 | current_.scopes[Scope::MC_SWEEP_CODE], |
| 644 | current_.scopes[Scope::MC_SWEEP_MAP], |
| 645 | current_.scopes[Scope::MC_SWEEP_OLD], |
| 646 | current_.scopes[Scope::MC_INCREMENTAL_FINALIZE], |
| 647 | current_.incremental_marking_steps, |
| 648 | current_.incremental_marking_duration, |
| 649 | current_.longest_incremental_marking_step, |
| 650 | cumulative_incremental_marking_finalization_steps_, |
| 651 | cumulative_incremental_marking_finalization_duration_, |
| 652 | longest_incremental_marking_finalization_step_, |
| 653 | IncrementalMarkingSpeedInBytesPerMillisecond(), |
| 654 | current_.start_object_size, current_.end_object_size, |
| 655 | current_.start_holes_size, current_.end_holes_size, |
| 656 | allocated_since_last_gc, heap_->promoted_objects_size(), |
| 657 | heap_->semi_space_copied_object_size(), |
| 658 | heap_->nodes_died_in_new_space_, heap_->nodes_copied_in_new_space_, |
| 659 | heap_->nodes_promoted_, heap_->promotion_ratio_, |
| 660 | AverageSurvivalRatio(), heap_->promotion_rate_, |
| 661 | heap_->semi_space_copied_rate_, |
| 662 | NewSpaceAllocationThroughputInBytesPerMillisecond(), |
| 663 | ContextDisposalRateInMilliseconds(), |
| 664 | CompactionSpeedInBytesPerMillisecond()); |
| 665 | break; |
| 666 | case Event::START: |
| 667 | break; |
| 668 | default: |
| 669 | UNREACHABLE(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 673 | double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, |
| 674 | const BytesAndDuration& initial, double time_ms) { |
| 675 | BytesAndDuration sum = buffer.Sum( |
| 676 | [time_ms](BytesAndDuration a, BytesAndDuration b) { |
| 677 | if (time_ms != 0 && a.second >= time_ms) return a; |
| 678 | return std::make_pair(a.first + b.first, a.second + b.second); |
| 679 | }, |
| 680 | initial); |
| 681 | uint64_t bytes = sum.first; |
| 682 | double durations = sum.second; |
| 683 | if (durations == 0.0) return 0; |
| 684 | double speed = bytes / durations; |
| 685 | const int max_speed = 1024 * MB; |
| 686 | const int min_speed = 1; |
| 687 | if (speed >= max_speed) return max_speed; |
| 688 | if (speed <= min_speed) return min_speed; |
| 689 | return speed; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 692 | double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer) { |
| 693 | return AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 696 | double GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 697 | if (cumulative_incremental_marking_duration_ == 0.0) return 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 698 | // We haven't completed an entire round of incremental marking, yet. |
| 699 | // Use data from GCTracer instead of data from event buffers. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 700 | if (recorded_incremental_marking_steps_.Count() == 0) { |
| 701 | return cumulative_incremental_marking_bytes_ / |
| 702 | cumulative_pure_incremental_marking_duration_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 703 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 704 | return AverageSpeed(recorded_incremental_marking_steps_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 707 | double GCTracer::ScavengeSpeedInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 708 | ScavengeSpeedMode mode) const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 709 | if (mode == kForAllObjects) { |
| 710 | return AverageSpeed(recorded_scavenges_total_); |
| 711 | } else { |
| 712 | return AverageSpeed(recorded_scavenges_survived_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 713 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 714 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 715 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 716 | double GCTracer::CompactionSpeedInBytesPerMillisecond() const { |
| 717 | return AverageSpeed(recorded_compactions_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 720 | double GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { |
| 721 | return AverageSpeed(recorded_mark_compacts_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 724 | double GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond() const { |
| 725 | return AverageSpeed(recorded_incremental_mark_compacts_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 728 | double GCTracer::CombinedMarkCompactSpeedInBytesPerMillisecond() { |
| 729 | if (combined_mark_compact_speed_cache_ > 0) |
| 730 | return combined_mark_compact_speed_cache_; |
| 731 | const double kMinimumMarkingSpeed = 0.5; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 732 | double speed1 = IncrementalMarkingSpeedInBytesPerMillisecond(); |
| 733 | double speed2 = FinalIncrementalMarkCompactSpeedInBytesPerMillisecond(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 734 | if (speed1 < kMinimumMarkingSpeed || speed2 < kMinimumMarkingSpeed) { |
| 735 | // No data for the incremental marking speed. |
| 736 | // Return the non-incremental mark-compact speed. |
| 737 | combined_mark_compact_speed_cache_ = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 738 | MarkCompactSpeedInBytesPerMillisecond(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 739 | } else { |
| 740 | // Combine the speed of incremental step and the speed of the final step. |
| 741 | // 1 / (1 / speed1 + 1 / speed2) = speed1 * speed2 / (speed1 + speed2). |
| 742 | combined_mark_compact_speed_cache_ = speed1 * speed2 / (speed1 + speed2); |
| 743 | } |
| 744 | return combined_mark_compact_speed_cache_; |
| 745 | } |
| 746 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 747 | double GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 748 | double time_ms) const { |
| 749 | size_t bytes = new_space_allocation_in_bytes_since_gc_; |
| 750 | double durations = allocation_duration_since_gc_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 751 | return AverageSpeed(recorded_new_generation_allocations_, |
| 752 | MakeBytesAndDuration(bytes, durations), time_ms); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 753 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 754 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 755 | double GCTracer::OldGenerationAllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 756 | double time_ms) const { |
| 757 | size_t bytes = old_generation_allocation_in_bytes_since_gc_; |
| 758 | double durations = allocation_duration_since_gc_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 759 | return AverageSpeed(recorded_old_generation_allocations_, |
| 760 | MakeBytesAndDuration(bytes, durations), time_ms); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 763 | double GCTracer::AllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 764 | double time_ms) const { |
| 765 | return NewSpaceAllocationThroughputInBytesPerMillisecond(time_ms) + |
| 766 | OldGenerationAllocationThroughputInBytesPerMillisecond(time_ms); |
| 767 | } |
| 768 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 769 | double GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 770 | return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrameMs); |
| 771 | } |
| 772 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 773 | double GCTracer::CurrentOldGenerationAllocationThroughputInBytesPerMillisecond() |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 774 | const { |
| 775 | return OldGenerationAllocationThroughputInBytesPerMillisecond( |
| 776 | kThroughputTimeFrameMs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 778 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 779 | double GCTracer::ContextDisposalRateInMilliseconds() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 780 | if (recorded_context_disposal_times_.Count() < |
| 781 | recorded_context_disposal_times_.kSize) |
| 782 | return 0.0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 783 | double begin = heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 784 | double end = recorded_context_disposal_times_.Sum( |
| 785 | [](double a, double b) { return b; }, 0.0); |
| 786 | return (begin - end) / recorded_context_disposal_times_.Count(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 789 | double GCTracer::AverageSurvivalRatio() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 790 | if (recorded_survival_ratios_.Count() == 0) return 0.0; |
| 791 | double sum = recorded_survival_ratios_.Sum( |
| 792 | [](double a, double b) { return a + b; }, 0.0); |
| 793 | return sum / recorded_survival_ratios_.Count(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 794 | } |
| 795 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 796 | bool GCTracer::SurvivalEventsRecorded() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 797 | return recorded_survival_ratios_.Count() > 0; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 798 | } |
| 799 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 800 | void GCTracer::ResetSurvivalEvents() { recorded_survival_ratios_.Reset(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 801 | } // namespace internal |
| 802 | } // namespace v8 |