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

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

Issue 7981004: add classes trace_analyzer::Query and TraceAnalyzer to make it easy to search through trace data (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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 //////////////////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////////////////
114 // 114 //
115 // TraceEvent 115 // TraceEvent
116 // 116 //
117 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
118 118
119 namespace { 119 namespace {
120 120
121 const char* GetPhaseStr(TraceEventPhase phase) {
122 switch(phase) {
123 case TRACE_EVENT_PHASE_BEGIN:
124 return "B";
125 case TRACE_EVENT_PHASE_INSTANT:
126 return "I";
127 case TRACE_EVENT_PHASE_END:
128 return "E";
129 case TRACE_EVENT_PHASE_METADATA:
130 return "M";
131 default:
132 NOTREACHED() << "Invalid phase argument";
133 return "?";
134 }
135 }
136
137 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; } 121 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; }
138 122
139 // Copies |*member| into |*buffer|, sets |*member| to point to this new 123 // Copies |*member| into |*buffer|, sets |*member| to point to this new
140 // location, and then advances |*buffer| by the amount written. 124 // location, and then advances |*buffer| by the amount written.
141 void CopyTraceEventParameter(char** buffer, 125 void CopyTraceEventParameter(char** buffer,
142 const char** member, 126 const char** member,
143 const char* end) { 127 const char* end) {
144 if (*member) { 128 if (*member) {
145 size_t written = strlcpy(*buffer, *member, end - *buffer) + 1; 129 size_t written = strlcpy(*buffer, *member, end - *buffer) + 1;
146 DCHECK_LE(static_cast<int>(written), end - *buffer); 130 DCHECK_LE(static_cast<int>(written), end - *buffer);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 CopyTraceEventParameter(&ptr, arg_values_[0].as_assignable_string(), end); 197 CopyTraceEventParameter(&ptr, arg_values_[0].as_assignable_string(), end);
214 if (arg2_is_copy) 198 if (arg2_is_copy)
215 CopyTraceEventParameter(&ptr, arg_values_[1].as_assignable_string(), end); 199 CopyTraceEventParameter(&ptr, arg_values_[1].as_assignable_string(), end);
216 DCHECK_EQ(end, ptr) << "Overrun by " << ptr - end; 200 DCHECK_EQ(end, ptr) << "Overrun by " << ptr - end;
217 } 201 }
218 } 202 }
219 203
220 TraceEvent::~TraceEvent() { 204 TraceEvent::~TraceEvent() {
221 } 205 }
222 206
207 const char* TraceEvent::GetPhaseStr(TraceEventPhase phase) {
208 switch(phase) {
209 case TRACE_EVENT_PHASE_BEGIN:
210 return "B";
211 case TRACE_EVENT_PHASE_INSTANT:
212 return "I";
213 case TRACE_EVENT_PHASE_END:
214 return "E";
215 case TRACE_EVENT_PHASE_METADATA:
216 return "M";
217 default:
218 NOTREACHED() << "Invalid phase argument";
219 return "?";
220 }
221 }
222
223 TraceEventPhase TraceEvent::GetPhase(const char* phase) {
224 switch(*phase) {
225 case 'B':
226 return TRACE_EVENT_PHASE_BEGIN;
227 case 'I':
228 return TRACE_EVENT_PHASE_INSTANT;
229 case 'E':
230 return TRACE_EVENT_PHASE_END;
231 case 'M':
232 return TRACE_EVENT_PHASE_METADATA;
233 default:
234 NOTREACHED() << "Invalid phase name";
235 return TRACE_EVENT_PHASE_METADATA;
236 }
237 }
238
223 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, 239 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
224 size_t start, 240 size_t start,
225 size_t count, 241 size_t count,
226 std::string* out) { 242 std::string* out) {
227 *out += "["; 243 *out += "[";
228 for (size_t i = 0; i < count && start + i < events.size(); ++i) { 244 for (size_t i = 0; i < count && start + i < events.size(); ++i) {
229 if (i > 0) 245 if (i > 0)
230 *out += ","; 246 *out += ",";
231 events[i + start].AppendAsJSON(out); 247 events[i + start].AppendAsJSON(out);
232 } 248 }
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 NULL, 0, NULL, 0, 626 NULL, 0, NULL, 0,
611 p_data_->threshold_begin_id, p_data_->threshold, 627 p_data_->threshold_begin_id, p_data_->threshold,
612 TraceLog::EVENT_FLAG_NONE); 628 TraceLog::EVENT_FLAG_NONE);
613 } 629 }
614 } 630 }
615 631
616 } // namespace internal 632 } // namespace internal
617 633
618 } // namespace debug 634 } // namespace debug
619 } // namespace base 635 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698