35 // Total malloc'd memory amount
36 size_t MallocMemorySnapshot::total() const {
37 size_t amount = 0;
38 for (int index = 0; index < mt_number_of_types; index ++) {
39 amount += _malloc[index].malloc_size();
40 }
41 amount += _tracking_header.size() + total_arena();
42 return amount;
43 }
44
45 // Total malloc'd memory used by arenas
46 size_t MallocMemorySnapshot::total_arena() const {
47 size_t amount = 0;
48 for (int index = 0; index < mt_number_of_types; index ++) {
49 amount += _malloc[index].arena_size();
50 }
51 return amount;
52 }
53
54 // Make adjustment by subtracting chunks used by arenas
55 // from total chunks to get total free chunck size
56 void MallocMemorySnapshot::make_adjustment() {
57 size_t arena_size = total_arena();
58 int chunk_idx = NMTUtil::flag_to_index(mtChunk);
59 _malloc[chunk_idx].record_free(arena_size);
60 }
61
62
63 void MallocMemorySummary::initialize() {
64 assert(sizeof(_snapshot) >= sizeof(MallocMemorySnapshot), "Sanity Check");
65 // Uses placement new operator to initialize static area.
66 ::new ((void*)_snapshot)MallocMemorySnapshot();
67 }
68
69 void MallocHeader::release() const {
70 // Tracking already shutdown, no housekeeping is needed anymore
71 if (MemTracker::tracking_level() <= NMT_minimal) return;
72
73 MallocMemorySummary::record_free(size(), flags());
74 MallocMemorySummary::record_free_malloc_header(sizeof(MallocHeader));
75 if (MemTracker::tracking_level() == NMT_detail) {
|
35 // Total malloc'd memory amount
36 size_t MallocMemorySnapshot::total() const {
37 size_t amount = 0;
38 for (int index = 0; index < mt_number_of_types; index ++) {
39 amount += _malloc[index].malloc_size();
40 }
41 amount += _tracking_header.size() + total_arena();
42 return amount;
43 }
44
45 // Total malloc'd memory used by arenas
46 size_t MallocMemorySnapshot::total_arena() const {
47 size_t amount = 0;
48 for (int index = 0; index < mt_number_of_types; index ++) {
49 amount += _malloc[index].arena_size();
50 }
51 return amount;
52 }
53
54 // Make adjustment by subtracting chunks used by arenas
55 // from total chunks to get total free chunk size
56 void MallocMemorySnapshot::make_adjustment() {
57 size_t arena_size = total_arena();
58 int chunk_idx = NMTUtil::flag_to_index(mtChunk);
59 _malloc[chunk_idx].record_free(arena_size);
60 }
61
62
63 void MallocMemorySummary::initialize() {
64 assert(sizeof(_snapshot) >= sizeof(MallocMemorySnapshot), "Sanity Check");
65 // Uses placement new operator to initialize static area.
66 ::new ((void*)_snapshot)MallocMemorySnapshot();
67 }
68
69 void MallocHeader::release() const {
70 // Tracking already shutdown, no housekeeping is needed anymore
71 if (MemTracker::tracking_level() <= NMT_minimal) return;
72
73 MallocMemorySummary::record_free(size(), flags());
74 MallocMemorySummary::record_free_malloc_header(sizeof(MallocHeader));
75 if (MemTracker::tracking_level() == NMT_detail) {
|