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

Unified Diff: base/trace_event/heap_profiler_allocation_register.cc

Issue 2797603002: heap-profiler: Clean up some comments and C++. (Closed)
Patch Set: Created 3 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_allocation_register.cc
diff --git a/base/trace_event/heap_profiler_allocation_register.cc b/base/trace_event/heap_profiler_allocation_register.cc
index 1cfb983852fae5fe66c559fc4788b2d445325d68..370166033094b7937ae2a860294ae5fee721490b 100644
--- a/base/trace_event/heap_profiler_allocation_register.cc
+++ b/base/trace_event/heap_profiler_allocation_register.cc
@@ -76,22 +76,9 @@ AllocationRegister::AllocationRegister()
AllocationRegister::AllocationRegister(size_t allocation_capacity,
size_t backtrace_capacity)
- : allocations_(allocation_capacity), backtraces_(backtrace_capacity) {
- Backtrace sentinel = {};
- sentinel.frames[0] = StackFrame::FromThreadName("[out of heap profiler mem]");
- sentinel.frame_count = 1;
-
- // Rationale for max / 2: in theory we could just start the sentinel with a
- // refcount == 0. However, this optimization avoids to hit the 2nd condition
- // of the "if" in RemoveBacktrace, hence reducing the chances of hurting the
- // fastpath. From a functional viewpoint, the sentinel is safe even if we wrap
- // over the refcount.
- BacktraceMap::KVPair::second_type sentinel_refcount =
- std::numeric_limits<BacktraceMap::KVPair::second_type>::max() / 2;
- auto index_and_flag = backtraces_.Insert(sentinel, sentinel_refcount);
- DCHECK(index_and_flag.second);
- out_of_storage_backtrace_index_ = index_and_flag.first;
-}
+ : allocations_(allocation_capacity),
+ backtraces_(backtrace_capacity),
+ out_of_storage_backtrace_index_(CreateBacktraceSentinel()) {}
Primiano Tucci (use gerrit) 2017/04/04 09:50:23 awesome. I wanted to suggest this yesterday during
awong 2017/04/04 18:28:30 Done.
AllocationRegister::~AllocationRegister() {}
@@ -161,6 +148,25 @@ void AllocationRegister::EstimateTraceMemoryOverhead(
overhead->Add("AllocationRegister", allocated, resident);
}
+AllocationRegister::BacktraceMap::KVIndex
+AllocationRegister::CreateBacktraceSentinel() {
+ Backtrace sentinel = {};
+ sentinel.frames[0] = StackFrame::FromThreadName("[out of heap profiler mem]");
+ sentinel.frame_count = 1;
+
+ // Rationale for max / 2: in theory we could just start the sentinel with a
+ // refcount == 0. However, using max / 2 allows short circuiting of the
+ // conditional in RemoveBacktrace() keeping the sentinel logic out of the fast
+ // path. From a functional viewpoint, the sentinel is safe even if we wrap
+ // over the refcount.
+ BacktraceMap::KVPair::second_type sentinel_refcount =
+ std::numeric_limits<BacktraceMap::KVPair::second_type>::max() / 2;
+ auto index_and_flag = backtraces_.Insert(sentinel, sentinel_refcount);
+ DCHECK(index_and_flag.second);
+
+ return index_and_flag.first;
+}
+
AllocationRegister::BacktraceMap::KVIndex AllocationRegister::InsertBacktrace(
const Backtrace& backtrace) {
auto index = backtraces_.Insert(backtrace, 0).first;

Powered by Google App Engine
This is Rietveld 408576698