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

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

Issue 1265393007: Reland 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: 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_impl.h ('k') | base/trace_event/trace_event_memory_overhead.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/json/string_escape.h" 8 #include "base/json/string_escape.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 } 165 }
166 166
167 void TraceEvent::Reset() { 167 void TraceEvent::Reset() {
168 // Only reset fields that won't be initialized in Initialize(), or that may 168 // Only reset fields that won't be initialized in Initialize(), or that may
169 // hold references to other objects. 169 // hold references to other objects.
170 duration_ = TimeDelta::FromInternalValue(-1); 170 duration_ = TimeDelta::FromInternalValue(-1);
171 parameter_copy_storage_ = NULL; 171 parameter_copy_storage_ = NULL;
172 for (int i = 0; i < kTraceMaxNumArgs; ++i) 172 for (int i = 0; i < kTraceMaxNumArgs; ++i)
173 convertable_values_[i] = NULL; 173 convertable_values_[i] = NULL;
174 cached_memory_overhead_estimate_.reset();
175 } 174 }
176 175
177 void TraceEvent::UpdateDuration(const TraceTicks& now, 176 void TraceEvent::UpdateDuration(const TraceTicks& now,
178 const ThreadTicks& thread_now) { 177 const ThreadTicks& thread_now) {
179 DCHECK_EQ(duration_.ToInternalValue(), -1); 178 DCHECK_EQ(duration_.ToInternalValue(), -1);
180 duration_ = now - timestamp_; 179 duration_ = now - timestamp_;
181 thread_duration_ = thread_now - thread_timestamp_; 180 thread_duration_ = thread_now - thread_timestamp_;
182 } 181 }
183 182
184 void TraceEvent::EstimateTraceMemoryOverhead( 183 void TraceEvent::EstimateTraceMemoryOverhead(
185 TraceEventMemoryOverhead* overhead) { 184 TraceEventMemoryOverhead* overhead) {
186 if (!cached_memory_overhead_estimate_) { 185 overhead->Add("TraceEvent", sizeof(*this));
187 cached_memory_overhead_estimate_.reset(new TraceEventMemoryOverhead); 186
188 cached_memory_overhead_estimate_->Add("TraceEvent", sizeof(*this)); 187 // TODO(primiano): parameter_copy_storage_ is refcounted and, in theory,
189 // TODO(primiano): parameter_copy_storage_ is refcounted and, in theory, 188 // could be shared by several events and we might overcount. In practice
190 // could be shared by several events and we might overcount. In practice 189 // this is unlikely but it's worth checking.
191 // this is unlikely but it's worth checking. 190 if (parameter_copy_storage_)
192 if (parameter_copy_storage_) { 191 overhead->AddRefCountedString(*parameter_copy_storage_.get());
193 cached_memory_overhead_estimate_->AddRefCountedString( 192
194 *parameter_copy_storage_.get()); 193 for (size_t i = 0; i < kTraceMaxNumArgs; ++i) {
195 } 194 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE)
196 for (size_t i = 0; i < kTraceMaxNumArgs; ++i) { 195 convertable_values_[i]->EstimateTraceMemoryOverhead(overhead);
197 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) {
198 convertable_values_[i]->EstimateTraceMemoryOverhead(
199 cached_memory_overhead_estimate_.get());
200 }
201 }
202 cached_memory_overhead_estimate_->AddSelf();
203 } 196 }
204 overhead->Update(*cached_memory_overhead_estimate_);
205 } 197 }
206 198
207 // static 199 // static
208 void TraceEvent::AppendValueAsJSON(unsigned char type, 200 void TraceEvent::AppendValueAsJSON(unsigned char type,
209 TraceEvent::TraceValue value, 201 TraceEvent::TraceValue value,
210 std::string* out) { 202 std::string* out) {
211 switch (type) { 203 switch (type) {
212 case TRACE_VALUE_TYPE_BOOL: 204 case TRACE_VALUE_TYPE_BOOL:
213 *out += value.as_bool ? "true" : "false"; 205 *out += value.as_bool ? "true" : "false";
214 break; 206 break;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); 388 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text);
397 389
398 *out << value_as_text; 390 *out << value_as_text;
399 } 391 }
400 *out << "}"; 392 *out << "}";
401 } 393 }
402 } 394 }
403 395
404 } // namespace trace_event 396 } // namespace trace_event
405 } // namespace base 397 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_impl.h ('k') | base/trace_event/trace_event_memory_overhead.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698