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

Side by Side Diff: base/trace_event/trace_event_impl.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_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();
174 } 175 }
175 176
176 void TraceEvent::UpdateDuration(const TraceTicks& now, 177 void TraceEvent::UpdateDuration(const TraceTicks& now,
177 const ThreadTicks& thread_now) { 178 const ThreadTicks& thread_now) {
178 DCHECK_EQ(duration_.ToInternalValue(), -1); 179 DCHECK_EQ(duration_.ToInternalValue(), -1);
179 duration_ = now - timestamp_; 180 duration_ = now - timestamp_;
180 thread_duration_ = thread_now - thread_timestamp_; 181 thread_duration_ = thread_now - thread_timestamp_;
181 } 182 }
182 183
183 void TraceEvent::EstimateTraceMemoryOverhead( 184 void TraceEvent::EstimateTraceMemoryOverhead(
184 TraceEventMemoryOverhead* overhead) { 185 TraceEventMemoryOverhead* overhead) {
185 overhead->Add("TraceEvent", sizeof(*this)); 186 if (!cached_memory_overhead_estimate_) {
186 187 cached_memory_overhead_estimate_.reset(new TraceEventMemoryOverhead);
187 // TODO(primiano): parameter_copy_storage_ is refcounted and, in theory, 188 cached_memory_overhead_estimate_->Add("TraceEvent", sizeof(*this));
188 // could be shared by several events and we might overcount. In practice 189 // TODO(primiano): parameter_copy_storage_ is refcounted and, in theory,
189 // this is unlikely but it's worth checking. 190 // could be shared by several events and we might overcount. In practice
190 if (parameter_copy_storage_) 191 // this is unlikely but it's worth checking.
191 overhead->AddRefCountedString(*parameter_copy_storage_.get()); 192 if (parameter_copy_storage_) {
192 193 cached_memory_overhead_estimate_->AddRefCountedString(
193 for (size_t i = 0; i < kTraceMaxNumArgs; ++i) { 194 *parameter_copy_storage_.get());
194 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) 195 }
195 convertable_values_[i]->EstimateTraceMemoryOverhead(overhead); 196 for (size_t i = 0; i < kTraceMaxNumArgs; ++i) {
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();
196 } 203 }
204 overhead->Update(*cached_memory_overhead_estimate_);
197 } 205 }
198 206
199 // static 207 // static
200 void TraceEvent::AppendValueAsJSON(unsigned char type, 208 void TraceEvent::AppendValueAsJSON(unsigned char type,
201 TraceEvent::TraceValue value, 209 TraceEvent::TraceValue value,
202 std::string* out) { 210 std::string* out) {
203 switch (type) { 211 switch (type) {
204 case TRACE_VALUE_TYPE_BOOL: 212 case TRACE_VALUE_TYPE_BOOL:
205 *out += value.as_bool ? "true" : "false"; 213 *out += value.as_bool ? "true" : "false";
206 break; 214 break;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); 396 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text);
389 397
390 *out << value_as_text; 398 *out << value_as_text;
391 } 399 }
392 *out << "}"; 400 *out << "}";
393 } 401 }
394 } 402 }
395 403
396 } // namespace trace_event 404 } // namespace trace_event
397 } // namespace base 405 } // 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