Eliminate zero count allocations from profile

If no objects allocated at a location are live when a profile is
collected we report a zero count sample. This is confusing to those
looking at the profiles and will leak memory.

We now delete allocations once the number of sampled live objects for
that location reaches zero.

R=ofrobots@google.com
BUG=

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

Cr-Commit-Position: refs/heads/master@{#35305}
This commit is contained in:
mattloring 2016-04-06 07:21:04 -07:00 committed by Commit bot
parent 69bad719fc
commit 3184aff964
2 changed files with 14 additions and 0 deletions

View File

@ -117,6 +117,9 @@ void SamplingHeapProfiler::OnWeakCallback(
AllocationNode* node = sample->owner;
DCHECK(node->allocations_[sample->size] > 0);
node->allocations_[sample->size]--;
if (node->allocations_[sample->size] == 0) {
node->allocations_.erase(sample->size);
}
sample->profiler->samples_.erase(sample);
delete sample;
}

View File

@ -2875,6 +2875,15 @@ static const v8::AllocationProfile::Node* FindAllocationProfileNode(
return node;
}
static void CheckNoZeroCountNodes(v8::AllocationProfile::Node* node) {
for (auto alloc : node->allocations) {
CHECK_GT(alloc.count, 0u);
}
for (auto child : node->children) {
CheckNoZeroCountNodes(child);
}
}
TEST(SamplingHeapProfiler) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext env;
@ -3002,6 +3011,8 @@ TEST(SamplingHeapProfiler) {
heap_profiler->GetAllocationProfile());
CHECK(!profile.is_empty());
CheckNoZeroCountNodes(profile->GetRootNode());
heap_profiler->StopSamplingHeapProfiler();
}
}