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

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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
106 // 106 //
107 // TraceEvent 107 // TraceEvent
108 // 108 //
109 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
110 110
111 namespace { 111 namespace {
112 112
113 const char* GetPhaseStr(TraceEventPhase phase) {
114 switch(phase) {
115 case TRACE_EVENT_PHASE_BEGIN:
116 return "B";
117 case TRACE_EVENT_PHASE_INSTANT:
118 return "I";
119 case TRACE_EVENT_PHASE_END:
120 return "E";
121 case TRACE_EVENT_PHASE_METADATA:
122 return "M";
123 default:
124 NOTREACHED() << "Invalid phase argument";
125 return "?";
126 }
127 }
128
129 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; } 113 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; }
130 114
131 // Copies |*member| into |*buffer|, sets |*member| to point to this new 115 // Copies |*member| into |*buffer|, sets |*member| to point to this new
132 // location, and then advances |*buffer| by the amount written. 116 // location, and then advances |*buffer| by the amount written.
133 void CopyTraceEventParameter(char** buffer, 117 void CopyTraceEventParameter(char** buffer,
134 const char** member, 118 const char** member,
135 const char* end) { 119 const char* end) {
136 if (*member) { 120 if (*member) {
137 size_t written = strlcpy(*buffer, *member, end - *buffer) + 1; 121 size_t written = strlcpy(*buffer, *member, end - *buffer) + 1;
138 DCHECK_LE(static_cast<int>(written), end - *buffer); 122 DCHECK_LE(static_cast<int>(written), end - *buffer);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 CopyTraceEventParameter(&ptr, arg_values_[0].as_assignable_string(), end); 189 CopyTraceEventParameter(&ptr, arg_values_[0].as_assignable_string(), end);
206 if (arg2_is_copy) 190 if (arg2_is_copy)
207 CopyTraceEventParameter(&ptr, arg_values_[1].as_assignable_string(), end); 191 CopyTraceEventParameter(&ptr, arg_values_[1].as_assignable_string(), end);
208 DCHECK_EQ(end, ptr) << "Overrun by " << ptr - end; 192 DCHECK_EQ(end, ptr) << "Overrun by " << ptr - end;
209 } 193 }
210 } 194 }
211 195
212 TraceEvent::~TraceEvent() { 196 TraceEvent::~TraceEvent() {
213 } 197 }
214 198
199 const char* TraceEvent::GetPhaseStr(TraceEventPhase phase) {
200 switch(phase) {
201 case TRACE_EVENT_PHASE_BEGIN:
202 return "B";
203 case TRACE_EVENT_PHASE_INSTANT:
204 return "I";
205 case TRACE_EVENT_PHASE_END:
206 return "E";
207 case TRACE_EVENT_PHASE_METADATA:
208 return "M";
209 default:
210 NOTREACHED() << "Invalid phase argument";
211 return "?";
212 }
213 }
214
215 TraceEventPhase TraceEvent::GetPhase(const char* phase) {
216 switch(*phase) {
217 case 'B':
218 return TRACE_EVENT_PHASE_BEGIN;
219 case 'I':
220 return TRACE_EVENT_PHASE_INSTANT;
221 case 'E':
222 return TRACE_EVENT_PHASE_END;
223 case 'M':
224 return TRACE_EVENT_PHASE_METADATA;
225 default:
226 NOTREACHED() << "Invalid phase name";
227 return TRACE_EVENT_PHASE_METADATA;
228 }
229 }
230
215 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, 231 void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
216 size_t start, 232 size_t start,
217 size_t count, 233 size_t count,
218 std::string* out) { 234 std::string* out) {
219 *out += "["; 235 *out += "[";
220 for (size_t i = 0; i < count && start + i < events.size(); ++i) { 236 for (size_t i = 0; i < count && start + i < events.size(); ++i) {
221 if (i > 0) 237 if (i > 0)
222 *out += ","; 238 *out += ",";
223 events[i + start].AppendAsJSON(out); 239 events[i + start].AppendAsJSON(out);
224 } 240 }
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 NULL, 0, NULL, 0, 609 NULL, 0, NULL, 0,
594 p_data_->threshold_begin_id, p_data_->threshold, 610 p_data_->threshold_begin_id, p_data_->threshold,
595 TraceLog::EVENT_FLAG_NONE); 611 TraceLog::EVENT_FLAG_NONE);
596 } 612 }
597 } 613 }
598 614
599 } // namespace internal 615 } // namespace internal
600 616
601 } // namespace debug 617 } // namespace debug
602 } // namespace base 618 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698