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 #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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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), |
| 79 backtraces_(backtrace_capacity) {} | 79 backtraces_(backtrace_capacity) {} |
| 80 | 80 |
| 81 AllocationRegister::~AllocationRegister() { | 81 AllocationRegister::~AllocationRegister() { |
| 82 } | 82 } |
| 83 | 83 |
| 84 void AllocationRegister::Insert(const void* address, | 84 bool AllocationRegister::Insert(const void* address, |
|
Primiano Tucci (use gerrit)
2017/03/30 13:32:40
do we need this bool here?
If it's just for the te
awong
2017/03/31 04:28:30
I feel like the API is cleaner to have a bool retu
Primiano Tucci (use gerrit)
2017/03/31 19:05:47
Not strong enough to justify another round on this
| |
| 85 size_t size, | 85 size_t size, |
| 86 const AllocationContext& context) { | 86 const AllocationContext& context) { |
| 87 DCHECK(address != nullptr); | 87 DCHECK(address != nullptr); |
| 88 if (size == 0) { | 88 if (size == 0) { |
| 89 return; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 AllocationInfo info = { | 92 AllocationInfo info = { |
| 93 size, | 93 size, |
| 94 context.type_name, | 94 context.type_name, |
| 95 InsertBacktrace(context.backtrace) | 95 InsertBacktrace(context.backtrace) |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // Try to insert the allocation. | 98 // Try to insert the allocation. |
| 99 auto index_and_flag = allocations_.Insert(address, info); | 99 auto index_and_flag = allocations_.Insert(address, info); |
| 100 if (!index_and_flag.second) { | 100 if (!index_and_flag.second && |
| 101 index_and_flag.first != AllocationMap::kInvalidKVIndex) { | |
| 101 // |address| is already there - overwrite the allocation info. | 102 // |address| is already there - overwrite the allocation info. |
| 102 auto& old_info = allocations_.Get(index_and_flag.first).second; | 103 auto& old_info = allocations_.Get(index_and_flag.first).second; |
| 103 RemoveBacktrace(old_info.backtrace_index); | 104 RemoveBacktrace(old_info.backtrace_index); |
| 104 old_info = info; | 105 old_info = info; |
| 105 } | 106 } |
| 107 | |
| 108 return index_and_flag.second; | |
| 106 } | 109 } |
| 107 | 110 |
| 108 void AllocationRegister::Remove(const void* address) { | 111 void AllocationRegister::Remove(const void* address) { |
| 109 auto index = allocations_.Find(address); | 112 auto index = allocations_.Find(address); |
| 110 if (index == AllocationMap::kInvalidKVIndex) { | 113 if (index == AllocationMap::kInvalidKVIndex) { |
| 111 return; | 114 return; |
| 112 } | 115 } |
| 113 | 116 |
| 114 const AllocationInfo& info = allocations_.Get(index).second; | 117 const AllocationInfo& info = allocations_.Get(index).second; |
| 115 RemoveBacktrace(info.backtrace_index); | 118 RemoveBacktrace(info.backtrace_index); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 address_and_info.first, | 174 address_and_info.first, |
| 172 address_and_info.second.size, | 175 address_and_info.second.size, |
| 173 AllocationContext( | 176 AllocationContext( |
| 174 backtrace_and_count.first, | 177 backtrace_and_count.first, |
| 175 address_and_info.second.type_name) | 178 address_and_info.second.type_name) |
| 176 }; | 179 }; |
| 177 } | 180 } |
| 178 | 181 |
| 179 } // namespace trace_event | 182 } // namespace trace_event |
| 180 } // namespace base | 183 } // namespace base |
| OLD | NEW |