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

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

Issue 8355024: Internalize JSON chunk management to trace_event.h API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include "base/debug/trace_event_win.h" 10 #include "base/debug/trace_event_win.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 } 218 }
219 219
220 TraceEvent::~TraceEvent() { 220 TraceEvent::~TraceEvent() {
221 } 221 }
222 222
223 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, 223 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
224 size_t start, 224 size_t start,
225 size_t count, 225 size_t count,
226 std::string* out) { 226 std::string* out) {
227 *out += "[";
228 for (size_t i = 0; i < count && start + i < events.size(); ++i) { 227 for (size_t i = 0; i < count && start + i < events.size(); ++i) {
229 if (i > 0) 228 if (i > 0)
230 *out += ","; 229 *out += ",";
231 events[i + start].AppendAsJSON(out); 230 events[i + start].AppendAsJSON(out);
232 } 231 }
233 *out += "]";
234 } 232 }
235 233
236 void TraceEvent::AppendAsJSON(std::string* out) const { 234 void TraceEvent::AppendAsJSON(std::string* out) const {
237 const char* phase_str = GetPhaseStr(phase_); 235 const char* phase_str = GetPhaseStr(phase_);
238 int64 time_int64 = timestamp_.ToInternalValue(); 236 int64 time_int64 = timestamp_.ToInternalValue();
239 // Category name checked at category creation time. 237 // Category name checked at category creation time.
240 DCHECK(!strchr(name_, '"')); 238 DCHECK(!strchr(name_, '"'));
241 StringAppendF(out, 239 StringAppendF(out,
242 "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld," 240 "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld,"
243 "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{", 241 "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{",
(...skipping 11 matching lines...) Expand all
255 *out += "\""; 253 *out += "\"";
256 *out += arg_names_[i]; 254 *out += arg_names_[i];
257 *out += "\":"; 255 *out += "\":";
258 arg_values_[i].AppendAsJSON(out); 256 arg_values_[i].AppendAsJSON(out);
259 } 257 }
260 *out += "}}"; 258 *out += "}}";
261 } 259 }
262 260
263 //////////////////////////////////////////////////////////////////////////////// 261 ////////////////////////////////////////////////////////////////////////////////
264 // 262 //
263 // TraceResultBuffer
264 //
265 ////////////////////////////////////////////////////////////////////////////////
266
267 TraceResultBuffer::TraceResultBuffer() {
268 }
269
270 TraceResultBuffer::~TraceResultBuffer() {
271 }
272
273 void TraceResultBuffer::AddFragment(const std::string& trace_fragment) {
274 fragments_.push_back(trace_fragment);
275 }
276
277 void TraceResultBuffer::GetJSON(std::string* json_trace_output) {
278 *json_trace_output = "[";
279 for (size_t i = 0; i < fragments_.size(); ++i) {
nduca 2011/10/20 00:28:03 Algorithmically, I see a bit too many strdups. I'd
jbates 2011/10/20 22:18:49 Similar optimizations occurred to me, but I though
280 if (i > 0)
281 *json_trace_output += ",";
282 *json_trace_output += fragments_[i];
283 }
284 *json_trace_output += "]";
285 }
286
287 ////////////////////////////////////////////////////////////////////////////////
288 //
265 // TraceLog 289 // TraceLog
266 // 290 //
267 //////////////////////////////////////////////////////////////////////////////// 291 ////////////////////////////////////////////////////////////////////////////////
268 292
269 // static 293 // static
270 TraceLog* TraceLog::GetInstance() { 294 TraceLog* TraceLog::GetInstance() {
271 return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get(); 295 return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get();
272 } 296 }
273 297
274 TraceLog::TraceLog() 298 TraceLog::TraceLog()
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 NULL, 0, NULL, 0, 634 NULL, 0, NULL, 0,
611 p_data_->threshold_begin_id, p_data_->threshold, 635 p_data_->threshold_begin_id, p_data_->threshold,
612 TraceLog::EVENT_FLAG_NONE); 636 TraceLog::EVENT_FLAG_NONE);
613 } 637 }
614 } 638 }
615 639
616 } // namespace internal 640 } // namespace internal
617 641
618 } // namespace debug 642 } // namespace debug
619 } // namespace base 643 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698