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

Unified Diff: base/trace_event/heap_profiler_allocation_context.cc

Issue 1467453003: [Tracing] Make heap profiler type info a string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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_context.cc
diff --git a/base/trace_event/heap_profiler_allocation_context.cc b/base/trace_event/heap_profiler_allocation_context.cc
index ce8e50d1c777130cb2751b995229c5fb03fcb7d2..038c083f0fa83241f9fef46c0ed239572d282d62 100644
--- a/base/trace_event/heap_profiler_allocation_context.cc
+++ b/base/trace_event/heap_profiler_allocation_context.cc
@@ -22,7 +22,7 @@ AllocationContext AllocationContext::Empty() {
for (size_t i = 0; i < arraysize(ctx.backtrace.frames); i++)
ctx.backtrace.frames[i] = nullptr;
- ctx.type_id = 0;
+ ctx.type_name = nullptr;
return ctx;
}
@@ -34,7 +34,7 @@ bool operator==(const Backtrace& lhs, const Backtrace& rhs) {
}
bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) {
- return (lhs.backtrace == rhs.backtrace) && (lhs.type_id == rhs.type_id);
+ return (lhs.backtrace == rhs.backtrace) && (lhs.type_name == rhs.type_name);
}
} // namespace trace_event
@@ -50,13 +50,18 @@ size_t hash<Backtrace>::operator()(const Backtrace& backtrace) const {
}
size_t hash<AllocationContext>::operator()(const AllocationContext& ctx) const {
- size_t ctx_hash = hash<Backtrace>()(ctx.backtrace);
+ size_t backtrace_hash = hash<Backtrace>()(ctx.backtrace);
+
+ // Multiplicative hash from [Knuth 1998]. Works best if |size_t| is 32 bits,
+ // because the magic number is a prime very close to 2^32 / golden ratio, but
+ // will still redistribute keys bijectively on 64-bit architectures because
+ // the magic number is coprime to 2^64.
+ size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761;
// Multiply one side to break the commutativity of +. Multiplication with a
// number coprime to |numeric_limits<size_t>::max() + 1| is bijective so
- // randomness is preserved. The type ID is assumed to be distributed randomly
- // already so there is no need to hash it.
- return (ctx_hash * 3) + static_cast<size_t>(ctx.type_id);
+ // randomness is preserved.
+ return (backtrace_hash * 3) + type_hash;
}
} // BASE_HASH_NAMESPACE
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context.h ('k') | base/trace_event/heap_profiler_allocation_context_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698