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

Unified Diff: base/trace_event/heap_profiler_heap_dump_writer.cc

Issue 1859143003: Handle zero-size allocations properly in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/heap_profiler_heap_dump_writer.cc
diff --git a/base/trace_event/heap_profiler_heap_dump_writer.cc b/base/trace_event/heap_profiler_heap_dump_writer.cc
index b94c31246b9d347d42c285d04878c586ed7f9163..2357a9b0b5209535b0bb697fbb8fcbc9ceb13e1c 100644
--- a/base/trace_event/heap_profiler_heap_dump_writer.cc
+++ b/base/trace_event/heap_profiler_heap_dump_writer.cc
@@ -129,20 +129,14 @@ std::vector<Bucket> BreakDownBy(const Bucket& bucket, BreakDownMode breakBy) {
std::make_heap(buckets.begin(), buckets.end());
// Keep including buckets until adding one would increase the number of
- // bytes accounted for by less than 0.8 percent. This simple heuristic works
+ // bytes accounted for by less than 0.8% (1/125). This simple heuristic works
// quite well. The large buckets end up in [it, end()), [begin(), it) is the
// part that contains the max-heap of small buckets.
size_t accounted_for = 0;
std::vector<Bucket>::iterator it;
for (it = buckets.end(); it != buckets.begin(); --it) {
- // Compute the contribution to the number of bytes accounted for as a
- // fraction of 125 (in increments of 0.8 percent). Anything less than 1/125
- // is rounded down to 0 due to integer division. Buckets are iterated by
- // descending size, so later buckets cannot have a larger contribution than
- // this one.
accounted_for += buckets.front().size;
- size_t contribution = buckets.front().size * 125 / accounted_for;
- if (contribution == 0)
+ if (buckets.front().size < (accounted_for / 125))
break;
// Put the largest bucket in [begin, it) at |it - 1| and max-heapify
@@ -234,6 +228,7 @@ const std::set<Entry>& HeapDumpWriter::Summarize(
// contexts stored in |bytes_by_context|.
Bucket root_bucket;
for (const auto& context_and_size : bytes_by_context) {
+ DCHECK_GT(context_and_size.second, 0u);
const AllocationContext* context = &context_and_size.first;
const size_t size = context_and_size.second;
root_bucket.bytes_by_context.push_back(std::make_pair(context, size));
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698