OLD | NEW |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 () ( | 58 size_t AllocationRegister::AddressHasher::operator () ( |
59 const void* address) const { | 59 const void* address) const { |
60 // The multiplicative hashing scheme from [Knuth 1998]. The value of |a| has | 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 | 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 | 62 // recorded from a Chrome trace run). It is the first prime after 2^17. For |
63 // |shift|, 13, 14 and 15 yield good results. These values are tuned to 2^18 | 63 // |shift|, 15 yield good results for both 2^18 and 2^19 bucket sizes. |
64 // buckets. Microbenchmarks show that this simple scheme outperforms fancy | 64 // Microbenchmarks show that this simple scheme outperforms fancy hashes like |
65 // hashes like Murmur3 by 20 to 40 percent. | 65 // Murmur3 by 20 to 40 percent. |
66 const uintptr_t key = reinterpret_cast<uintptr_t>(address); | 66 const uintptr_t key = reinterpret_cast<uintptr_t>(address); |
67 const uintptr_t a = 131101; | 67 const uintptr_t a = 131101; |
68 const uintptr_t shift = 14; | 68 const uintptr_t shift = 15; |
69 const uintptr_t h = (key * a) >> shift; | 69 const uintptr_t h = (key * a) >> shift; |
70 return h; | 70 return h; |
71 } | 71 } |
72 | 72 |
73 AllocationRegister::AllocationRegister() | 73 AllocationRegister::AllocationRegister() |
74 : AllocationRegister(kAllocationCapacity, kBacktraceCapacity) {} | 74 : AllocationRegister(kAllocationCapacity, kBacktraceCapacity) {} |
75 | 75 |
76 AllocationRegister::AllocationRegister(size_t allocation_capacity, | 76 AllocationRegister::AllocationRegister(size_t allocation_capacity, |
77 size_t backtrace_capacity) | 77 size_t backtrace_capacity) |
78 : allocations_(allocation_capacity), | 78 : allocations_(allocation_capacity), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 address_and_info.first, | 171 address_and_info.first, |
172 address_and_info.second.size, | 172 address_and_info.second.size, |
173 AllocationContext( | 173 AllocationContext( |
174 backtrace_and_count.first, | 174 backtrace_and_count.first, |
175 address_and_info.second.type_name) | 175 address_and_info.second.type_name) |
176 }; | 176 }; |
177 } | 177 } |
178 | 178 |
179 } // namespace trace_event | 179 } // namespace trace_event |
180 } // namespace base | 180 } // namespace base |
OLD | NEW |