Commit 3e9c664b authored by hpayer's avatar hpayer Committed by Commit bot

Fix overflow in allocation throughput calculation.

BUG=chromium:492021
LOG=n

Review URL: https://codereview.chromium.org/1148953009

Cr-Commit-Position: refs/heads/master@{#28638}
parent 395fa8ba
......@@ -615,7 +615,8 @@ size_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const {
}
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_;
......@@ -630,17 +631,13 @@ size_t GCTracer::AllocatedBytesInLast(double time_ms) const {
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);
}
......
......@@ -386,9 +386,10 @@ class GCTracer {
// 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.
......
......@@ -5548,13 +5548,13 @@ TEST(NewSpaceAllocationThroughput2) {
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);
}
......@@ -5611,13 +5611,13 @@ TEST(OldGenerationAllocationThroughput) {
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);
}
......@@ -5633,11 +5633,11 @@ TEST(AllocationThroughput) {
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment