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

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

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