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 11 matching lines...) Expand all Loading... |
22 // a related trace event. The related trace event is typically the matching end | 22 // a related trace event. The related trace event is typically the matching end |
23 // of a begin event or the matching begin of an end event. | 23 // of a begin event or the matching begin of an end event. |
24 // | 24 // |
25 // The following examples use this basic setup code to construct TraceAnalyzer | 25 // The following examples use this basic setup code to construct TraceAnalyzer |
26 // with the json trace string retrieved from TraceLog and construct an event | 26 // with the json trace string retrieved from TraceLog and construct an event |
27 // vector for retrieving events: | 27 // vector for retrieving events: |
28 // | 28 // |
29 // TraceAnalyzer analyzer(json_events); | 29 // TraceAnalyzer analyzer(json_events); |
30 // TraceEventVector events; | 30 // TraceEventVector events; |
31 // | 31 // |
32 // During construction, TraceAnalyzer::SetDefaultAssociations is called to | |
33 // associate all matching begin/end pairs similar to how they are shown in | |
34 // about:tracing. | |
35 // | |
36 // EXAMPLE 1: Find events named "my_event". | 32 // EXAMPLE 1: Find events named "my_event". |
37 // | 33 // |
38 // analyzer.FindEvents(Query(EVENT_NAME) == "my_event", &events); | 34 // analyzer.FindEvents(Query(EVENT_NAME) == "my_event", &events); |
39 // | 35 // |
40 // EXAMPLE 2: Find begin events named "my_event" with duration > 1 second. | 36 // EXAMPLE 2: Find begin events named "my_event" with duration > 1 second. |
41 // | 37 // |
42 // Query q = (Query(EVENT_NAME) == Query::String("my_event") && | 38 // Query q = (Query(EVENT_NAME) == Query::String("my_event") && |
43 // Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN) && | 39 // Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN) && |
44 // Query(EVENT_DURATION) > Query::Double(1000000.0)); | 40 // Query(EVENT_DURATION) > Query::Double(1000000.0)); |
45 // analyzer.FindEvents(q, &events); | 41 // analyzer.FindEvents(q, &events); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 266 |
271 //////////////////////////////////////////////////////////////// | 267 //////////////////////////////////////////////////////////////// |
272 // Common queries: | 268 // Common queries: |
273 | 269 |
274 // Find BEGIN events that have a corresponding END event. | 270 // Find BEGIN events that have a corresponding END event. |
275 static Query MatchBeginWithEnd() { | 271 static Query MatchBeginWithEnd() { |
276 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && | 272 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && |
277 Query(EVENT_HAS_OTHER); | 273 Query(EVENT_HAS_OTHER); |
278 } | 274 } |
279 | 275 |
280 // Find START events that have a corresponding FINISH event. | 276 // Find ASYNC_BEGIN events that have a corresponding ASYNC_END event. |
281 static Query MatchStartWithFinish() { | 277 static Query MatchAsyncBeginWithNext() { |
282 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_START)) && | 278 return (Query(EVENT_PHASE) == |
| 279 Query::Phase(TRACE_EVENT_PHASE_ASYNC_BEGIN)) && |
283 Query(EVENT_HAS_OTHER); | 280 Query(EVENT_HAS_OTHER); |
284 } | 281 } |
285 | 282 |
286 // Find BEGIN events of given |name| which also have associated END events. | 283 // Find BEGIN events of given |name| which also have associated END events. |
287 static Query MatchBeginName(const std::string& name) { | 284 static Query MatchBeginName(const std::string& name) { |
288 return (Query(EVENT_NAME) == name) && MatchBeginWithEnd(); | 285 return (Query(EVENT_NAME) == name) && MatchBeginWithEnd(); |
289 } | 286 } |
290 | 287 |
291 // Match given Process ID and Thread ID. | 288 // Match given Process ID and Thread ID. |
292 static Query MatchThread(const TraceEvent::ProcessThreadID& thread) { | 289 static Query MatchThread(const TraceEvent::ProcessThreadID& thread) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 472 |
476 // Use trace events from JSON string generated by tracing API. | 473 // Use trace events from JSON string generated by tracing API. |
477 // Returns non-NULL if the JSON is successfully parsed. | 474 // Returns non-NULL if the JSON is successfully parsed. |
478 static TraceAnalyzer* Create(const std::string& json_events) | 475 static TraceAnalyzer* Create(const std::string& json_events) |
479 WARN_UNUSED_RESULT; | 476 WARN_UNUSED_RESULT; |
480 | 477 |
481 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) | 478 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) |
482 // to access the associated event and enables Query(EVENT_DURATION). | 479 // to access the associated event and enables Query(EVENT_DURATION). |
483 // An end event will match the most recent begin event with the same name, | 480 // An end event will match the most recent begin event with the same name, |
484 // category, process ID and thread ID. This matches what is shown in | 481 // category, process ID and thread ID. This matches what is shown in |
485 // about:tracing. | 482 // about:tracing. After association, the BEGIN event will point to the |
| 483 // matching END event, but the END event will not point to the BEGIN event. |
486 void AssociateBeginEndEvents(); | 484 void AssociateBeginEndEvents(); |
487 | 485 |
488 // Associate START and FINISH events with each other. | 486 // Associate ASYNC_BEGIN, ASYNC_STEP and ASYNC_END events with each other. |
489 // A FINISH event will match the most recent START event with the same name, | 487 // An ASYNC_END event will match the most recent ASYNC_BEGIN or ASYNC_STEP |
490 // category, and ID. | 488 // event with the same name, category, and ID. This creates a singly linked |
491 void AssociateStartFinishEvents(); | 489 // list of ASYNC_BEGIN->ASYNC_STEP...->ASYNC_END. |
| 490 void AssociateAsyncBeginEndEvents(); |
492 | 491 |
493 // AssociateEvents can be used to customize event associations by setting the | 492 // AssociateEvents can be used to customize event associations by setting the |
494 // other_event member of TraceEvent. This should be used to associate two | 493 // other_event member of TraceEvent. This should be used to associate two |
495 // INSTANT events. | 494 // INSTANT events. |
496 // | 495 // |
497 // The assumptions are: | 496 // The assumptions are: |
498 // - |first| events occur before |second| events. | 497 // - |first| events occur before |second| events. |
499 // - the closest matching |second| event is the correct match. | 498 // - the closest matching |second| event is the correct match. |
500 // | 499 // |
501 // |first| - Eligible |first| events match this query. | 500 // |first| - Eligible |first| events match this query. |
502 // |second| - Eligible |second| events match this query. | 501 // |second| - Eligible |second| events match this query. |
503 // |match| - This query is run on the |first| event. The OTHER_* EventMember | 502 // |match| - This query is run on the |first| event. The OTHER_* EventMember |
504 // queries will point to an eligible |second| event. The query | 503 // queries will point to an eligible |second| event. The query |
505 // should evaluate to true if the |first|/|second| pair is a match. | 504 // should evaluate to true if the |first|/|second| pair is a match. |
506 // | 505 // |
507 // When a match is found, the pair will be associated by having their | 506 // When a match is found, the pair will be associated by having the first |
508 // other_event member point to each other. AssociateEvents does not clear | 507 // event's other_event member point to the other. AssociateEvents does not |
509 // previous associations, so it is possible to associate multiple pairs of | 508 // clear previous associations, so it is possible to associate multiple pairs |
510 // events by calling AssociateEvents more than once with different queries. | 509 // of events by calling AssociateEvents more than once with different queries. |
511 // | 510 // |
512 // NOTE: AssociateEvents will overwrite existing other_event associations if | 511 // NOTE: AssociateEvents will overwrite existing other_event associations if |
513 // the queries pass for events that already had a previous association. | 512 // the queries pass for events that already had a previous association. |
514 // | 513 // |
515 // After calling FindEvents or FindOneEvent, it is not allowed to call | 514 // After calling FindEvents or FindOneEvent, it is not allowed to call |
516 // AssociateEvents again. | 515 // AssociateEvents again. |
517 void AssociateEvents(const Query& first, | 516 void AssociateEvents(const Query& first, |
518 const Query& second, | 517 const Query& second, |
519 const Query& match); | 518 const Query& match); |
520 | 519 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 590 |
592 // Count all matches. | 591 // Count all matches. |
593 static inline size_t CountMatches(const TraceEventVector& events, | 592 static inline size_t CountMatches(const TraceEventVector& events, |
594 const Query& query) { | 593 const Query& query) { |
595 return CountMatches(events, query, 0u, events.size()); | 594 return CountMatches(events, query, 0u, events.size()); |
596 } | 595 } |
597 | 596 |
598 } // namespace trace_analyzer | 597 } // namespace trace_analyzer |
599 | 598 |
600 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 599 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
OLD | NEW |