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

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

Issue 1859143003: Handle zero-size allocations properly in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | base/trace_event/heap_profiler_allocation_register_unittest.cc » ('j') | 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 "base/trace_event/trace_event_memory_overhead.h" 7 #include "base/trace_event/trace_event_memory_overhead.h"
8 8
9 namespace base { 9 namespace base {
10 namespace trace_event { 10 namespace trace_event {
(...skipping 18 matching lines...) Expand all
29 29
30 AllocationRegister::~AllocationRegister() { 30 AllocationRegister::~AllocationRegister() {
31 FreeVirtualMemory(buckets_, kNumBuckets * sizeof(CellIndex)); 31 FreeVirtualMemory(buckets_, kNumBuckets * sizeof(CellIndex));
32 FreeVirtualMemory(cells_, num_cells_ * sizeof(Cell)); 32 FreeVirtualMemory(cells_, num_cells_ * sizeof(Cell));
33 } 33 }
34 34
35 void AllocationRegister::Insert(void* address, 35 void AllocationRegister::Insert(void* address,
36 size_t size, 36 size_t size,
37 AllocationContext context) { 37 AllocationContext context) {
38 DCHECK(address != nullptr); 38 DCHECK(address != nullptr);
39 if (size == 0)
40 return;
39 41
40 CellIndex* idx_ptr = Lookup(address); 42 CellIndex* idx_ptr = Lookup(address);
41 43
42 // If the index is 0, the address is not yet present, so insert it. 44 // If the index is 0, the address is not yet present, so insert it.
43 if (*idx_ptr == 0) { 45 if (*idx_ptr == 0) {
44 *idx_ptr = GetFreeCell(); 46 *idx_ptr = GetFreeCell();
45 47
46 // The address stored in a cell is const as long as it is exposed (via the 48 // The address stored in a cell is const as long as it is exposed (via the
47 // iterators or |Get|), but because cells are re-used, a const cast is 49 // iterators or |Get|), but because cells are re-used, a const cast is
48 // required to set it on insert and remove. 50 // required to set it on insert and remove.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 size_t resident = sizeof(AllocationRegister) 190 size_t resident = sizeof(AllocationRegister)
189 // Include size of touched cells (size of |*cells_|). 191 // Include size of touched cells (size of |*cells_|).
190 + sizeof(Cell) * next_unused_cell_ 192 + sizeof(Cell) * next_unused_cell_
191 // Size of |*buckets_|. 193 // Size of |*buckets_|.
192 + sizeof(CellIndex) * kNumBuckets; 194 + sizeof(CellIndex) * kNumBuckets;
193 overhead->Add("AllocationRegister", allocated, resident); 195 overhead->Add("AllocationRegister", allocated, resident);
194 } 196 }
195 197
196 } // namespace trace_event 198 } // namespace trace_event
197 } // namespace base 199 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_register_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698