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

Side by Side Diff: base/test/trace_event_analyzer.h

Issue 8682027: Add TraceAnalyzer support for START/FINISH events and JSON error logging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | base/test/trace_event_analyzer.cc » ('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) 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 // Use trace_analyzer::Query and trace_analyzer::TraceAnalyzer to search for 5 // Use trace_analyzer::Query and trace_analyzer::TraceAnalyzer to search for
6 // specific trace events that were generated by the trace_event.h API. 6 // specific trace events that were generated by the trace_event.h API.
7 // 7 //
8 // Basic procedure: 8 // Basic procedure:
9 // - Get trace events JSON string from base::debug::TraceLog. 9 // - Get trace events JSON string from base::debug::TraceLog.
10 // - Create TraceAnalyzer with JSON string. 10 // - Create TraceAnalyzer with JSON string.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Time since epoch in microseconds. 151 // Time since epoch in microseconds.
152 // Stored as double to match its JSON representation. 152 // Stored as double to match its JSON representation.
153 double timestamp; 153 double timestamp;
154 154
155 base::debug::TraceEventPhase phase; 155 base::debug::TraceEventPhase phase;
156 156
157 std::string category; 157 std::string category;
158 158
159 std::string name; 159 std::string name;
160 160
161 std::string id;
162
161 // All numbers and bool values from TraceEvent args are cast to double. 163 // All numbers and bool values from TraceEvent args are cast to double.
162 // bool becomes 1.0 (true) or 0.0 (false). 164 // bool becomes 1.0 (true) or 0.0 (false).
163 std::map<std::string, double> arg_numbers; 165 std::map<std::string, double> arg_numbers;
164 166
165 std::map<std::string, std::string> arg_strings; 167 std::map<std::string, std::string> arg_strings;
166 168
167 // The other event associated with this event (or NULL). 169 // The other event associated with this event (or NULL).
168 const TraceEvent* other_event; 170 const TraceEvent* other_event;
169 }; 171 };
170 172
171 // Pass these values to Query to compare with the corresponding member of a 173 // Pass these values to Query to compare with the corresponding member of a
172 // TraceEvent. Unless otherwise specfied, the usage is Query(ENUM_MEMBER). 174 // TraceEvent. Unless otherwise specfied, the usage is Query(ENUM_MEMBER).
173 enum TraceEventMember { 175 enum TraceEventMember {
174 EVENT_INVALID, 176 EVENT_INVALID,
175 // Use these to access the event members: 177 // Use these to access the event members:
176 EVENT_PID, 178 EVENT_PID,
177 EVENT_TID, 179 EVENT_TID,
178 // Return the timestamp of the event in microseconds since epoch. 180 // Return the timestamp of the event in microseconds since epoch.
179 EVENT_TIME, 181 EVENT_TIME,
180 // Return the absolute time between event and other event in microseconds. 182 // Return the absolute time between event and other event in microseconds.
181 // Only works for events with associated BEGIN/END: Query(EVENT_HAS_OTHER). 183 // Only works for events with associated BEGIN/END: Query(EVENT_HAS_OTHER).
182 EVENT_DURATION, 184 EVENT_DURATION,
183 EVENT_PHASE, 185 EVENT_PHASE,
184 EVENT_CATEGORY, 186 EVENT_CATEGORY,
185 EVENT_NAME, 187 EVENT_NAME,
188 EVENT_ID,
186 189
187 // Evaluates to true if arg exists and is a string. 190 // Evaluates to true if arg exists and is a string.
188 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name") 191 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name")
189 EVENT_HAS_STRING_ARG, 192 EVENT_HAS_STRING_ARG,
190 // Evaluates to true if arg exists and is a number. 193 // Evaluates to true if arg exists and is a number.
191 // Number arguments include types double, int and bool. 194 // Number arguments include types double, int and bool.
192 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name") 195 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name")
193 EVENT_HAS_NUMBER_ARG, 196 EVENT_HAS_NUMBER_ARG,
194 // Evaluates to arg value (string or number). 197 // Evaluates to arg value (string or number).
195 // Usage: Query(EVENT_ARG, "arg_name") 198 // Usage: Query(EVENT_ARG, "arg_name")
196 EVENT_ARG, 199 EVENT_ARG,
197 // Return true if associated event exists. 200 // Return true if associated event exists.
198 // (Typically BEGIN for END or END for BEGIN). 201 // (Typically BEGIN for END or END for BEGIN).
199 EVENT_HAS_OTHER, 202 EVENT_HAS_OTHER,
200 203
201 // Access the associated other_event's members: 204 // Access the associated other_event's members:
202 OTHER_PID, 205 OTHER_PID,
203 OTHER_TID, 206 OTHER_TID,
204 OTHER_TIME, 207 OTHER_TIME,
205 OTHER_PHASE, 208 OTHER_PHASE,
206 OTHER_CATEGORY, 209 OTHER_CATEGORY,
207 OTHER_NAME, 210 OTHER_NAME,
211 OTHER_ID,
208 212
209 // Evaluates to true if arg exists and is a string. 213 // Evaluates to true if arg exists and is a string.
210 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name") 214 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name")
211 OTHER_HAS_STRING_ARG, 215 OTHER_HAS_STRING_ARG,
212 // Evaluates to true if arg exists and is a number. 216 // Evaluates to true if arg exists and is a number.
213 // Number arguments include types double, int and bool. 217 // Number arguments include types double, int and bool.
214 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name") 218 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name")
215 OTHER_HAS_NUMBER_ARG, 219 OTHER_HAS_NUMBER_ARG,
216 // Evaluates to arg value (string or number). 220 // Evaluates to arg value (string or number).
217 // Usage: Query(EVENT_ARG, "arg_name") 221 // Usage: Query(EVENT_ARG, "arg_name")
(...skipping 27 matching lines...) Expand all
245 static Query Phase(base::debug::TraceEventPhase phase); 249 static Query Phase(base::debug::TraceEventPhase phase);
246 250
247 // Compare with the given string pattern. Only works with == and != operators. 251 // Compare with the given string pattern. Only works with == and != operators.
248 // Example: Query(EVENT_NAME) == Query::Pattern("MyEvent*") 252 // Example: Query(EVENT_NAME) == Query::Pattern("MyEvent*")
249 static Query Pattern(const std::string& pattern); 253 static Query Pattern(const std::string& pattern);
250 254
251 // Common queries: 255 // Common queries:
252 256
253 // Find BEGIN events that have a corresponding END event. 257 // Find BEGIN events that have a corresponding END event.
254 static Query MatchBeginWithEnd() { 258 static Query MatchBeginWithEnd() {
255 return (Query(EVENT_PHASE) == 259 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) &&
256 Query::Phase(TRACE_EVENT_PHASE_BEGIN)) &&
257 Query(EVENT_HAS_OTHER); 260 Query(EVENT_HAS_OTHER);
258 } 261 }
259 262
263 // Find START events that have a corresponding FINISH event.
264 static Query MatchStartWithFinish() {
265 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_START)) &&
266 Query(EVENT_HAS_OTHER);
267 }
268
260 // Find BEGIN events of given |name| which also have associated END events. 269 // Find BEGIN events of given |name| which also have associated END events.
261 static Query MatchBeginName(const std::string& name) { 270 static Query MatchBeginName(const std::string& name) {
262 return (Query(EVENT_NAME) == name) && MatchBeginWithEnd(); 271 return (Query(EVENT_NAME) == name) && MatchBeginWithEnd();
263 } 272 }
264 273
265 // Match given Process ID and Thread ID. 274 // Match given Process ID and Thread ID.
266 static Query MatchThread(const TraceEvent::ProcessThreadID& thread) { 275 static Query MatchThread(const TraceEvent::ProcessThreadID& thread) {
267 return (Query(EVENT_PID) == Query::Int(thread.process_id)) && 276 return (Query(EVENT_PID) == Query::Int(thread.process_id)) &&
268 (Query(EVENT_TID) == Query::Int(thread.thread_id)); 277 (Query(EVENT_TID) == Query::Int(thread.thread_id));
269 } 278 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 static TraceAnalyzer* Create(const std::string& json_events) 427 static TraceAnalyzer* Create(const std::string& json_events)
419 WARN_UNUSED_RESULT; 428 WARN_UNUSED_RESULT;
420 429
421 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) 430 // Associate BEGIN and END events with each other. This allows Query(OTHER_*)
422 // to access the associated event and enables Query(EVENT_DURATION). 431 // to access the associated event and enables Query(EVENT_DURATION).
423 // An end event will match the most recent begin event with the same name, 432 // An end event will match the most recent begin event with the same name,
424 // category, process ID and thread ID. This matches what is shown in 433 // category, process ID and thread ID. This matches what is shown in
425 // about:tracing. 434 // about:tracing.
426 void AssociateBeginEndEvents(); 435 void AssociateBeginEndEvents();
427 436
437 // Associate START and FINISH events with each other.
438 // A FINISH event will match the most recent START event with the same name,
439 // category, and ID.
440 void AssociateStartFinishEvents();
441
428 // AssociateEvents can be used to customize event associations by setting the 442 // AssociateEvents can be used to customize event associations by setting the
429 // other_event member of TraceEvent. This should be used to associate two 443 // other_event member of TraceEvent. This should be used to associate two
430 // INSTANT events. 444 // INSTANT events.
431 // 445 //
432 // The assumptions are: 446 // The assumptions are:
433 // - |first| events occur before |second| events. 447 // - |first| events occur before |second| events.
434 // - the closest matching |second| event is the correct match. 448 // - the closest matching |second| event is the correct match.
435 // 449 //
436 // |first| - Eligible |first| events match this query. 450 // |first| - Eligible |first| events match this query.
437 // |second| - Eligible |second| events match this query. 451 // |second| - Eligible |second| events match this query.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; 486 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_;
473 std::vector<TraceEvent> raw_events_; 487 std::vector<TraceEvent> raw_events_;
474 bool allow_assocation_changes_; 488 bool allow_assocation_changes_;
475 489
476 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); 490 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer);
477 }; 491 };
478 492
479 } // namespace trace_analyzer 493 } // namespace trace_analyzer
480 494
481 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ 495 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_
OLDNEW
« no previous file with comments | « no previous file | base/test/trace_event_analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698