| OLD | NEW |
| 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 // 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 static Query EventDuration() { return Query(EVENT_DURATION); } | 208 static Query EventDuration() { return Query(EVENT_DURATION); } |
| 209 | 209 |
| 210 static Query EventPhase() { return Query(EVENT_PHASE); } | 210 static Query EventPhase() { return Query(EVENT_PHASE); } |
| 211 | 211 |
| 212 static Query EventCategory() { return Query(EVENT_CATEGORY); } | 212 static Query EventCategory() { return Query(EVENT_CATEGORY); } |
| 213 | 213 |
| 214 static Query EventName() { return Query(EVENT_NAME); } | 214 static Query EventName() { return Query(EVENT_NAME); } |
| 215 | 215 |
| 216 static Query EventId() { return Query(EVENT_ID); } | 216 static Query EventId() { return Query(EVENT_ID); } |
| 217 | 217 |
| 218 static Query EventPidIs(int process_id) { |
| 219 return Query(EVENT_PID) == Query::Int(process_id); |
| 220 } |
| 221 |
| 222 static Query EventTidIs(int thread_id) { |
| 223 return Query(EVENT_TID) == Query::Int(thread_id); |
| 224 } |
| 225 |
| 226 static Query EventThreadIs(const TraceEvent::ProcessThreadID& thread) { |
| 227 return EventPidIs(thread.process_id) && EventTidIs(thread.thread_id); |
| 228 } |
| 229 |
| 230 static Query EventTimeIs(double timestamp) { |
| 231 return Query(EVENT_TIME) == Query::Double(timestamp); |
| 232 } |
| 233 |
| 234 static Query EventDurationIs(double duration) { |
| 235 return Query(EVENT_DURATION) == Query::Double(duration); |
| 236 } |
| 237 |
| 238 static Query EventPhaseIs(char phase) { |
| 239 return Query(EVENT_PHASE) == Query::Phase(phase); |
| 240 } |
| 241 |
| 242 static Query EventCategoryIs(const std::string& category) { |
| 243 return Query(EVENT_CATEGORY) == Query::String(category); |
| 244 } |
| 245 |
| 246 static Query EventNameIs(const std::string& name) { |
| 247 return Query(EVENT_NAME) == Query::String(name); |
| 248 } |
| 249 |
| 250 static Query EventIdIs(const std::string& id) { |
| 251 return Query(EVENT_ID) == Query::String(id); |
| 252 } |
| 253 |
| 218 // Evaluates to true if arg exists and is a string. | 254 // Evaluates to true if arg exists and is a string. |
| 219 static Query EventHasStringArg(const std::string& arg_name) { | 255 static Query EventHasStringArg(const std::string& arg_name) { |
| 220 return Query(EVENT_HAS_STRING_ARG, arg_name); | 256 return Query(EVENT_HAS_STRING_ARG, arg_name); |
| 221 } | 257 } |
| 222 | 258 |
| 223 // Evaluates to true if arg exists and is a number. | 259 // Evaluates to true if arg exists and is a number. |
| 224 // Number arguments include types double, int and bool. | 260 // Number arguments include types double, int and bool. |
| 225 static Query EventHasNumberArg(const std::string& arg_name) { | 261 static Query EventHasNumberArg(const std::string& arg_name) { |
| 226 return Query(EVENT_HAS_NUMBER_ARG, arg_name); | 262 return Query(EVENT_HAS_NUMBER_ARG, arg_name); |
| 227 } | 263 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 243 static Query OtherTime() { return Query(OTHER_TIME); } | 279 static Query OtherTime() { return Query(OTHER_TIME); } |
| 244 | 280 |
| 245 static Query OtherPhase() { return Query(OTHER_PHASE); } | 281 static Query OtherPhase() { return Query(OTHER_PHASE); } |
| 246 | 282 |
| 247 static Query OtherCategory() { return Query(OTHER_CATEGORY); } | 283 static Query OtherCategory() { return Query(OTHER_CATEGORY); } |
| 248 | 284 |
| 249 static Query OtherName() { return Query(OTHER_NAME); } | 285 static Query OtherName() { return Query(OTHER_NAME); } |
| 250 | 286 |
| 251 static Query OtherId() { return Query(OTHER_ID); } | 287 static Query OtherId() { return Query(OTHER_ID); } |
| 252 | 288 |
| 289 static Query OtherPidIs(int process_id) { |
| 290 return Query(OTHER_PID) == Query::Int(process_id); |
| 291 } |
| 292 |
| 293 static Query OtherTidIs(int thread_id) { |
| 294 return Query(OTHER_TID) == Query::Int(thread_id); |
| 295 } |
| 296 |
| 297 static Query OtherThreadIs(const TraceEvent::ProcessThreadID& thread) { |
| 298 return OtherPidIs(thread.process_id) && OtherTidIs(thread.thread_id); |
| 299 } |
| 300 |
| 301 static Query OtherTimeIs(double timestamp) { |
| 302 return Query(OTHER_TIME) == Query::Double(timestamp); |
| 303 } |
| 304 |
| 305 static Query OtherPhaseIs(char phase) { |
| 306 return Query(OTHER_PHASE) == Query::Phase(phase); |
| 307 } |
| 308 |
| 309 static Query OtherCategoryIs(const std::string& category) { |
| 310 return Query(OTHER_CATEGORY) == Query::String(category); |
| 311 } |
| 312 |
| 313 static Query OtherNameIs(const std::string& name) { |
| 314 return Query(OTHER_NAME) == Query::String(name); |
| 315 } |
| 316 |
| 317 static Query OtherIdIs(const std::string& id) { |
| 318 return Query(OTHER_ID) == Query::String(id); |
| 319 } |
| 320 |
| 321 // Evaluates to true if arg exists and is a string. |
| 253 static Query OtherHasStringArg(const std::string& arg_name) { | 322 static Query OtherHasStringArg(const std::string& arg_name) { |
| 254 return Query(OTHER_HAS_STRING_ARG, arg_name); | 323 return Query(OTHER_HAS_STRING_ARG, arg_name); |
| 255 } | 324 } |
| 256 | 325 |
| 326 // Evaluates to true if arg exists and is a number. |
| 327 // Number arguments include types double, int and bool. |
| 257 static Query OtherHasNumberArg(const std::string& arg_name) { | 328 static Query OtherHasNumberArg(const std::string& arg_name) { |
| 258 return Query(OTHER_HAS_NUMBER_ARG, arg_name); | 329 return Query(OTHER_HAS_NUMBER_ARG, arg_name); |
| 259 } | 330 } |
| 260 | 331 |
| 332 // Evaluates to arg value (string or number). |
| 261 static Query OtherArg(const std::string& arg_name) { | 333 static Query OtherArg(const std::string& arg_name) { |
| 262 return Query(OTHER_ARG, arg_name); | 334 return Query(OTHER_ARG, arg_name); |
| 263 } | 335 } |
| 264 | 336 |
| 265 //////////////////////////////////////////////////////////////// | 337 //////////////////////////////////////////////////////////////// |
| 266 // Common queries: | 338 // Common queries: |
| 267 | 339 |
| 268 // Find BEGIN events that have a corresponding END event. | 340 // Find BEGIN events that have a corresponding END event. |
| 269 static Query MatchBeginWithEnd() { | 341 static Query MatchBeginWithEnd() { |
| 270 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && | 342 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // should evaluate to true if the |first|/|second| pair is a match. | 574 // should evaluate to true if the |first|/|second| pair is a match. |
| 503 // | 575 // |
| 504 // When a match is found, the pair will be associated by having the first | 576 // When a match is found, the pair will be associated by having the first |
| 505 // event's other_event member point to the other. AssociateEvents does not | 577 // event's other_event member point to the other. AssociateEvents does not |
| 506 // clear previous associations, so it is possible to associate multiple pairs | 578 // clear previous associations, so it is possible to associate multiple pairs |
| 507 // of events by calling AssociateEvents more than once with different queries. | 579 // of events by calling AssociateEvents more than once with different queries. |
| 508 // | 580 // |
| 509 // NOTE: AssociateEvents will overwrite existing other_event associations if | 581 // NOTE: AssociateEvents will overwrite existing other_event associations if |
| 510 // the queries pass for events that already had a previous association. | 582 // the queries pass for events that already had a previous association. |
| 511 // | 583 // |
| 512 // After calling FindEvents or FindOneEvent, it is not allowed to call | 584 // After calling any Find* method, it is not allowed to call AssociateEvents |
| 513 // AssociateEvents again. | 585 // again. |
| 514 void AssociateEvents(const Query& first, | 586 void AssociateEvents(const Query& first, |
| 515 const Query& second, | 587 const Query& second, |
| 516 const Query& match); | 588 const Query& match); |
| 517 | 589 |
| 518 // For each event, copy its arguments to the other_event argument map. If | 590 // For each event, copy its arguments to the other_event argument map. If |
| 519 // argument name already exists, it will not be overwritten. | 591 // argument name already exists, it will not be overwritten. |
| 520 void MergeAssociatedEventArgs(); | 592 void MergeAssociatedEventArgs(); |
| 521 | 593 |
| 522 // Find all events that match query and replace output vector. | 594 // Find all events that match query and replace output vector. |
| 523 size_t FindEvents(const Query& query, TraceEventVector* output); | 595 size_t FindEvents(const Query& query, TraceEventVector* output); |
| 524 | 596 |
| 525 // Helper method: find first event that matches query | 597 // Find first event that matches query or NULL if not found. |
| 526 const TraceEvent* FindOneEvent(const Query& query); | 598 const TraceEvent* FindFirstOf(const Query& query); |
| 599 |
| 600 // Find last event that matches query or NULL if not found. |
| 601 const TraceEvent* FindLastOf(const Query& query); |
| 527 | 602 |
| 528 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); | 603 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); |
| 529 | 604 |
| 530 private: | 605 private: |
| 531 TraceAnalyzer(); | 606 TraceAnalyzer(); |
| 532 | 607 |
| 533 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; | 608 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; |
| 534 | 609 |
| 535 // Read metadata (thread names, etc) from events. | 610 // Read metadata (thread names, etc) from events. |
| 536 void ParseMetadata(); | 611 void ParseMetadata(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 675 |
| 601 // Count all matches. | 676 // Count all matches. |
| 602 static inline size_t CountMatches(const TraceEventVector& events, | 677 static inline size_t CountMatches(const TraceEventVector& events, |
| 603 const Query& query) { | 678 const Query& query) { |
| 604 return CountMatches(events, query, 0u, events.size()); | 679 return CountMatches(events, query, 0u, events.size()); |
| 605 } | 680 } |
| 606 | 681 |
| 607 } // namespace trace_analyzer | 682 } // namespace trace_analyzer |
| 608 | 683 |
| 609 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 684 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| OLD | NEW |