Chromium Code Reviews| 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::trace_event::TraceLog. |
| 10 // - Create TraceAnalyzer with JSON string. | 10 // - Create TraceAnalyzer with JSON string. |
| 11 // - Call TraceAnalyzer::AssociateBeginEndEvents (optional). | 11 // - Call TraceAnalyzer::AssociateBeginEndEvents (optional). |
| 12 // - Call TraceAnalyzer::AssociateEvents (zero or more times). | 12 // - Call TraceAnalyzer::AssociateEvents (zero or more times). |
| 13 // - Call TraceAnalyzer::FindEvents with queries to find specific events. | 13 // - Call TraceAnalyzer::FindEvents with queries to find specific events. |
| 14 // | 14 // |
| 15 // A Query is a boolean expression tree that evaluates to true or false for a | 15 // A Query is a boolean expression tree that evaluates to true or false for a |
| 16 // given trace event. Queries can be combined into a tree using boolean, | 16 // given trace event. Queries can be combined into a tree using boolean, |
| 17 // arithmetic and comparison operators that refer to data of an individual trace | 17 // arithmetic and comparison operators that refer to data of an individual trace |
| 18 // event. | 18 // event. |
| 19 // | 19 // |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Query(EVENT_HAS_OTHER)); | 65 // Query(EVENT_HAS_OTHER)); |
| 66 // analyzer.FindEvents(q, &events); | 66 // analyzer.FindEvents(q, &events); |
| 67 // | 67 // |
| 68 // Step 4: analyze events, such as checking durations. | 68 // Step 4: analyze events, such as checking durations. |
| 69 // for (size_t i = 0; i < events.size(); ++i) { | 69 // for (size_t i = 0; i < events.size(); ++i) { |
| 70 // double duration; | 70 // double duration; |
| 71 // EXPECT_TRUE(events[i].GetAbsTimeToOtherEvent(&duration)); | 71 // EXPECT_TRUE(events[i].GetAbsTimeToOtherEvent(&duration)); |
| 72 // EXPECT_LT(duration, 1000000.0/60.0); // expect less than 1/60 second. | 72 // EXPECT_LT(duration, 1000000.0/60.0); // expect less than 1/60 second. |
| 73 // } | 73 // } |
| 74 | 74 |
| 75 | |
|
Primiano Tucci (use gerrit)
2015/02/09 12:17:45
Nit: You accidentally ate this line.
| |
| 76 #ifndef BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 75 #ifndef BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| 77 #define BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 76 #define BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| 78 | 77 |
| 79 #include <map> | 78 #include <map> |
| 80 | 79 |
| 81 #include "base/memory/ref_counted.h" | 80 #include "base/memory/ref_counted.h" |
| 82 #include "base/trace_event/trace_event.h" | 81 #include "base/trace_event/trace_event.h" |
| 83 | 82 |
| 84 namespace base { | 83 namespace base { |
| 85 class Value; | 84 class Value; |
| 86 } | 85 } |
| 87 | 86 |
| 88 namespace trace_analyzer { | 87 namespace trace_analyzer { |
| 89 class QueryNode; | 88 class QueryNode; |
| 90 | 89 |
| 91 // trace_analyzer::TraceEvent is a more convenient form of the | 90 // trace_analyzer::TraceEvent is a more convenient form of the |
| 92 // base::debug::TraceEvent class to make tracing-based tests easier to write. | 91 // base::trace_event::TraceEvent class to make tracing-based tests easier to |
| 92 // write. | |
| 93 struct TraceEvent { | 93 struct TraceEvent { |
| 94 // ProcessThreadID contains a Process ID and Thread ID. | 94 // ProcessThreadID contains a Process ID and Thread ID. |
| 95 struct ProcessThreadID { | 95 struct ProcessThreadID { |
| 96 ProcessThreadID() : process_id(0), thread_id(0) {} | 96 ProcessThreadID() : process_id(0), thread_id(0) {} |
| 97 ProcessThreadID(int process_id, int thread_id) | 97 ProcessThreadID(int process_id, int thread_id) |
| 98 : process_id(process_id), thread_id(thread_id) {} | 98 : process_id(process_id), thread_id(thread_id) {} |
| 99 bool operator< (const ProcessThreadID& rhs) const { | 99 bool operator< (const ProcessThreadID& rhs) const { |
| 100 if (process_id != rhs.process_id) | 100 if (process_id != rhs.process_id) |
| 101 return process_id < rhs.process_id; | 101 return process_id < rhs.process_id; |
| 102 return thread_id < rhs.thread_id; | 102 return thread_id < rhs.thread_id; |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 | 696 |
| 697 // Count all matches. | 697 // Count all matches. |
| 698 static inline size_t CountMatches(const TraceEventVector& events, | 698 static inline size_t CountMatches(const TraceEventVector& events, |
| 699 const Query& query) { | 699 const Query& query) { |
| 700 return CountMatches(events, query, 0u, events.size()); | 700 return CountMatches(events, query, 0u, events.size()); |
| 701 } | 701 } |
| 702 | 702 |
| 703 } // namespace trace_analyzer | 703 } // namespace trace_analyzer |
| 704 | 704 |
| 705 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 705 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| OLD | NEW |