}
-size_t GCTracer::AllocatedBytesInLast(double time_ms) const {
+size_t GCTracer::AllocationThroughputInBytesPerMillisecond(
+ double time_ms) const {
size_t bytes = new_space_allocation_in_bytes_since_gc_ +
old_generation_allocation_in_bytes_since_gc_;
double durations = allocation_duration_since_gc_;
if (durations == 0.0) return 0;
- bytes = static_cast<size_t>(bytes * (time_ms / durations) + 0.5);
- // Return at least 1 since 0 means "no data".
- return std::max<size_t>(bytes, 1);
+ return static_cast<size_t>(bytes / durations + 0.5);
}
size_t GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const {
static const double kThroughputTimeFrame = 5000;
- size_t allocated_bytes = AllocatedBytesInLast(kThroughputTimeFrame);
- if (allocated_bytes == 0) return 0;
- return static_cast<size_t>((allocated_bytes / kThroughputTimeFrame) + 1);
+ return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrame);
}
// Returns 0 if no allocation events have been recorded.
size_t NewSpaceAllocationThroughputInBytesPerMillisecond() const;
- // Bytes allocated in heap in the specified time.
+ // Allocation throughput in heap in bytes/millisecond in the last time_ms
+ // milliseconds.
// Returns 0 if no allocation events have been recorded.
- size_t AllocatedBytesInLast(double time_ms) const;
+ size_t AllocationThroughputInBytesPerMillisecond(double time_ms) const;
// Allocation throughput in heap in bytes/milliseconds in
// the last five seconds.
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, counter2, 0);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(10000, bytes);
+ size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, counter3, 0);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput);
}
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, 0, counter2);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(10000, bytes);
+ size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, 0, counter3);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput);
}
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, counter2, counter2);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(20000, bytes);
+ size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, counter3, counter3);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ(2 * (counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput);
}