| 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::trace_event::TraceLog. | 9 // - Get trace events JSON string from base::trace_event::TraceLog. |
| 10 // - Create TraceAnalyzer with JSON string. | 10 // - Create TraceAnalyzer with JSON string. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 TraceEvent(); | 113 TraceEvent(); |
| 114 TraceEvent(const TraceEvent& other); | 114 TraceEvent(const TraceEvent& other); |
| 115 ~TraceEvent(); | 115 ~TraceEvent(); |
| 116 | 116 |
| 117 bool SetFromJSON(const base::Value* event_value) WARN_UNUSED_RESULT; | 117 bool SetFromJSON(const base::Value* event_value) WARN_UNUSED_RESULT; |
| 118 | 118 |
| 119 bool operator< (const TraceEvent& rhs) const { | 119 bool operator< (const TraceEvent& rhs) const { |
| 120 return timestamp < rhs.timestamp; | 120 return timestamp < rhs.timestamp; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void operator=(const TraceEvent& rhs); |
| 124 |
| 123 bool has_other_event() const { return other_event; } | 125 bool has_other_event() const { return other_event; } |
| 124 | 126 |
| 125 // Returns absolute duration in microseconds between this event and other | 127 // Returns absolute duration in microseconds between this event and other |
| 126 // event. Must have already verified that other_event exists by | 128 // event. Must have already verified that other_event exists by |
| 127 // Query(EVENT_HAS_OTHER) or by calling has_other_event(). | 129 // Query(EVENT_HAS_OTHER) or by calling has_other_event(). |
| 128 double GetAbsTimeToOtherEvent() const; | 130 double GetAbsTimeToOtherEvent() const; |
| 129 | 131 |
| 130 // Return the argument value if it exists and it is a string. | 132 // Return the argument value if it exists and it is a string. |
| 131 bool GetArgAsString(const std::string& name, std::string* arg) const; | 133 bool GetArgAsString(const std::string& name, std::string* arg) const; |
| 132 // Return the argument value if it exists and it is a number. | 134 // Return the argument value if it exists and it is a number. |
| 133 bool GetArgAsNumber(const std::string& name, double* arg) const; | 135 bool GetArgAsNumber(const std::string& name, double* arg) const; |
| 136 // Return the argument value if it exists. |
| 137 bool GetArgAsValue(const std::string& name, |
| 138 scoped_ptr<base::Value>* arg) const; |
| 134 | 139 |
| 135 // Check if argument exists and is string. | 140 // Check if argument exists and is string. |
| 136 bool HasStringArg(const std::string& name) const; | 141 bool HasStringArg(const std::string& name) const; |
| 137 // Check if argument exists and is number (double, int or bool). | 142 // Check if argument exists and is number (double, int or bool). |
| 138 bool HasNumberArg(const std::string& name) const; | 143 bool HasNumberArg(const std::string& name) const; |
| 144 // Check if argument exists. |
| 145 bool HasArg(const std::string& name) const; |
| 139 | 146 |
| 140 // Get known existing arguments as specific types. | 147 // Get known existing arguments as specific types. |
| 141 // Useful when you have already queried the argument with | 148 // Useful when you have already queried the argument with |
| 142 // Query(HAS_NUMBER_ARG) or Query(HAS_STRING_ARG). | 149 // Query(HAS_NUMBER_ARG) or Query(HAS_STRING_ARG). |
| 143 std::string GetKnownArgAsString(const std::string& name) const; | 150 std::string GetKnownArgAsString(const std::string& name) const; |
| 144 double GetKnownArgAsDouble(const std::string& name) const; | 151 double GetKnownArgAsDouble(const std::string& name) const; |
| 145 int GetKnownArgAsInt(const std::string& name) const; | 152 int GetKnownArgAsInt(const std::string& name) const; |
| 146 bool GetKnownArgAsBool(const std::string& name) const; | 153 bool GetKnownArgAsBool(const std::string& name) const; |
| 154 scoped_ptr<base::Value> GetKnownArgAsValue(const std::string& name) const; |
| 147 | 155 |
| 148 // Process ID and Thread ID. | 156 // Process ID and Thread ID. |
| 149 ProcessThreadID thread; | 157 ProcessThreadID thread; |
| 150 | 158 |
| 151 // Time since epoch in microseconds. | 159 // Time since epoch in microseconds. |
| 152 // Stored as double to match its JSON representation. | 160 // Stored as double to match its JSON representation. |
| 153 double timestamp; | 161 double timestamp; |
| 154 | 162 |
| 155 double duration; | 163 double duration; |
| 156 | 164 |
| 157 char phase; | 165 char phase; |
| 158 | 166 |
| 159 std::string category; | 167 std::string category; |
| 160 | 168 |
| 161 std::string name; | 169 std::string name; |
| 162 | 170 |
| 163 std::string id; | 171 std::string id; |
| 164 | 172 |
| 165 // All numbers and bool values from TraceEvent args are cast to double. | 173 // All numbers and bool values from TraceEvent args are cast to double. |
| 166 // bool becomes 1.0 (true) or 0.0 (false). | 174 // bool becomes 1.0 (true) or 0.0 (false). |
| 167 std::map<std::string, double> arg_numbers; | 175 std::map<std::string, double> arg_numbers; |
| 168 | 176 |
| 169 std::map<std::string, std::string> arg_strings; | 177 std::map<std::string, std::string> arg_strings; |
| 170 | 178 |
| 179 std::map<std::string, scoped_ptr<base::Value>> arg_values; |
| 180 |
| 171 // The other event associated with this event (or NULL). | 181 // The other event associated with this event (or NULL). |
| 172 const TraceEvent* other_event; | 182 const TraceEvent* other_event; |
| 173 }; | 183 }; |
| 174 | 184 |
| 175 typedef std::vector<const TraceEvent*> TraceEventVector; | 185 typedef std::vector<const TraceEvent*> TraceEventVector; |
| 176 | 186 |
| 177 class Query { | 187 class Query { |
| 178 public: | 188 public: |
| 179 Query(const Query& query); | 189 Query(const Query& query); |
| 180 | 190 |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 | 712 |
| 703 // Count all matches. | 713 // Count all matches. |
| 704 static inline size_t CountMatches(const TraceEventVector& events, | 714 static inline size_t CountMatches(const TraceEventVector& events, |
| 705 const Query& query) { | 715 const Query& query) { |
| 706 return CountMatches(events, query, 0u, events.size()); | 716 return CountMatches(events, query, 0u, events.size()); |
| 707 } | 717 } |
| 708 | 718 |
| 709 } // namespace trace_analyzer | 719 } // namespace trace_analyzer |
| 710 | 720 |
| 711 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 721 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| OLD | NEW |