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

Side by Side Diff: base/trace_event/heap_profiler_allocation_register.cc

Issue 2705023002: [Experimental, DO NOT LAND] bucket num 16
Patch Set: impl Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/heap_profiler_allocation_register.h" 5 #include "base/trace_event/heap_profiler_allocation_register.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event_memory_overhead.h" 9 #include "base/trace_event/trace_event_memory_overhead.h"
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 total_value += backtrace.frame_count; 50 total_value += backtrace.frame_count;
51 51
52 // These magic constants give best results in terms of average collisions 52 // These magic constants give best results in terms of average collisions
53 // per backtrace. They were found by replaying real backtraces from Linux 53 // per backtrace. They were found by replaying real backtraces from Linux
54 // and Android against different hash functions. 54 // and Android against different hash functions.
55 return (total_value * 131101) >> 14; 55 return (total_value * 131101) >> 14;
56 } 56 }
57 57
58 size_t AllocationRegister::AddressHasher::operator () (
59 const void* address) const {
60 // The multiplicative hashing scheme from [Knuth 1998]. The value of |a| has
61 // been chosen carefully based on measurements with real-word data (addresses
62 // recorded from a Chrome trace run). It is the first prime after 2^17. For
63 // |shift|, 15 yield good results for both 2^18 and 2^19 bucket sizes.
64 // Microbenchmarks show that this simple scheme outperforms fancy hashes like
65 // Murmur3 by 20 to 40 percent.
66 const uintptr_t key = reinterpret_cast<uintptr_t>(address);
67 const uintptr_t a = 131101;
68 const uintptr_t shift = 15;
69 const uintptr_t h = (key * a) >> shift;
70 return h;
71 }
72
73 AllocationRegister::AllocationRegister() 58 AllocationRegister::AllocationRegister()
74 : AllocationRegister(kAllocationCapacity, kBacktraceCapacity) {} 59 : AllocationRegister(kAllocationCapacity, kBacktraceCapacity) {}
75 60
76 AllocationRegister::AllocationRegister(size_t allocation_capacity, 61 AllocationRegister::AllocationRegister(size_t allocation_capacity,
77 size_t backtrace_capacity) 62 size_t backtrace_capacity)
78 : allocations_(allocation_capacity), 63 : allocations_(allocation_capacity),
79 backtraces_(backtrace_capacity) {} 64 backtraces_(backtrace_capacity) {}
80 65
81 AllocationRegister::~AllocationRegister() { 66 AllocationRegister::~AllocationRegister() {
82 } 67 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 address_and_info.first, 156 address_and_info.first,
172 address_and_info.second.size, 157 address_and_info.second.size,
173 AllocationContext( 158 AllocationContext(
174 backtrace_and_count.first, 159 backtrace_and_count.first,
175 address_and_info.second.type_name) 160 address_and_info.second.type_name)
176 }; 161 };
177 } 162 }
178 163
179 } // namespace trace_event 164 } // namespace trace_event
180 } // namespace base 165 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698