| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_HEAP_GC_TRACER_H_ | 5 #ifndef V8_HEAP_GC_TRACER_H_ |
| 6 #define V8_HEAP_GC_TRACER_H_ | 6 #define V8_HEAP_GC_TRACER_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/counters.h" | 10 #include "src/counters.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GCTracer::Scope::ScopeId gc_tracer_scope_id(scope_id); \ | 128 GCTracer::Scope::ScopeId gc_tracer_scope_id(scope_id); \ |
| 129 GCTracer::Scope gc_tracer_scope(tracer, gc_tracer_scope_id); \ | 129 GCTracer::Scope gc_tracer_scope(tracer, gc_tracer_scope_id); \ |
| 130 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \ | 130 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \ |
| 131 GCTracer::Scope::Name(gc_tracer_scope_id)) | 131 GCTracer::Scope::Name(gc_tracer_scope_id)) |
| 132 | 132 |
| 133 // GCTracer collects and prints ONE line after each garbage collector | 133 // GCTracer collects and prints ONE line after each garbage collector |
| 134 // invocation IFF --trace_gc is used. | 134 // invocation IFF --trace_gc is used. |
| 135 class GCTracer { | 135 class GCTracer { |
| 136 public: | 136 public: |
| 137 struct IncrementalMarkingInfos { | 137 struct IncrementalMarkingInfos { |
| 138 IncrementalMarkingInfos() | 138 IncrementalMarkingInfos() : duration(0), longest_step(0), steps(0) {} |
| 139 : cumulative_duration(0), longest_step(0), steps(0) {} | |
| 140 | 139 |
| 141 void Update(double duration) { | 140 void Update(double duration) { |
| 142 steps++; | 141 steps++; |
| 143 cumulative_duration += duration; | 142 this->duration += duration; |
| 144 if (duration > longest_step) { | 143 if (duration > longest_step) { |
| 145 longest_step = duration; | 144 longest_step = duration; |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 | 147 |
| 149 void ResetCurrentCycle() { | 148 void ResetCurrentCycle() { |
| 149 duration = 0; |
| 150 longest_step = 0; | 150 longest_step = 0; |
| 151 steps = 0; | 151 steps = 0; |
| 152 } | 152 } |
| 153 | 153 |
| 154 double cumulative_duration; | 154 double duration; |
| 155 double longest_step; | 155 double longest_step; |
| 156 int steps; | 156 int steps; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 class Scope { | 159 class Scope { |
| 160 public: | 160 public: |
| 161 enum ScopeId { | 161 enum ScopeId { |
| 162 #define DEFINE_SCOPE(scope) scope, | 162 #define DEFINE_SCOPE(scope) scope, |
| 163 TRACER_SCOPES(DEFINE_SCOPE) | 163 TRACER_SCOPES(DEFINE_SCOPE) |
| 164 #undef DEFINE_SCOPE | 164 #undef DEFINE_SCOPE |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 // Size of new space objects in constructor. | 237 // Size of new space objects in constructor. |
| 238 intptr_t new_space_object_size; | 238 intptr_t new_space_object_size; |
| 239 | 239 |
| 240 // Size of survived new space objects in destructor. | 240 // Size of survived new space objects in destructor. |
| 241 intptr_t survived_new_space_object_size; | 241 intptr_t survived_new_space_object_size; |
| 242 | 242 |
| 243 // Bytes marked since creation of tracer (value at start of event). | 243 // Bytes marked since creation of tracer (value at start of event). |
| 244 intptr_t cumulative_incremental_marking_bytes; | 244 intptr_t cumulative_incremental_marking_bytes; |
| 245 | 245 |
| 246 // Bytes marked since | 246 // Bytes marked incrementally for INCREMENTAL_MARK_COMPACTOR |
| 247 // - last event for SCAVENGER events | |
| 248 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR | |
| 249 // events | |
| 250 intptr_t incremental_marking_bytes; | 247 intptr_t incremental_marking_bytes; |
| 251 | 248 |
| 252 // Cumulative pure duration of incremental marking steps since creation of | 249 // Duration of incremental marking steps for INCREMENTAL_MARK_COMPACTOR. |
| 253 // tracer. (value at start of event) | 250 double incremental_marking_duration; |
| 254 double cumulative_pure_incremental_marking_duration; | |
| 255 | |
| 256 // Duration of pure incremental marking steps since | |
| 257 // - last event for SCAVENGER events | |
| 258 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR | |
| 259 // events | |
| 260 double pure_incremental_marking_duration; | |
| 261 | 251 |
| 262 // Amounts of time spent in different scopes during GC. | 252 // Amounts of time spent in different scopes during GC. |
| 263 double scopes[Scope::NUMBER_OF_SCOPES]; | 253 double scopes[Scope::NUMBER_OF_SCOPES]; |
| 264 | 254 |
| 265 // Holds details for incremental marking scopes. | 255 // Holds details for incremental marking scopes. |
| 266 IncrementalMarkingInfos | 256 IncrementalMarkingInfos |
| 267 incremental_marking_scopes[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; | 257 incremental_marking_scopes[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; |
| 268 }; | 258 }; |
| 269 | 259 |
| 270 static const int kThroughputTimeFrameMs = 5000; | 260 static const int kThroughputTimeFrameMs = 5000; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 352 |
| 363 // Discard all recorded survival events. | 353 // Discard all recorded survival events. |
| 364 void ResetSurvivalEvents(); | 354 void ResetSurvivalEvents(); |
| 365 | 355 |
| 366 void NotifyIncrementalMarkingStart(); | 356 void NotifyIncrementalMarkingStart(); |
| 367 | 357 |
| 368 V8_INLINE void AddScopeSample(Scope::ScopeId scope, double duration) { | 358 V8_INLINE void AddScopeSample(Scope::ScopeId scope, double duration) { |
| 369 DCHECK(scope < Scope::NUMBER_OF_SCOPES); | 359 DCHECK(scope < Scope::NUMBER_OF_SCOPES); |
| 370 if (scope >= Scope::FIRST_INCREMENTAL_SCOPE && | 360 if (scope >= Scope::FIRST_INCREMENTAL_SCOPE && |
| 371 scope <= Scope::LAST_INCREMENTAL_SCOPE) { | 361 scope <= Scope::LAST_INCREMENTAL_SCOPE) { |
| 372 incremental_marking_scopes_[scope].Update(duration); | 362 incremental_marking_scopes_[scope - Scope::FIRST_INCREMENTAL_SCOPE] |
| 363 .Update(duration); |
| 373 } else { | 364 } else { |
| 374 current_.scopes[scope] += duration; | 365 current_.scopes[scope] += duration; |
| 375 } | 366 } |
| 376 } | 367 } |
| 377 | 368 |
| 378 private: | 369 private: |
| 379 FRIEND_TEST(GCTracer, AverageSpeed); | 370 FRIEND_TEST(GCTracer, AverageSpeed); |
| 380 FRIEND_TEST(GCTracerTest, AllocationThroughput); | 371 FRIEND_TEST(GCTracerTest, AllocationThroughput); |
| 381 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput); | 372 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput); |
| 382 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughputWithProvidedTime); | 373 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughputWithProvidedTime); |
| 383 FRIEND_TEST(GCTracerTest, OldGenerationAllocationThroughputWithProvidedTime); | 374 FRIEND_TEST(GCTracerTest, OldGenerationAllocationThroughputWithProvidedTime); |
| 384 FRIEND_TEST(GCTracerTest, RegularScope); | 375 FRIEND_TEST(GCTracerTest, RegularScope); |
| 385 FRIEND_TEST(GCTracerTest, IncrementalMarkingDetails); | 376 FRIEND_TEST(GCTracerTest, IncrementalMarkingDetails); |
| 386 FRIEND_TEST(GCTracerTest, IncrementalScope); | 377 FRIEND_TEST(GCTracerTest, IncrementalScope); |
| 378 FRIEND_TEST(GCTracerTest, IncrementalMarkingSpeed); |
| 387 | 379 |
| 388 // Returns the average speed of the events in the buffer. | 380 // Returns the average speed of the events in the buffer. |
| 389 // If the buffer is empty, the result is 0. | 381 // If the buffer is empty, the result is 0. |
| 390 // Otherwise, the result is between 1 byte/ms and 1 GB/ms. | 382 // Otherwise, the result is between 1 byte/ms and 1 GB/ms. |
| 391 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer); | 383 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer); |
| 392 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, | 384 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, |
| 393 const BytesAndDuration& initial, double time_ms); | 385 const BytesAndDuration& initial, double time_ms); |
| 394 | 386 |
| 395 void MergeBaseline(const Event& baseline); | |
| 396 | |
| 397 void ResetForTesting(); | 387 void ResetForTesting(); |
| 388 void ResetIncrementalMarkingCounters(); |
| 389 void RecordIncrementalMarkingSpeed(intptr_t bytes, double duration); |
| 398 | 390 |
| 399 // Print one detailed trace line in name=value format. | 391 // Print one detailed trace line in name=value format. |
| 400 // TODO(ernstm): Move to Heap. | 392 // TODO(ernstm): Move to Heap. |
| 401 void PrintNVP() const; | 393 void PrintNVP() const; |
| 402 | 394 |
| 403 // Print one trace line. | 395 // Print one trace line. |
| 404 // TODO(ernstm): Move to Heap. | 396 // TODO(ernstm): Move to Heap. |
| 405 void Print() const; | 397 void Print() const; |
| 406 | 398 |
| 407 // Prints a line and also adds it to the heap's ring buffer so that | 399 // Prints a line and also adds it to the heap's ring buffer so that |
| (...skipping 13 matching lines...) Expand all Loading... |
| 421 // Pointer to the heap that owns this tracer. | 413 // Pointer to the heap that owns this tracer. |
| 422 Heap* heap_; | 414 Heap* heap_; |
| 423 | 415 |
| 424 // Current tracer event. Populated during Start/Stop cycle. Valid after Stop() | 416 // Current tracer event. Populated during Start/Stop cycle. Valid after Stop() |
| 425 // has returned. | 417 // has returned. |
| 426 Event current_; | 418 Event current_; |
| 427 | 419 |
| 428 // Previous tracer event. | 420 // Previous tracer event. |
| 429 Event previous_; | 421 Event previous_; |
| 430 | 422 |
| 431 // Previous INCREMENTAL_MARK_COMPACTOR event. | 423 // Size of incremental marking steps (in bytes) accumulated since the end of |
| 432 Event previous_incremental_mark_compactor_event_; | 424 // the last mark compact GC. |
| 425 intptr_t incremental_marking_bytes_; |
| 433 | 426 |
| 434 // Cumulative size of incremental marking steps (in bytes) since creation of | 427 // Duration of incremental marking steps since the end of the last mark- |
| 435 // tracer. | 428 // compact event. |
| 436 intptr_t cumulative_incremental_marking_bytes_; | 429 double incremental_marking_duration_; |
| 437 | 430 |
| 438 // Cumulative duration of incremental marking steps since creation of tracer. | 431 double incremental_marking_start_time_; |
| 439 double cumulative_incremental_marking_duration_; | |
| 440 | 432 |
| 441 // Cumulative duration of pure incremental marking steps since creation of | 433 double recorded_incremental_marking_speed_; |
| 442 // tracer. | |
| 443 double cumulative_pure_incremental_marking_duration_; | |
| 444 | 434 |
| 445 // Incremental scopes carry more information than just the duration. The infos | 435 // Incremental scopes carry more information than just the duration. The infos |
| 446 // here are merged back upon starting/stopping the GC tracer. | 436 // here are merged back upon starting/stopping the GC tracer. |
| 447 IncrementalMarkingInfos | 437 IncrementalMarkingInfos |
| 448 incremental_marking_scopes_[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; | 438 incremental_marking_scopes_[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; |
| 449 | 439 |
| 450 double incremental_marking_start_time_; | |
| 451 | 440 |
| 452 // Timestamp and allocation counter at the last sampled allocation event. | 441 // Timestamp and allocation counter at the last sampled allocation event. |
| 453 double allocation_time_ms_; | 442 double allocation_time_ms_; |
| 454 size_t new_space_allocation_counter_bytes_; | 443 size_t new_space_allocation_counter_bytes_; |
| 455 size_t old_generation_allocation_counter_bytes_; | 444 size_t old_generation_allocation_counter_bytes_; |
| 456 | 445 |
| 457 // Accumulated duration and allocated bytes since the last GC. | 446 // Accumulated duration and allocated bytes since the last GC. |
| 458 double allocation_duration_since_gc_; | 447 double allocation_duration_since_gc_; |
| 459 size_t new_space_allocation_in_bytes_since_gc_; | 448 size_t new_space_allocation_in_bytes_since_gc_; |
| 460 size_t old_generation_allocation_in_bytes_since_gc_; | 449 size_t old_generation_allocation_in_bytes_since_gc_; |
| 461 | 450 |
| 462 double combined_mark_compact_speed_cache_; | 451 double combined_mark_compact_speed_cache_; |
| 463 | 452 |
| 464 // Counts how many tracers were started without stopping. | 453 // Counts how many tracers were started without stopping. |
| 465 int start_counter_; | 454 int start_counter_; |
| 466 | 455 |
| 467 // Separate timer used for --runtime_call_stats | 456 // Separate timer used for --runtime_call_stats |
| 468 RuntimeCallTimer timer_; | 457 RuntimeCallTimer timer_; |
| 469 | 458 |
| 470 RingBuffer<BytesAndDuration> recorded_incremental_marking_steps_; | |
| 471 RingBuffer<BytesAndDuration> recorded_scavenges_total_; | 459 RingBuffer<BytesAndDuration> recorded_scavenges_total_; |
| 472 RingBuffer<BytesAndDuration> recorded_scavenges_survived_; | 460 RingBuffer<BytesAndDuration> recorded_scavenges_survived_; |
| 473 RingBuffer<BytesAndDuration> recorded_compactions_; | 461 RingBuffer<BytesAndDuration> recorded_compactions_; |
| 462 RingBuffer<BytesAndDuration> recorded_incremental_mark_compacts_; |
| 474 RingBuffer<BytesAndDuration> recorded_mark_compacts_; | 463 RingBuffer<BytesAndDuration> recorded_mark_compacts_; |
| 475 RingBuffer<BytesAndDuration> recorded_incremental_mark_compacts_; | |
| 476 RingBuffer<BytesAndDuration> recorded_new_generation_allocations_; | 464 RingBuffer<BytesAndDuration> recorded_new_generation_allocations_; |
| 477 RingBuffer<BytesAndDuration> recorded_old_generation_allocations_; | 465 RingBuffer<BytesAndDuration> recorded_old_generation_allocations_; |
| 478 RingBuffer<double> recorded_context_disposal_times_; | 466 RingBuffer<double> recorded_context_disposal_times_; |
| 479 RingBuffer<double> recorded_survival_ratios_; | 467 RingBuffer<double> recorded_survival_ratios_; |
| 480 | 468 |
| 481 DISALLOW_COPY_AND_ASSIGN(GCTracer); | 469 DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| 482 }; | 470 }; |
| 483 } // namespace internal | 471 } // namespace internal |
| 484 } // namespace v8 | 472 } // namespace v8 |
| 485 | 473 |
| 486 #endif // V8_HEAP_GC_TRACER_H_ | 474 #endif // V8_HEAP_GC_TRACER_H_ |
| OLD | NEW |