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 16 matching lines...) Expand all Loading... |
27 // stored. | 27 // stored. |
28 // | 28 // |
29 // Replaying a recording of Chrome's allocations and frees against this hash | 29 // Replaying a recording of Chrome's allocations and frees against this hash |
30 // table takes about 15% of the time that it takes to replay them against | 30 // table takes about 15% of the time that it takes to replay them against |
31 // |std::map|. | 31 // |std::map|. |
32 class BASE_EXPORT AllocationRegister { | 32 class BASE_EXPORT AllocationRegister { |
33 public: | 33 public: |
34 // The data stored in the hash table; | 34 // The data stored in the hash table; |
35 // contains the details about an allocation. | 35 // contains the details about an allocation. |
36 struct Allocation { | 36 struct Allocation { |
37 void* address; | 37 void* const address; |
38 size_t size; | 38 size_t size; |
39 AllocationContext context; | 39 AllocationContext context; |
40 }; | 40 }; |
41 | 41 |
42 // An iterator that iterates entries in the hash table efficiently, but in no | 42 // An iterator that iterates entries in the hash table efficiently, but in no |
43 // particular order. It can do this by iterating the cells and ignoring the | 43 // particular order. It can do this by iterating the cells and ignoring the |
44 // linked lists altogether. Instead of checking whether a cell is in the free | 44 // linked lists altogether. Instead of checking whether a cell is in the free |
45 // list to see if it should be skipped, a null address is used to indicate | 45 // list to see if it should be skipped, a null address is used to indicate |
46 // that a cell is free. | 46 // that a cell is free. |
47 class BASE_EXPORT ConstIterator { | 47 class BASE_EXPORT ConstIterator { |
(...skipping 20 matching lines...) Expand all Loading... |
68 // Inserts allocation details into the table. If the address was present | 68 // Inserts allocation details into the table. If the address was present |
69 // already, its details are updated. |address| must not be null. (This is | 69 // already, its details are updated. |address| must not be null. (This is |
70 // because null is used to mark free cells, to allow efficient iteration of | 70 // because null is used to mark free cells, to allow efficient iteration of |
71 // the hash table.) | 71 // the hash table.) |
72 void Insert(void* address, size_t size, AllocationContext context); | 72 void Insert(void* address, size_t size, AllocationContext context); |
73 | 73 |
74 // Removes the address from the table if it is present. It is ok to call this | 74 // Removes the address from the table if it is present. It is ok to call this |
75 // with a null pointer. | 75 // with a null pointer. |
76 void Remove(void* address); | 76 void Remove(void* address); |
77 | 77 |
| 78 // Returns a pointer to the allocation at the address, or null if there is no |
| 79 // allocation at that address. This can be used to change the allocation |
| 80 // context after insertion, for example to change the type name. |
| 81 Allocation* Get(void* address); |
| 82 |
78 ConstIterator begin() const; | 83 ConstIterator begin() const; |
79 ConstIterator end() const; | 84 ConstIterator end() const; |
80 | 85 |
81 // Estimates memory overhead including |sizeof(AllocationRegister)|. | 86 // Estimates memory overhead including |sizeof(AllocationRegister)|. |
82 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) const; | 87 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) const; |
83 | 88 |
84 private: | 89 private: |
85 friend class AllocationRegisterTest; | 90 friend class AllocationRegisterTest; |
86 using CellIndex = uint32_t; | 91 using CellIndex = uint32_t; |
87 | 92 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // is used. This is the high water mark for the number of entries stored. | 167 // is used. This is the high water mark for the number of entries stored. |
163 CellIndex next_unused_cell_; | 168 CellIndex next_unused_cell_; |
164 | 169 |
165 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); | 170 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); |
166 }; | 171 }; |
167 | 172 |
168 } // namespace trace_event | 173 } // namespace trace_event |
169 } // namespace base | 174 } // namespace base |
170 | 175 |
171 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 176 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
OLD | NEW |