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

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
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..ee48a69c6a39686b0cc0130660ec1364d489f058 100644
--- a/base/trace_event/heap_profiler_heap_dump_writer.cc
+++ b/base/trace_event/heap_profiler_heap_dump_writer.cc
@@ -135,14 +135,10 @@ std::vector<Bucket> BreakDownBy(const Bucket& bucket, BreakDownMode breakBy) {
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.
+ // Compute the total accounted amount of bytes
+ // If next bucket increase this amount by less then 0.8% just skip the tail
Primiano Tucci (use gerrit) 2016/04/06 08:20:44 I'd add a "(1/125)" after 0.8% otherwise It's not
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 +230,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));

Powered by Google App Engine
This is Rietveld 408576698