Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1182)

Unified Diff: src/heap/gc-tracer.cc

Issue 1125193005: Make new space allocation throughput estimation more accurate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/heap/gc-tracer.cc
diff --git a/src/heap/gc-tracer.cc b/src/heap/gc-tracer.cc
index 1c5226d6c4796d8b663b4912700bccc9feaaca24..fb9a23413e165e4a5ecec1f2cdf75fa2b17ab54f 100644
--- a/src/heap/gc-tracer.cc
+++ b/src/heap/gc-tracer.cc
@@ -20,7 +20,7 @@ static intptr_t CountTotalHolesSize(Heap* heap) {
GCTracer::AllocationEvent::AllocationEvent(double duration,
- intptr_t allocation_in_bytes) {
+ size_t allocation_in_bytes) {
duration_ = duration;
allocation_in_bytes_ = allocation_in_bytes;
}
@@ -99,7 +99,8 @@ GCTracer::GCTracer(Heap* heap)
longest_incremental_marking_step_(0.0),
cumulative_marking_duration_(0.0),
cumulative_sweeping_duration_(0.0),
- new_space_top_after_gc_(0),
+ new_space_allocation_time_ms_(0.0),
+ new_space_allocation_counter_bytes_(0),
start_counter_(0) {
current_ = Event(Event::START, NULL, NULL);
current_.end_time = base::OS::TimeCurrentMillis();
@@ -114,12 +115,7 @@ void GCTracer::Start(GarbageCollector collector, const char* gc_reason,
previous_ = current_;
double start_time = heap_->MonotonicallyIncreasingTimeInMs();
- if (new_space_top_after_gc_ != 0) {
- AddNewSpaceAllocationTime(
- start_time - previous_.end_time,
- reinterpret_cast<intptr_t>((heap_->new_space()->top()) -
- new_space_top_after_gc_));
- }
+ SampleNewSpaceAllocation(start_time, heap_->NewSpaceAllocationCounter());
if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR)
previous_incremental_mark_compactor_event_ = current_;
@@ -184,8 +180,6 @@ void GCTracer::Stop(GarbageCollector collector) {
current_.end_object_size = heap_->SizeOfObjects();
current_.end_memory_size = heap_->isolate()->memory_allocator()->Size();
current_.end_holes_size = CountTotalHolesSize(heap_);
- new_space_top_after_gc_ =
- reinterpret_cast<intptr_t>(heap_->new_space()->top());
int committed_memory = static_cast<int>(heap_->CommittedMemory() / KB);
int used_memory = static_cast<int>(current_.end_object_size / KB);
@@ -259,9 +253,26 @@ void GCTracer::Stop(GarbageCollector collector) {
}
-void GCTracer::AddNewSpaceAllocationTime(double duration,
- intptr_t allocation_in_bytes) {
- allocation_events_.push_front(AllocationEvent(duration, allocation_in_bytes));
+void GCTracer::SampleNewSpaceAllocation(double current_ms,
+ size_t counter_bytes) {
+ if (new_space_allocation_time_ms_ == 0) {
+ // It is the first sample.
+ new_space_allocation_time_ms_ = current_ms;
+ new_space_allocation_counter_bytes_ = counter_bytes;
+ return;
+ }
+ // This assumes that counters are unsigned integers so that the subtraction
+ // below works even if the new counter is less then the old counter.
+ size_t allocated_bytes = counter_bytes - new_space_allocation_counter_bytes_;
+ double duration = current_ms - new_space_allocation_time_ms_;
+ const double kMinDurationMs = 1;
+ if (duration < kMinDurationMs) {
+ // Do not sample small durations to avoid precision errors.
+ return;
+ }
+ new_space_allocation_time_ms_ = current_ms;
+ new_space_allocation_counter_bytes_ = counter_bytes;
+ allocation_events_.push_front(AllocationEvent(duration, allocated_bytes));
}
@@ -555,11 +566,12 @@ intptr_t GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()
}
-intptr_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const {
- intptr_t bytes = 0;
+size_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const {
+ size_t bytes = 0;
double durations = 0.0;
AllocationEventBuffer::const_iterator iter = allocation_events_.begin();
- while (iter != allocation_events_.end()) {
+ const size_t max_bytes = static_cast<size_t>(-1);
+ while (iter != allocation_events_.end() && bytes < max_bytes - bytes) {
bytes += iter->allocation_in_bytes_;
durations += iter->duration_;
++iter;
@@ -567,7 +579,7 @@ intptr_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const {
if (durations == 0.0) return 0;
- return static_cast<intptr_t>(bytes / durations);
+ return static_cast<size_t>(bytes / durations + 0.5);
}

Powered by Google App Engine
This is Rietveld 408576698