Chromium Code Reviews| 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 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 template <size_t NumBuckets, class Key, class Value, class KeyHasher> | 38 template <size_t NumBuckets, class Key, class Value, class KeyHasher> |
| 39 class FixedHashMap { | 39 class FixedHashMap { |
| 40 // To keep things simple we don't call destructors. | 40 // To keep things simple we don't call destructors. |
| 41 static_assert(is_trivially_destructible<Key>::value && | 41 static_assert(is_trivially_destructible<Key>::value && |
| 42 is_trivially_destructible<Value>::value, | 42 is_trivially_destructible<Value>::value, |
| 43 "Key and Value shouldn't have destructors"); | 43 "Key and Value shouldn't have destructors"); |
| 44 public: | 44 public: |
| 45 using KVPair = std::pair<const Key, Value>; | 45 using KVPair = std::pair<const Key, Value>; |
| 46 | 46 |
| 47 // For implementation simplicity API uses integer index instead | 47 // For implementation simplicity API uses integer index instead |
| 48 // of iterators. Most operations (except FindValidIndex) on KVIndex | 48 // of iterators. Most operations (except Find) on KVIndex are O(1). |
| 49 // are O(1). | |
| 50 using KVIndex = size_t; | 49 using KVIndex = size_t; |
| 51 static const KVIndex kInvalidKVIndex = static_cast<KVIndex>(-1); | 50 static const KVIndex kInvalidKVIndex = static_cast<KVIndex>(-1); |
| 52 | 51 |
| 53 // Capacity controls how many items this hash map can hold, and largely | 52 // Capacity controls how many items this hash map can hold, and largely |
| 54 // affects memory footprint. | 53 // affects memory footprint. |
| 55 FixedHashMap(size_t capacity) | 54 FixedHashMap(size_t capacity) |
| 56 : num_cells_(capacity), | 55 : num_cells_(capacity), |
| 57 cells_(static_cast<Cell*>( | 56 cells_(static_cast<Cell*>( |
| 58 AllocateGuardedVirtualMemory(num_cells_ * sizeof(Cell)))), | 57 AllocateGuardedVirtualMemory(num_cells_ * sizeof(Cell)))), |
| 59 buckets_(static_cast<Bucket*>( | 58 buckets_(static_cast<Bucket*>( |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) const; | 297 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) const; |
| 299 | 298 |
| 300 private: | 299 private: |
| 301 friend AllocationRegisterTest; | 300 friend AllocationRegisterTest; |
| 302 | 301 |
| 303 // Expect max 1.5M allocations. Number of buckets is 2^18 for optimal | 302 // Expect max 1.5M allocations. Number of buckets is 2^18 for optimal |
| 304 // hashing and should be changed together with AddressHasher. | 303 // hashing and should be changed together with AddressHasher. |
| 305 static const size_t kAllocationBuckets = 1 << 18; | 304 static const size_t kAllocationBuckets = 1 << 18; |
| 306 static const size_t kAllocationCapacity = 1500000; | 305 static const size_t kAllocationCapacity = 1500000; |
| 307 | 306 |
| 308 // Expect max 2^15 unique backtraces. Can be changed to 2^16 without | 307 // 2^16 works well with BacktraceHasher. When increasing this number make |
| 309 // needing to tweak BacktraceHasher implementation. | 308 // sure BacktraceHasher still produces low number of collisions. |
| 310 static const size_t kBacktraceBuckets = 1 << 15; | 309 static const size_t kBacktraceBuckets = 1 << 16; |
| 311 static const size_t kBacktraceCapacity = kBacktraceBuckets; | 310 #if defined(OS_ANDROID) |
| 311 static const size_t kBacktraceCapacity = 32000; // 22K was observed | |
| 312 #else | |
| 313 static const size_t kBacktraceCapacity = 55000; // 45K was observed on Linux | |
|
Primiano Tucci (use gerrit)
2016/08/03 13:15:01
maybe just go for 64k or 128k? On linux we usually
| |
| 314 #endif | |
| 312 | 315 |
| 313 struct BacktraceHasher { | 316 struct BacktraceHasher { |
| 314 size_t operator () (const Backtrace& backtrace) const; | 317 size_t operator () (const Backtrace& backtrace) const; |
| 315 }; | 318 }; |
| 316 | 319 |
| 317 using BacktraceMap = internal::FixedHashMap< | 320 using BacktraceMap = internal::FixedHashMap< |
| 318 kBacktraceBuckets, | 321 kBacktraceBuckets, |
| 319 Backtrace, | 322 Backtrace, |
| 320 size_t, // Number of references to the backtrace (the key). Incremented | 323 size_t, // Number of references to the backtrace (the key). Incremented |
| 321 // when an allocation that references the backtrace is inserted, | 324 // when an allocation that references the backtrace is inserted, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 347 AllocationMap allocations_; | 350 AllocationMap allocations_; |
| 348 BacktraceMap backtraces_; | 351 BacktraceMap backtraces_; |
| 349 | 352 |
| 350 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); | 353 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); |
| 351 }; | 354 }; |
| 352 | 355 |
| 353 } // namespace trace_event | 356 } // namespace trace_event |
| 354 } // namespace base | 357 } // namespace base |
| 355 | 358 |
| 356 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 359 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| OLD | NEW |