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

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

Issue 8438058: Clean up some API in trace_event_analyzer.h and add some getters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added test for new APIs 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool has_other_event() const { return other_event; } 123 bool has_other_event() const { return other_event; }
124 124
125 // Returns absolute duration in microseconds between this event and other 125 // Returns absolute duration in microseconds between this event and other
126 // event. Returns false if has_other_event() is false. 126 // event. Must have already verified that other_event exists by
127 bool GetAbsTimeToOtherEvent(double* duration) const; 127 // Query(EVENT_HAS_OTHER) or by calling has_other_event().
128 double GetAbsTimeToOtherEvent() const;
nduca 2011/11/03 19:05:53 What happens if you forget to do this? DCHECK or a
jbates 2011/11/03 19:34:39 The behavior is to crash when other_event doesn't
128 129
129 // Return the argument value if it exists and it is a string. 130 // Return the argument value if it exists and it is a string.
130 bool GetArgAsString(const std::string& name, std::string* arg) const; 131 bool GetArgAsString(const std::string& name, std::string* arg) const;
131 // Return the argument value if it exists and it is a number. 132 // Return the argument value if it exists and it is a number.
132 bool GetArgAsNumber(const std::string& name, double* arg) const; 133 bool GetArgAsNumber(const std::string& name, double* arg) const;
133 134
135 // Check if argument exists and is string.
136 bool HasStringArg(const std::string& name) const;
137 // Check if argument exists and is number (double, int or bool).
138 bool HasNumberArg(const std::string& name) const;
139
140 // Get known existing arguments as specific types.
141 // Useful when you have already queried the argument with
142 // Query(HAS_NUMBER_ARG) or Query(HAS_STRING_ARG).
143 std::string GetKnownArgAsString(const std::string& name) const;
144 double GetKnownArgAsDouble(const std::string& name) const;
145 int GetKnownArgAsInt(const std::string& name) const;
146 bool GetKnownArgAsBool(const std::string& name) const;
147
nduca 2011/11/03 19:05:53 I guess by moving to this CL, I didn't get your re
jbates 2011/11/03 19:34:39 What I realized (tried to explain it in the commen
134 // Process ID and Thread ID. 148 // Process ID and Thread ID.
135 ProcessThreadID thread; 149 ProcessThreadID thread;
136 150
137 // Time since epoch in microseconds. 151 // Time since epoch in microseconds.
138 // Stored as double to match its JSON representation. 152 // Stored as double to match its JSON representation.
139 double timestamp; 153 double timestamp;
140 154
141 base::debug::TraceEventPhase phase; 155 base::debug::TraceEventPhase phase;
142 156
143 std::string category; 157 std::string category;
144 158
145 std::string name; 159 std::string name;
146 160
147 // All numbers and bool values from TraceEvent args are cast to double. 161 // All numbers and bool values from TraceEvent args are cast to double.
148 // bool becomes 1.0 (true) or 0.0 (false). 162 // bool becomes 1.0 (true) or 0.0 (false).
149 std::map<std::string, double> arg_numbers; 163 std::map<std::string, double> arg_numbers;
150 164
151 std::map<std::string, std::string> arg_strings; 165 std::map<std::string, std::string> arg_strings;
152 166
153 // The other event associated with this event (or NULL). 167 // The other event associated with this event (or NULL).
154 const TraceEvent* other_event; 168 const TraceEvent* other_event;
155 }; 169 };
156 170
157 // Pass these values to Query to compare with the corresponding member of a 171 // Pass these values to Query to compare with the corresponding member of a
158 // TraceEvent. 172 // TraceEvent. Unless otherwise specfied, the usage is Query(ENUM_MEMBER).
159 enum TraceEventMember { 173 enum TraceEventMember {
160 EVENT_INVALID, 174 EVENT_INVALID,
161 // Use these to access the event members: 175 // Use these to access the event members:
162 EVENT_PID, 176 EVENT_PID,
163 EVENT_TID, 177 EVENT_TID,
164 // Return the timestamp of the event in microseconds since epoch. 178 // Return the timestamp of the event in microseconds since epoch.
165 EVENT_TIME, 179 EVENT_TIME,
166 // Return the absolute time between event and other event in microseconds. 180 // Return the absolute time between event and other event in microseconds.
167 // Only works for events with associated BEGIN/END: Query(EVENT_HAS_OTHER). 181 // Only works for events with associated BEGIN/END: Query(EVENT_HAS_OTHER).
168 EVENT_DURATION, 182 EVENT_DURATION,
169 EVENT_PHASE, 183 EVENT_PHASE,
170 EVENT_CATEGORY, 184 EVENT_CATEGORY,
171 EVENT_NAME, 185 EVENT_NAME,
172 EVENT_HAS_ARG, 186
187 // Evaluates to true if arg exists and is a string.
188 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name")
189 EVENT_HAS_STRING_ARG,
190 // Evaluates to true if arg exists and is a number.
191 // Number arguments include types double, int and bool.
192 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name")
193 EVENT_HAS_NUMBER_ARG,
194 // Evaluates to arg value (string or number).
195 // Usage: Query(EVENT_ARG, "arg_name")
173 EVENT_ARG, 196 EVENT_ARG,
174 // Return true if associated event exists. 197 // Return true if associated event exists.
175 // (Typically BEGIN for END or END for BEGIN). 198 // (Typically BEGIN for END or END for BEGIN).
176 EVENT_HAS_OTHER, 199 EVENT_HAS_OTHER,
177 // Use these to access the associated event's members: 200
201 // Access the associated other_event's members:
178 OTHER_PID, 202 OTHER_PID,
179 OTHER_TID, 203 OTHER_TID,
180 OTHER_TIME, 204 OTHER_TIME,
181 OTHER_PHASE, 205 OTHER_PHASE,
182 OTHER_CATEGORY, 206 OTHER_CATEGORY,
183 OTHER_NAME, 207 OTHER_NAME,
184 OTHER_HAS_ARG, 208
185 OTHER_ARG 209 // Evaluates to true if arg exists and is a string.
210 // Usage: Query(EVENT_HAS_STRING_ARG, "arg_name")
211 OTHER_HAS_STRING_ARG,
212 // Evaluates to true if arg exists and is a number.
213 // Number arguments include types double, int and bool.
214 // Usage: Query(EVENT_HAS_NUMBER_ARG, "arg_name")
215 OTHER_HAS_NUMBER_ARG,
216 // Evaluates to arg value (string or number).
217 // Usage: Query(EVENT_ARG, "arg_name")
218 OTHER_ARG,
186 }; 219 };
187 220
188 class Query { 221 class Query {
189 public: 222 public:
190 // Compare with the given member. 223 // Compare with the given member.
191 Query(TraceEventMember member); 224 Query(TraceEventMember member);
192 225
193 // Compare with the given member argument value. 226 // Compare with the given member argument value.
194 Query(TraceEventMember member, const std::string& arg_name); 227 Query(TraceEventMember member, const std::string& arg_name);
195 228
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; 472 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_;
440 std::vector<TraceEvent> raw_events_; 473 std::vector<TraceEvent> raw_events_;
441 bool allow_assocation_changes_; 474 bool allow_assocation_changes_;
442 475
443 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); 476 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer);
444 }; 477 };
445 478
446 } // namespace trace_analyzer 479 } // namespace trace_analyzer
447 480
448 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ 481 #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