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

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

Issue 1258903003: Revert of [tracing] Fix, simplify and speed up accounting of TraceEvent memory overhead (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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 | « base/trace_event/trace_event_memory_overhead.h ('k') | no next file » | 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/trace_event_memory_overhead.h" 5 #include "base/trace_event/trace_event_memory_overhead.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bits.h" 9 #include "base/bits.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 void TraceEventMemoryOverhead::AddSelf() { 116 void TraceEventMemoryOverhead::AddSelf() {
117 size_t estimated_size = sizeof(*this); 117 size_t estimated_size = sizeof(*this);
118 // If the SmallMap did overflow its static capacity, its elements will be 118 // If the SmallMap did overflow its static capacity, its elements will be
119 // allocated on the heap and have to be accounted separately. 119 // allocated on the heap and have to be accounted separately.
120 if (allocated_objects_.UsingFullMap()) 120 if (allocated_objects_.UsingFullMap())
121 estimated_size += sizeof(map_type::value_type) * allocated_objects_.size(); 121 estimated_size += sizeof(map_type::value_type) * allocated_objects_.size();
122 Add("TraceEventMemoryOverhead", estimated_size); 122 Add("TraceEventMemoryOverhead", estimated_size);
123 } 123 }
124 124
125 size_t TraceEventMemoryOverhead::GetCount(const char* object_type) const {
126 const auto& it = allocated_objects_.find(object_type);
127 if (it == allocated_objects_.end())
128 return 0u;
129 return it->second.count;
130 }
131
132 void TraceEventMemoryOverhead::Update(const TraceEventMemoryOverhead& other) { 125 void TraceEventMemoryOverhead::Update(const TraceEventMemoryOverhead& other) {
133 for (const auto& it : other.allocated_objects_) { 126 for (const auto& it : other.allocated_objects_) {
134 AddOrCreateInternal(it.first, it.second.count, 127 AddOrCreateInternal(it.first, it.second.count,
135 it.second.allocated_size_in_bytes, 128 it.second.allocated_size_in_bytes,
136 it.second.resident_size_in_bytes); 129 it.second.resident_size_in_bytes);
137 } 130 }
138 } 131 }
139 132
140 void TraceEventMemoryOverhead::DumpInto(const char* base_name, 133 void TraceEventMemoryOverhead::DumpInto(const char* base_name,
141 ProcessMemoryDump* pmd) const { 134 ProcessMemoryDump* pmd) const {
142 for (const auto& it : allocated_objects_) { 135 for (const auto& it : allocated_objects_) {
143 std::string dump_name = StringPrintf("%s/%s", base_name, it.first); 136 std::string dump_name = StringPrintf("%s/%s", base_name, it.first);
144 MemoryAllocatorDump* mad = pmd->CreateAllocatorDump(dump_name); 137 MemoryAllocatorDump* mad = pmd->CreateAllocatorDump(dump_name);
145 mad->AddScalar(MemoryAllocatorDump::kNameSize, 138 mad->AddScalar(MemoryAllocatorDump::kNameSize,
146 MemoryAllocatorDump::kUnitsBytes, 139 MemoryAllocatorDump::kUnitsBytes,
147 it.second.allocated_size_in_bytes); 140 it.second.allocated_size_in_bytes);
148 mad->AddScalar("resident_size", MemoryAllocatorDump::kUnitsBytes, 141 mad->AddScalar("resident_size", MemoryAllocatorDump::kUnitsBytes,
149 it.second.resident_size_in_bytes); 142 it.second.resident_size_in_bytes);
150 mad->AddScalar(MemoryAllocatorDump::kNameObjectsCount, 143 mad->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
151 MemoryAllocatorDump::kUnitsObjects, it.second.count); 144 MemoryAllocatorDump::kUnitsObjects, it.second.count);
152 } 145 }
153 } 146 }
154 147
155 } // namespace trace_event 148 } // namespace trace_event
156 } // namespace base 149 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_memory_overhead.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698