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

Side by Side Diff: base/debug/trace_event_internal.h

Issue 12150004: Category group support/Renamings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed review comments + a few improvements. Created 7 years, 10 months 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
OLDNEW
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 // This header file defines the set of trace_event macros without specifying 5 // This header file defines the set of trace_event macros without specifying
6 // how the events actually get collected and stored. If you need to expose trace 6 // how the events actually get collected and stored. If you need to expose trace
7 // events to some other universe, you can copy-and-paste this file as well as 7 // events to some other universe, you can copy-and-paste this file as well as
8 // trace_event.h, modifying the macros contained there as necessary for the 8 // trace_event.h, modifying the macros contained there as necessary for the
9 // target platform. The end result is that multiple libraries can funnel events 9 // target platform. The end result is that multiple libraries can funnel events
10 // through to a shared trace event collector. 10 // through to a shared trace event collector.
11 11
12 // Trace events are for tracking application performance and resource usage. 12 // Trace events are for tracking application performance and resource usage.
13 // Macros are provided to track: 13 // Macros are provided to track:
14 // Begin and end of function calls 14 // Begin and end of function calls
15 // Counters 15 // Counters
16 // 16 //
17 // Events are issued against categories. Whereas LOG's 17 // Events are issued against categories. Whereas LOG's
18 // categories are statically defined, TRACE categories are created 18 // categories are statically defined, TRACE categories are created
19 // implicitly with a string. For example: 19 // implicitly with a string. For example:
20 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") 20 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent")
21 // 21 //
22 // It is often the case that one trace may belong in multiple categories at the
23 // same time. The first argument to the trace can be a comma-separated list of
24 // categories, forming a category group, like:
25 //
26 // TRACE_EVENT_INSTANT0("input,views", "OnMouseOver")
27 //
28 // We can enable/disable tracing of OnMouseOver by enabling/disabling either
29 // category.
30 //
22 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: 31 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope:
23 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") 32 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly")
24 // doSomethingCostly() 33 // doSomethingCostly()
25 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") 34 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly")
26 // Note: our tools can't always determine the correct BEGIN/END pairs unless 35 // Note: our tools can't always determine the correct BEGIN/END pairs unless
27 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you 36 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you
28 // need them to be in separate scopes. 37 // need them to be in separate scopes.
29 // 38 //
30 // A common use case is to trace entire function scopes. This 39 // A common use case is to trace entire function scopes. This
31 // issues a trace BEGIN and END automatically: 40 // issues a trace BEGIN and END automatically:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // unique ID, by using the TRACE_COUNTER_ID* variations. 101 // unique ID, by using the TRACE_COUNTER_ID* variations.
93 // 102 //
94 // By default, trace collection is compiled in, but turned off at runtime. 103 // By default, trace collection is compiled in, but turned off at runtime.
95 // Collecting trace data is the responsibility of the embedding 104 // Collecting trace data is the responsibility of the embedding
96 // application. In Chrome's case, navigating to about:tracing will turn on 105 // application. In Chrome's case, navigating to about:tracing will turn on
97 // tracing and display data collected across all active processes. 106 // tracing and display data collected across all active processes.
98 // 107 //
99 // 108 //
100 // Memory scoping note: 109 // Memory scoping note:
101 // Tracing copies the pointers, not the string content, of the strings passed 110 // Tracing copies the pointers, not the string content, of the strings passed
102 // in for category, name, and arg_names. Thus, the following code will 111 // in for category_group, name, and arg_names. Thus, the following code will
103 // cause problems: 112 // cause problems:
104 // char* str = strdup("impprtantName"); 113 // char* str = strdup("importantName");
105 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! 114 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD!
106 // free(str); // Trace system now has dangling pointer 115 // free(str); // Trace system now has dangling pointer
107 // 116 //
108 // To avoid this issue with the |name| and |arg_name| parameters, use the 117 // To avoid this issue with the |name| and |arg_name| parameters, use the
109 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. 118 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
110 // Notes: The category must always be in a long-lived char* (i.e. static const). 119 // Notes: The category must always be in a long-lived char* (i.e. static const).
111 // The |arg_values|, when used, are always deep copied with the _COPY 120 // The |arg_values|, when used, are always deep copied with the _COPY
112 // macros. 121 // macros.
113 // 122 //
114 // When are string argument values copied: 123 // When are string argument values copied:
(...skipping 12 matching lines...) Expand all
127 // A thread safe singleton and mutex are used for thread safety. Category 136 // A thread safe singleton and mutex are used for thread safety. Category
128 // enabled flags are used to limit the performance impact when the system 137 // enabled flags are used to limit the performance impact when the system
129 // is not enabled. 138 // is not enabled.
130 // 139 //
131 // TRACE_EVENT macros first cache a pointer to a category. The categories are 140 // TRACE_EVENT macros first cache a pointer to a category. The categories are
132 // statically allocated and safe at all times, even after exit. Fetching a 141 // statically allocated and safe at all times, even after exit. Fetching a
133 // category is protected by the TraceLog::lock_. Multiple threads initializing 142 // category is protected by the TraceLog::lock_. Multiple threads initializing
134 // the static variable is safe, as they will be serialized by the lock and 143 // the static variable is safe, as they will be serialized by the lock and
135 // multiple calls will return the same pointer to the category. 144 // multiple calls will return the same pointer to the category.
136 // 145 //
137 // Then the category_enabled flag is checked. This is a unsigned char, and 146 // Then the category_group_enabled flag is checked. This is a unsigned char, and
138 // not intended to be multithread safe. It optimizes access to AddTraceEvent 147 // not intended to be multithread safe. It optimizes access to AddTraceEvent
139 // which is threadsafe internally via TraceLog::lock_. The enabled flag may 148 // which is threadsafe internally via TraceLog::lock_. The enabled flag may
140 // cause some threads to incorrectly call or skip calling AddTraceEvent near 149 // cause some threads to incorrectly call or skip calling AddTraceEvent near
141 // the time of the system being enabled or disabled. This is acceptable as 150 // the time of the system being enabled or disabled. This is acceptable as
142 // we tolerate some data loss while the system is being enabled/disabled and 151 // we tolerate some data loss while the system is being enabled/disabled and
143 // because AddTraceEvent is threadsafe internally and checks the enabled state 152 // because AddTraceEvent is threadsafe internally and checks the enabled state
144 // again under lock. 153 // again under lock.
145 // 154 //
146 // Without the use of these static category pointers and enabled flags all 155 // Without the use of these static category pointers and enabled flags all
147 // trace points would carry a significant performance cost of aquiring a lock 156 // trace points would carry a significant performance cost of aquiring a lock
(...skipping 13 matching lines...) Expand all
161 // By default, uint64 ID argument values are not mangled with the Process ID in 170 // By default, uint64 ID argument values are not mangled with the Process ID in
162 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. 171 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling.
163 #define TRACE_ID_MANGLE(id) \ 172 #define TRACE_ID_MANGLE(id) \
164 trace_event_internal::TraceID::ForceMangle(id) 173 trace_event_internal::TraceID::ForceMangle(id)
165 174
166 // Records a pair of begin and end events called "name" for the current 175 // Records a pair of begin and end events called "name" for the current
167 // scope, with 0, 1 or 2 associated arguments. If the category is not 176 // scope, with 0, 1 or 2 associated arguments. If the category is not
168 // enabled, then this does nothing. 177 // enabled, then this does nothing.
169 // - category and name strings must have application lifetime (statics or 178 // - category and name strings must have application lifetime (statics or
170 // literals). They may not include " chars. 179 // literals). They may not include " chars.
171 #define TRACE_EVENT0(category, name) \ 180 #define TRACE_EVENT0(category_group, name) \
172 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name) 181 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
173 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ 182 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
174 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val) 183 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
175 #define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ 184 #define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, \
176 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \ 185 arg2_val) \
186 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, \
177 arg2_name, arg2_val) 187 arg2_name, arg2_val)
178 188
179 // Same as TRACE_EVENT except that they are not included in official builds. 189 // Same as TRACE_EVENT except that they are not included in official builds.
180 #ifdef OFFICIAL_BUILD 190 #ifdef OFFICIAL_BUILD
181 #define UNSHIPPED_TRACE_EVENT0(category, name) (void)0 191 #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0
182 #define UNSHIPPED_TRACE_EVENT1(category, name, arg1_name, arg1_val) (void)0 192 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
183 #define UNSHIPPED_TRACE_EVENT2(category, name, arg1_name, arg1_val, \ 193 (void)0
194 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
184 arg2_name, arg2_val) (void)0 195 arg2_name, arg2_val) (void)0
185 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category, name) (void)0 196 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name) (void)0
186 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ 197 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, arg1_name, \
198 arg1_val) \
187 (void)0 199 (void)0
188 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ 200 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, arg1_name, \
189 arg2_name, arg2_val) (void)0 201 arg1_val, arg2_name, arg2_val) (void)0
190 #else 202 #else
191 #define UNSHIPPED_TRACE_EVENT0(category, name) \ 203 #define UNSHIPPED_TRACE_EVENT0(category_group, name) \
192 TRACE_EVENT0(category, name) 204 TRACE_EVENT0(category_group, name)
193 #define UNSHIPPED_TRACE_EVENT1(category, name, arg1_name, arg1_val) \ 205 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
194 TRACE_EVENT1(category, name, arg1_name, arg1_val) 206 TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
195 #define UNSHIPPED_TRACE_EVENT2(category, name, arg1_name, arg1_val, \ 207 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
196 arg2_name, arg2_val) \ 208 arg2_name, arg2_val) \
197 TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) 209 TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
198 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category, name) \ 210 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name) \
199 TRACE_EVENT_INSTANT0(category, name) 211 TRACE_EVENT_INSTANT0(category_group, name)
200 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ 212 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, arg1_name, \
201 TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) 213 arg1_val) \
202 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ 214 TRACE_EVENT_INSTANT1(category_group, name, arg1_name, arg1_val)
203 arg2_name, arg2_val) \ 215 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, arg1_name, \
204 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ 216 arg1_val, arg2_name, arg2_val) \
217 TRACE_EVENT_INSTANT2(category_group, name, arg1_name, arg1_val, \
205 arg2_name, arg2_val) 218 arg2_name, arg2_val)
206 #endif 219 #endif
207 220
208 // Records a single event called "name" immediately, with 0, 1 or 2 221 // Records a single event called "name" immediately, with 0, 1 or 2
209 // associated arguments. If the category is not enabled, then this 222 // associated arguments. If the category is not enabled, then this
210 // does nothing. 223 // does nothing.
211 // - category and name strings must have application lifetime (statics or 224 // - category and name strings must have application lifetime (statics or
212 // literals). They may not include " chars. 225 // literals). They may not include " chars.
213 #define TRACE_EVENT_INSTANT0(category, name) \ 226 #define TRACE_EVENT_INSTANT0(category_group, name) \
214 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 227 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
215 category, name, TRACE_EVENT_FLAG_NONE) 228 category_group, name, TRACE_EVENT_FLAG_NONE)
216 #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ 229 #define TRACE_EVENT_INSTANT1(category_group, name, arg1_name, arg1_val) \
217 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 230 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
218 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 231 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
219 #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ 232 #define TRACE_EVENT_INSTANT2(category_group, name, arg1_name, arg1_val, \
220 arg2_name, arg2_val) \ 233 arg2_name, arg2_val) \
221 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 234 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
222 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ 235 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
223 arg2_name, arg2_val) 236 arg2_name, arg2_val)
224 #define TRACE_EVENT_COPY_INSTANT0(category, name) \ 237 #define TRACE_EVENT_COPY_INSTANT0(category_group, name) \
225 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 238 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
226 category, name, TRACE_EVENT_FLAG_COPY) 239 category_group, name, TRACE_EVENT_FLAG_COPY)
227 #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ 240 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, arg1_name, arg1_val) \
228 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 241 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
229 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) 242 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
230 #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ 243 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, arg1_name, arg1_val, \
231 arg2_name, arg2_val) \ 244 arg2_name, arg2_val) \
232 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ 245 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \
233 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ 246 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
234 arg2_name, arg2_val) 247 arg2_name, arg2_val)
235 248
236 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 249 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2
237 // associated arguments. If the category is not enabled, then this 250 // associated arguments. If the category is not enabled, then this
238 // does nothing. 251 // does nothing.
239 // - category and name strings must have application lifetime (statics or 252 // - category and name strings must have application lifetime (statics or
240 // literals). They may not include " chars. 253 // literals). They may not include " chars.
241 #define TRACE_EVENT_BEGIN0(category, name) \ 254 #define TRACE_EVENT_BEGIN0(category_group, name) \
242 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 255 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
243 category, name, TRACE_EVENT_FLAG_NONE) 256 category_group, name, TRACE_EVENT_FLAG_NONE)
244 #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ 257 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \
245 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 258 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
246 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 259 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
247 #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ 260 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \
248 arg2_name, arg2_val) \ 261 arg2_name, arg2_val) \
249 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 262 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
250 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ 263 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
251 arg2_name, arg2_val) 264 arg2_name, arg2_val)
252 #define TRACE_EVENT_COPY_BEGIN0(category, name) \ 265 #define TRACE_EVENT_COPY_BEGIN0(category_group, name) \
253 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 266 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
254 category, name, TRACE_EVENT_FLAG_COPY) 267 category_group, name, TRACE_EVENT_FLAG_COPY)
255 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ 268 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
256 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 269 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
257 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) 270 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
258 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ 271 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
259 arg2_name, arg2_val) \ 272 arg2_name, arg2_val) \
260 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ 273 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \
261 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ 274 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
262 arg2_name, arg2_val) 275 arg2_name, arg2_val)
263 276
264 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. 277 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
265 // - |id| is used to match the _BEGIN event with the _END event. 278 // - |id| is used to match the _BEGIN event with the _END event.
266 // Events are considered to match if their category, name and id values all 279 // Events are considered to match if their category_group, name and id values
267 // match. |id| must either be a pointer or an integer value up to 64 bits. If 280 // all match. |id| must either be a pointer or an integer value up to 64 bits.
268 // it's a pointer, the bits will be xored with a hash of the process ID so 281 // If it's a pointer, the bits will be xored with a hash of the process ID so
269 // that the same pointer on two different processes will not collide. 282 // that the same pointer on two different processes will not collide.
270 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category, \ 283 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, \
271 name, id, thread_id, timestamp) \ 284 name, id, thread_id, timestamp) \
272 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 285 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
273 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, thread_id, \ 286 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
274 timestamp, TRACE_EVENT_FLAG_NONE) 287 timestamp, TRACE_EVENT_FLAG_NONE)
275 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ 288 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
276 category, name, id, thread_id, timestamp) \ 289 category_group, name, id, thread_id, timestamp) \
277 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 290 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
278 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, thread_id, \ 291 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
279 timestamp, TRACE_EVENT_FLAG_COPY) 292 timestamp, TRACE_EVENT_FLAG_COPY)
280 293
281 // Records a single END event for "name" immediately. If the category 294 // Records a single END event for "name" immediately. If the category
282 // is not enabled, then this does nothing. 295 // is not enabled, then this does nothing.
283 // - category and name strings must have application lifetime (statics or 296 // - category and name strings must have application lifetime (statics or
284 // literals). They may not include " chars. 297 // literals). They may not include " chars.
285 #define TRACE_EVENT_END0(category, name) \ 298 #define TRACE_EVENT_END0(category_group, name) \
286 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 299 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
287 category, name, TRACE_EVENT_FLAG_NONE) 300 category_group, name, TRACE_EVENT_FLAG_NONE)
288 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ 301 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \
289 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 302 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
290 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 303 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
291 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ 304 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, \
292 arg2_name, arg2_val) \ 305 arg2_name, arg2_val) \
293 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 306 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
294 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ 307 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
295 arg2_name, arg2_val) 308 arg2_name, arg2_val)
296 #define TRACE_EVENT_COPY_END0(category, name) \ 309 #define TRACE_EVENT_COPY_END0(category_group, name) \
297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 310 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
298 category, name, TRACE_EVENT_FLAG_COPY) 311 category_group, name, TRACE_EVENT_FLAG_COPY)
299 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ 312 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
300 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 313 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
301 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) 314 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
302 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ 315 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
303 arg2_name, arg2_val) \ 316 arg2_name, arg2_val) \
304 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ 317 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \
305 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ 318 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
306 arg2_name, arg2_val) 319 arg2_name, arg2_val)
307 320
308 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. 321 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
309 // - |id| is used to match the _BEGIN event with the _END event. 322 // - |id| is used to match the _BEGIN event with the _END event.
310 // Events are considered to match if their category, name and id values all 323 // Events are considered to match if their category_group, name and id values
311 // match. |id| must either be a pointer or an integer value up to 64 bits. If 324 // all match. |id| must either be a pointer or an integer value up to 64 bits.
312 // it's a pointer, the bits will be xored with a hash of the process ID so 325 // If it's a pointer, the bits will be xored with a hash of the process ID so
313 // that the same pointer on two different processes will not collide. 326 // that the same pointer on two different processes will not collide.
314 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category, \ 327 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, \
315 name, id, thread_id, timestamp) \ 328 name, id, thread_id, timestamp) \
316 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 329 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
317 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, thread_id, timestamp, \ 330 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
318 TRACE_EVENT_FLAG_NONE) 331 timestamp, TRACE_EVENT_FLAG_NONE)
319 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ 332 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
320 category, name, id, thread_id, timestamp) \ 333 category_group, name, id, thread_id, timestamp) \
321 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 334 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
322 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, thread_id, timestamp, \ 335 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
323 TRACE_EVENT_FLAG_COPY) 336 timestamp, TRACE_EVENT_FLAG_COPY)
324 337
325 // Records the value of a counter called "name" immediately. Value 338 // Records the value of a counter called "name" immediately. Value
326 // must be representable as a 32 bit integer. 339 // must be representable as a 32 bit integer.
327 // - category and name strings must have application lifetime (statics or 340 // - category and name strings must have application lifetime (statics or
328 // literals). They may not include " chars. 341 // literals). They may not include " chars.
329 #define TRACE_COUNTER1(category, name, value) \ 342 #define TRACE_COUNTER1(category_group, name, value) \
330 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ 343 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
331 category, name, TRACE_EVENT_FLAG_NONE, \ 344 category_group, name, TRACE_EVENT_FLAG_NONE, \
332 "value", static_cast<int>(value)) 345 "value", static_cast<int>(value))
333 #define TRACE_COPY_COUNTER1(category, name, value) \ 346 #define TRACE_COPY_COUNTER1(category_group, name, value) \
334 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ 347 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
335 category, name, TRACE_EVENT_FLAG_COPY, \ 348 category_group, name, TRACE_EVENT_FLAG_COPY, \
336 "value", static_cast<int>(value)) 349 "value", static_cast<int>(value))
337 350
338 // Records the values of a multi-parted counter called "name" immediately. 351 // Records the values of a multi-parted counter called "name" immediately.
339 // The UI will treat value1 and value2 as parts of a whole, displaying their 352 // The UI will treat value1 and value2 as parts of a whole, displaying their
340 // values as a stacked-bar chart. 353 // values as a stacked-bar chart.
341 // - category and name strings must have application lifetime (statics or 354 // - category and name strings must have application lifetime (statics or
342 // literals). They may not include " chars. 355 // literals). They may not include " chars.
343 #define TRACE_COUNTER2(category, name, value1_name, value1_val, \ 356 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \
344 value2_name, value2_val) \ 357 value2_name, value2_val) \
345 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ 358 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
346 category, name, TRACE_EVENT_FLAG_NONE, \ 359 category_group, name, TRACE_EVENT_FLAG_NONE, \
347 value1_name, static_cast<int>(value1_val), \ 360 value1_name, static_cast<int>(value1_val), \
348 value2_name, static_cast<int>(value2_val)) 361 value2_name, static_cast<int>(value2_val))
349 #define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ 362 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \
350 value2_name, value2_val) \ 363 value2_name, value2_val) \
351 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ 364 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \
352 category, name, TRACE_EVENT_FLAG_COPY, \ 365 category_group, name, TRACE_EVENT_FLAG_COPY, \
353 value1_name, static_cast<int>(value1_val), \ 366 value1_name, static_cast<int>(value1_val), \
354 value2_name, static_cast<int>(value2_val)) 367 value2_name, static_cast<int>(value2_val))
355 368
356 // Records the value of a counter called "name" immediately. Value 369 // Records the value of a counter called "name" immediately. Value
357 // must be representable as a 32 bit integer. 370 // must be representable as a 32 bit integer.
358 // - category and name strings must have application lifetime (statics or 371 // - category and name strings must have application lifetime (statics or
359 // literals). They may not include " chars. 372 // literals). They may not include " chars.
360 // - |id| is used to disambiguate counters with the same name. It must either 373 // - |id| is used to disambiguate counters with the same name. It must either
361 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits 374 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
362 // will be xored with a hash of the process ID so that the same pointer on 375 // will be xored with a hash of the process ID so that the same pointer on
363 // two different processes will not collide. 376 // two different processes will not collide.
364 #define TRACE_COUNTER_ID1(category, name, id, value) \ 377 #define TRACE_COUNTER_ID1(category_group, name, id, value) \
365 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ 378 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
366 category, name, id, TRACE_EVENT_FLAG_NONE, \ 379 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
367 "value", static_cast<int>(value)) 380 "value", static_cast<int>(value))
368 #define TRACE_COPY_COUNTER_ID1(category, name, id, value) \ 381 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \
369 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ 382 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
370 category, name, id, TRACE_EVENT_FLAG_COPY, \ 383 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
371 "value", static_cast<int>(value)) 384 "value", static_cast<int>(value))
372 385
373 // Records the values of a multi-parted counter called "name" immediately. 386 // Records the values of a multi-parted counter called "name" immediately.
374 // The UI will treat value1 and value2 as parts of a whole, displaying their 387 // The UI will treat value1 and value2 as parts of a whole, displaying their
375 // values as a stacked-bar chart. 388 // values as a stacked-bar chart.
376 // - category and name strings must have application lifetime (statics or 389 // - category and name strings must have application lifetime (statics or
377 // literals). They may not include " chars. 390 // literals). They may not include " chars.
378 // - |id| is used to disambiguate counters with the same name. It must either 391 // - |id| is used to disambiguate counters with the same name. It must either
379 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits 392 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
380 // will be xored with a hash of the process ID so that the same pointer on 393 // will be xored with a hash of the process ID so that the same pointer on
381 // two different processes will not collide. 394 // two different processes will not collide.
382 #define TRACE_COUNTER_ID2(category, name, id, value1_name, value1_val, \ 395 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \
383 value2_name, value2_val) \ 396 value2_name, value2_val) \
384 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ 397 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
385 category, name, id, TRACE_EVENT_FLAG_NONE, \ 398 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
386 value1_name, static_cast<int>(value1_val), \ 399 value1_name, static_cast<int>(value1_val), \
387 value2_name, static_cast<int>(value2_val)) 400 value2_name, static_cast<int>(value2_val))
388 #define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \ 401 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \
389 value2_name, value2_val) \ 402 value1_val, value2_name, value2_val) \
390 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ 403 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \
391 category, name, id, TRACE_EVENT_FLAG_COPY, \ 404 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
392 value1_name, static_cast<int>(value1_val), \ 405 value1_name, static_cast<int>(value1_val), \
393 value2_name, static_cast<int>(value2_val)) 406 value2_name, static_cast<int>(value2_val))
394 407
395 408
396 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2 409 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
397 // associated arguments. If the category is not enabled, then this 410 // associated arguments. If the category is not enabled, then this
398 // does nothing. 411 // does nothing.
399 // - category and name strings must have application lifetime (statics or 412 // - category and name strings must have application lifetime (statics or
400 // literals). They may not include " chars. 413 // literals). They may not include " chars.
401 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC 414 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
402 // events are considered to match if their category, name and id values all 415 // events are considered to match if their category_group, name and id values
403 // match. |id| must either be a pointer or an integer value up to 64 bits. If 416 // all match. |id| must either be a pointer or an integer value up to 64 bits.
404 // it's a pointer, the bits will be xored with a hash of the process ID so 417 // If it's a pointer, the bits will be xored with a hash of the process ID so
405 // that the same pointer on two different processes will not collide. 418 // that the same pointer on two different processes will not collide.
406 // An asynchronous operation can consist of multiple phases. The first phase is 419 // An asynchronous operation can consist of multiple phases. The first phase is
407 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the 420 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
408 // ASYNC_STEP macros. When the operation completes, call ASYNC_END. 421 // ASYNC_STEP macros. When the operation completes, call ASYNC_END.
409 // An ASYNC trace typically occur on a single thread (if not, they will only be 422 // An ASYNC trace typically occur on a single thread (if not, they will only be
410 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that 423 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
411 // operation must use the same |name| and |id|. Each event can have its own 424 // operation must use the same |name| and |id|. Each event can have its own
412 // args. 425 // args.
413 #define TRACE_EVENT_ASYNC_BEGIN0(category, name, id) \ 426 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \
414 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 427 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
415 category, name, id, TRACE_EVENT_FLAG_NONE) 428 category_group, name, id, TRACE_EVENT_FLAG_NONE)
416 #define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \ 429 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
430 arg1_val) \
417 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 431 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
418 category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 432 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
419 #define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \ 433 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
420 arg2_name, arg2_val) \ 434 arg1_val, arg2_name, arg2_val) \
421 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 435 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
422 category, name, id, TRACE_EVENT_FLAG_NONE, \ 436 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
423 arg1_name, arg1_val, arg2_name, arg2_val) 437 arg1_name, arg1_val, arg2_name, arg2_val)
424 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) \ 438 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \
425 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 439 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
426 category, name, id, TRACE_EVENT_FLAG_COPY) 440 category_group, name, id, TRACE_EVENT_FLAG_COPY)
427 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \ 441 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
442 arg1_val) \
428 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 443 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
429 category, name, id, TRACE_EVENT_FLAG_COPY, \ 444 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
430 arg1_name, arg1_val) 445 arg1_name, arg1_val)
431 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \ 446 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
432 arg2_name, arg2_val) \ 447 arg1_val, arg2_name, arg2_val) \
433 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ 448 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
434 category, name, id, TRACE_EVENT_FLAG_COPY, \ 449 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
435 arg1_name, arg1_val, arg2_name, arg2_val) 450 arg1_name, arg1_val, arg2_name, arg2_val)
436 451
437 // Records a single ASYNC_STEP event for |step| immediately. If the category 452 // Records a single ASYNC_STEP event for |step| immediately. If the category
438 // is not enabled, then this does nothing. The |name| and |id| must match the 453 // is not enabled, then this does nothing. The |name| and |id| must match the
439 // ASYNC_BEGIN event above. The |step| param identifies this step within the 454 // ASYNC_BEGIN event above. The |step| param identifies this step within the
440 // async event. This should be called at the beginning of the next phase of an 455 // async event. This should be called at the beginning of the next phase of an
441 // asynchronous operation. 456 // asynchronous operation.
442 #define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) \ 457 #define TRACE_EVENT_ASYNC_STEP0(category_group, name, id, step) \
443 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \ 458 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \
444 category, name, id, TRACE_EVENT_FLAG_NONE, "step", step) 459 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step)
445 #define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, \ 460 #define TRACE_EVENT_ASYNC_STEP1(category_group, name, id, step, \
446 arg1_name, arg1_val) \ 461 arg1_name, arg1_val) \
447 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \ 462 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \
448 category, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ 463 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \
449 arg1_name, arg1_val) 464 arg1_name, arg1_val)
450 #define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) \ 465 #define TRACE_EVENT_COPY_ASYNC_STEP0(category_group, name, id, step) \
451 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \ 466 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \
452 category, name, id, TRACE_EVENT_FLAG_COPY, "step", step) 467 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step)
453 #define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, \ 468 #define TRACE_EVENT_COPY_ASYNC_STEP1(category_group, name, id, step, \
454 arg1_name, arg1_val) \ 469 arg1_name, arg1_val) \
455 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \ 470 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, \
456 category, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ 471 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \
457 arg1_name, arg1_val) 472 arg1_name, arg1_val)
458 473
459 // Records a single ASYNC_END event for "name" immediately. If the category 474 // Records a single ASYNC_END event for "name" immediately. If the category
460 // is not enabled, then this does nothing. 475 // is not enabled, then this does nothing.
461 #define TRACE_EVENT_ASYNC_END0(category, name, id) \ 476 #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \
462 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 477 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
463 category, name, id, TRACE_EVENT_FLAG_NONE) 478 category_group, name, id, TRACE_EVENT_FLAG_NONE)
464 #define TRACE_EVENT_ASYNC_END1(category, name, id, arg1_name, arg1_val) \ 479 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
465 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 480 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
466 category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 481 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
467 #define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, \ 482 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
468 arg2_name, arg2_val) \ 483 arg2_name, arg2_val) \
469 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 484 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
470 category, name, id, TRACE_EVENT_FLAG_NONE, \ 485 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
471 arg1_name, arg1_val, arg2_name, arg2_val) 486 arg1_name, arg1_val, arg2_name, arg2_val)
472 #define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) \ 487 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \
473 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 488 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
474 category, name, id, TRACE_EVENT_FLAG_COPY) 489 category_group, name, id, TRACE_EVENT_FLAG_COPY)
475 #define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \ 490 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
491 arg1_val) \
476 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 492 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
477 category, name, id, TRACE_EVENT_FLAG_COPY, \ 493 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
478 arg1_name, arg1_val) 494 arg1_name, arg1_val)
479 #define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \ 495 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
480 arg2_name, arg2_val) \ 496 arg1_val, arg2_name, arg2_val) \
481 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ 497 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
482 category, name, id, TRACE_EVENT_FLAG_COPY, \ 498 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
483 arg1_name, arg1_val, arg2_name, arg2_val) 499 arg1_name, arg1_val, arg2_name, arg2_val)
484 500
485 501
486 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2 502 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
487 // associated arguments. If the category is not enabled, then this 503 // associated arguments. If the category is not enabled, then this
488 // does nothing. 504 // does nothing.
489 // - category and name strings must have application lifetime (statics or 505 // - category and name strings must have application lifetime (statics or
490 // literals). They may not include " chars. 506 // literals). They may not include " chars.
491 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW 507 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
492 // events are considered to match if their category, name and id values all 508 // events are considered to match if their category_group, name and id values
493 // match. |id| must either be a pointer or an integer value up to 64 bits. If 509 // all match. |id| must either be a pointer or an integer value up to 64 bits.
494 // it's a pointer, the bits will be xored with a hash of the process ID so 510 // If it's a pointer, the bits will be xored with a hash of the process ID so
495 // that the same pointer on two different processes will not collide. 511 // that the same pointer on two different processes will not collide.
496 // FLOW events are different from ASYNC events in how they are drawn by the 512 // FLOW events are different from ASYNC events in how they are drawn by the
497 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task 513 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task
498 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be 514 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
499 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar 515 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
500 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined 516 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
501 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP 517 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
502 // macros. When the operation completes, call FLOW_END. An async operation can 518 // macros. When the operation completes, call FLOW_END. An async operation can
503 // span threads and processes, but all events in that operation must use the 519 // span threads and processes, but all events in that operation must use the
504 // same |name| and |id|. Each event can have its own args. 520 // same |name| and |id|. Each event can have its own args.
505 #define TRACE_EVENT_FLOW_BEGIN0(category, name, id) \ 521 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \
506 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 522 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
507 category, name, id, TRACE_EVENT_FLAG_NONE) 523 category_group, name, id, TRACE_EVENT_FLAG_NONE)
508 #define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ 524 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
509 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 525 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
510 category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 526 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
511 #define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ 527 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
512 arg2_name, arg2_val) \ 528 arg2_name, arg2_val) \
513 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 529 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
514 category, name, id, TRACE_EVENT_FLAG_NONE, \ 530 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
515 arg1_name, arg1_val, arg2_name, arg2_val) 531 arg1_name, arg1_val, arg2_name, arg2_val)
516 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) \ 532 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \
517 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 533 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
518 category, name, id, TRACE_EVENT_FLAG_COPY) 534 category_group, name, id, TRACE_EVENT_FLAG_COPY)
519 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ 535 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
536 arg1_val) \
520 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 537 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
521 category, name, id, TRACE_EVENT_FLAG_COPY, \ 538 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
522 arg1_name, arg1_val) 539 arg1_name, arg1_val)
523 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ 540 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
524 arg2_name, arg2_val) \ 541 arg1_val, arg2_name, arg2_val) \
525 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ 542 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
526 category, name, id, TRACE_EVENT_FLAG_COPY, \ 543 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
527 arg1_name, arg1_val, arg2_name, arg2_val) 544 arg1_name, arg1_val, arg2_name, arg2_val)
528 545
529 // Records a single FLOW_STEP event for |step| immediately. If the category 546 // Records a single FLOW_STEP event for |step| immediately. If the category
530 // is not enabled, then this does nothing. The |name| and |id| must match the 547 // is not enabled, then this does nothing. The |name| and |id| must match the
531 // FLOW_BEGIN event above. The |step| param identifies this step within the 548 // FLOW_BEGIN event above. The |step| param identifies this step within the
532 // async event. This should be called at the beginning of the next phase of an 549 // async event. This should be called at the beginning of the next phase of an
533 // asynchronous operation. 550 // asynchronous operation.
534 #define TRACE_EVENT_FLOW_STEP0(category, name, id, step) \ 551 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \
535 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ 552 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
536 category, name, id, TRACE_EVENT_FLAG_NONE, "step", step) 553 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step)
537 #define TRACE_EVENT_FLOW_STEP1(category, name, id, step, \ 554 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, \
538 arg1_name, arg1_val) \ 555 arg1_name, arg1_val) \
539 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ 556 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
540 category, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ 557 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \
541 arg1_name, arg1_val) 558 arg1_name, arg1_val)
542 #define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) \ 559 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
543 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ 560 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
544 category, name, id, TRACE_EVENT_FLAG_COPY, "step", step) 561 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step)
545 #define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, \ 562 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, \
546 arg1_name, arg1_val) \ 563 arg1_name, arg1_val) \
547 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ 564 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
548 category, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ 565 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \
549 arg1_name, arg1_val) 566 arg1_name, arg1_val)
550 567
551 // Records a single FLOW_END event for "name" immediately. If the category 568 // Records a single FLOW_END event for "name" immediately. If the category
552 // is not enabled, then this does nothing. 569 // is not enabled, then this does nothing.
553 #define TRACE_EVENT_FLOW_END0(category, name, id) \ 570 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \
554 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 571 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
555 category, name, id, TRACE_EVENT_FLAG_NONE) 572 category_group, name, id, TRACE_EVENT_FLAG_NONE)
556 #define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \ 573 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \
557 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 574 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
558 category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 575 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
559 #define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \ 576 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \
560 arg2_name, arg2_val) \ 577 arg2_name, arg2_val) \
561 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 578 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
562 category, name, id, TRACE_EVENT_FLAG_NONE, \ 579 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
563 arg1_name, arg1_val, arg2_name, arg2_val) 580 arg1_name, arg1_val, arg2_name, arg2_val)
564 #define TRACE_EVENT_COPY_FLOW_END0(category, name, id) \ 581 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \
565 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 582 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
566 category, name, id, TRACE_EVENT_FLAG_COPY) 583 category_group, name, id, TRACE_EVENT_FLAG_COPY)
567 #define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \ 584 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \
585 arg1_val) \
568 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 586 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
569 category, name, id, TRACE_EVENT_FLAG_COPY, \ 587 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
570 arg1_name, arg1_val) 588 arg1_name, arg1_val)
571 #define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \ 589 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \
572 arg2_name, arg2_val) \ 590 arg1_val, arg2_name, arg2_val) \
573 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 591 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
574 category, name, id, TRACE_EVENT_FLAG_COPY, \ 592 category_group, name, id, TRACE_EVENT_FLAG_COPY, \
575 arg1_name, arg1_val, arg2_name, arg2_val) 593 arg1_name, arg1_val, arg2_name, arg2_val)
576 594
577 // Implementation detail: trace event macros create temporary variables 595 // Implementation detail: trace event macros create temporary variables
578 // to keep instrumentation overhead low. These macros give each temporary 596 // to keep instrumentation overhead low. These macros give each temporary
579 // variable a unique name based on the line number to prevent name collissions. 597 // variable a unique name based on the line number to prevent name collissions.
580 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ 598 #define INTERNAL_TRACE_EVENT_UID3(a,b) \
581 trace_event_unique_##a##b 599 trace_event_unique_##a##b
582 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ 600 #define INTERNAL_TRACE_EVENT_UID2(a,b) \
583 INTERNAL_TRACE_EVENT_UID3(a,b) 601 INTERNAL_TRACE_EVENT_UID3(a,b)
584 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ 602 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \
585 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) 603 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
586 604
587 // Implementation detail: internal macro to create static category. 605 // Implementation detail: internal macro to create static category.
588 // No barriers are needed, because this code is designed to operate safely 606 // No barriers are needed, because this code is designed to operate safely
589 // even when the unsigned char* points to garbage data (which may be the case 607 // even when the unsigned char* points to garbage data (which may be the case
590 // on processors without cache coherency). 608 // on processors without cache coherency).
591 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ 609 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
592 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 610 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
593 const unsigned char* INTERNAL_TRACE_EVENT_UID(catstatic) = \ 611 const unsigned char* INTERNAL_TRACE_EVENT_UID(catstatic) = \
594 reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD( \ 612 reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD( \
595 INTERNAL_TRACE_EVENT_UID(atomic))); \ 613 INTERNAL_TRACE_EVENT_UID(atomic))); \
596 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 614 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) { \
597 INTERNAL_TRACE_EVENT_UID(catstatic) = \ 615 INTERNAL_TRACE_EVENT_UID(catstatic) = \
598 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \ 616 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \
599 TRACE_EVENT_API_ATOMIC_STORE(INTERNAL_TRACE_EVENT_UID(atomic), \ 617 TRACE_EVENT_API_ATOMIC_STORE(INTERNAL_TRACE_EVENT_UID(atomic), \
600 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \ 618 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \
601 INTERNAL_TRACE_EVENT_UID(catstatic))); \ 619 INTERNAL_TRACE_EVENT_UID(catstatic))); \
602 } 620 }
603 621
604 // Implementation detail: internal macro to create static category and add 622 // Implementation detail: internal macro to create static category and add
605 // event if the category is enabled. 623 // event if the category is enabled.
606 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ 624 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
607 do { \ 625 do { \
608 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 626 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
609 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 627 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \
610 trace_event_internal::AddTraceEvent( \ 628 trace_event_internal::AddTraceEvent( \
611 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ 629 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \
612 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ 630 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \
613 } \ 631 } \
614 } while (0) 632 } while (0)
615 633
616 // Implementation detail: internal macro to create static category and add begin 634 // Implementation detail: internal macro to create static category and add begin
617 // event if the category is enabled. Also adds the end event when the scope 635 // event if the category is enabled. Also adds the end event when the scope
618 // ends. 636 // ends.
619 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ 637 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
620 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 638 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
621 trace_event_internal::TraceEndOnScopeClose \ 639 trace_event_internal::TraceEndOnScopeClose \
622 INTERNAL_TRACE_EVENT_UID(profileScope); \ 640 INTERNAL_TRACE_EVENT_UID(profileScope); \
623 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 641 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \
624 trace_event_internal::AddTraceEvent( \ 642 trace_event_internal::AddTraceEvent( \
625 TRACE_EVENT_PHASE_BEGIN, \ 643 TRACE_EVENT_PHASE_BEGIN, \
626 INTERNAL_TRACE_EVENT_UID(catstatic), \ 644 INTERNAL_TRACE_EVENT_UID(catstatic), \
627 name, trace_event_internal::kNoEventId, \ 645 name, trace_event_internal::kNoEventId, \
628 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 646 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
629 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ 647 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \
630 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ 648 INTERNAL_TRACE_EVENT_UID(catstatic), name); \
631 } 649 }
632 650
633 // Implementation detail: internal macro to create static category and add 651 // Implementation detail: internal macro to create static category and add
634 // event if the category is enabled. 652 // event if the category is enabled.
635 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ 653 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
636 ...) \ 654 flags, ...) \
637 do { \ 655 do { \
638 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 656 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
639 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 657 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \
640 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 658 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
641 trace_event_internal::TraceID trace_event_trace_id( \ 659 trace_event_internal::TraceID trace_event_trace_id( \
642 id, &trace_event_flags); \ 660 id, &trace_event_flags); \
643 trace_event_internal::AddTraceEvent( \ 661 trace_event_internal::AddTraceEvent( \
644 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ 662 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \
645 name, trace_event_trace_id.data(), trace_event_flags, \ 663 name, trace_event_trace_id.data(), trace_event_flags, \
646 ##__VA_ARGS__); \ 664 ##__VA_ARGS__); \
647 } \ 665 } \
648 } while (0) 666 } while (0)
649 667
650 // Implementation detail: internal macro to create static category and add 668 // Implementation detail: internal macro to create static category and add
651 // event if the category is enabled. 669 // event if the category is enabled.
652 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, category, \ 670 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \
653 name, id, thread_id, timestamp, flags, ...) \ 671 category_group, name, id, thread_id, timestamp, flags, ...) \
654 do { \ 672 do { \
655 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 673 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
656 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 674 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \
657 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 675 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
658 trace_event_internal::TraceID trace_event_trace_id( \ 676 trace_event_internal::TraceID trace_event_trace_id( \
659 id, &trace_event_flags); \ 677 id, &trace_event_flags); \
660 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ 678 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \
661 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ 679 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \
662 name, trace_event_trace_id.data(), \ 680 name, trace_event_trace_id.data(), \
663 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ 681 thread_id, base::TimeTicks::FromInternalValue(timestamp), \
664 trace_event_flags, ##__VA_ARGS__); \ 682 trace_event_flags, ##__VA_ARGS__); \
665 } \ 683 } \
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 // Used by TRACE_EVENTx macro. Do not use directly. 968 // Used by TRACE_EVENTx macro. Do not use directly.
951 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { 969 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose {
952 public: 970 public:
953 // Note: members of data_ intentionally left uninitialized. See Initialize. 971 // Note: members of data_ intentionally left uninitialized. See Initialize.
954 TraceEndOnScopeClose() : p_data_(NULL) {} 972 TraceEndOnScopeClose() : p_data_(NULL) {}
955 ~TraceEndOnScopeClose() { 973 ~TraceEndOnScopeClose() {
956 if (p_data_) 974 if (p_data_)
957 AddEventIfEnabled(); 975 AddEventIfEnabled();
958 } 976 }
959 977
960 void Initialize(const unsigned char* category_enabled, 978 void Initialize(const unsigned char* category_group_enabled,
961 const char* name) { 979 const char* name) {
962 data_.category_enabled = category_enabled; 980 data_.category_group_enabled = category_group_enabled;
963 data_.name = name; 981 data_.name = name;
964 p_data_ = &data_; 982 p_data_ = &data_;
965 } 983 }
966 984
967 private: 985 private:
968 // Add the end event if the category is still enabled. 986 // Add the end event if the category is still enabled.
969 void AddEventIfEnabled() { 987 void AddEventIfEnabled() {
970 // Only called when p_data_ is non-null. 988 // Only called when p_data_ is non-null.
971 if (*p_data_->category_enabled) { 989 if (*p_data_->category_group_enabled) {
972 TRACE_EVENT_API_ADD_TRACE_EVENT( 990 TRACE_EVENT_API_ADD_TRACE_EVENT(
973 TRACE_EVENT_PHASE_END, 991 TRACE_EVENT_PHASE_END,
974 p_data_->category_enabled, 992 p_data_->category_group_enabled,
975 p_data_->name, kNoEventId, 993 p_data_->name, kNoEventId,
976 kZeroNumArgs, NULL, NULL, NULL, 994 kZeroNumArgs, NULL, NULL, NULL,
977 TRACE_EVENT_FLAG_NONE); 995 TRACE_EVENT_FLAG_NONE);
978 } 996 }
979 } 997 }
980 998
981 // This Data struct workaround is to avoid initializing all the members 999 // This Data struct workaround is to avoid initializing all the members
982 // in Data during construction of this object, since this object is always 1000 // in Data during construction of this object, since this object is always
983 // constructed, even when tracing is disabled. If the members of Data were 1001 // constructed, even when tracing is disabled. If the members of Data were
984 // members of this class instead, compiler warnings occur about potential 1002 // members of this class instead, compiler warnings occur about potential
985 // uninitialized accesses. 1003 // uninitialized accesses.
986 struct Data { 1004 struct Data {
987 const unsigned char* category_enabled; 1005 const unsigned char* category_group_enabled;
988 const char* name; 1006 const char* name;
989 }; 1007 };
990 Data* p_data_; 1008 Data* p_data_;
991 Data data_; 1009 Data data_;
992 }; 1010 };
993 1011
994 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. 1012 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
995 class TRACE_EVENT_API_CLASS_EXPORT ScopedTrace { 1013 class TRACE_EVENT_API_CLASS_EXPORT ScopedTrace {
996 public: 1014 public:
997 ScopedTrace(TRACE_EVENT_API_ATOMIC_WORD* event_uid, const char* name); 1015 ScopedTrace(TRACE_EVENT_API_ATOMIC_WORD* event_uid, const char* name);
998 ~ScopedTrace(); 1016 ~ScopedTrace();
999 1017
1000 private: 1018 private:
1001 const unsigned char* category_enabled_; 1019 const unsigned char* category_enabled_;
1002 const char* name_; 1020 const char* name_;
1003 }; 1021 };
1004 1022
1005 // A support macro for TRACE_EVENT_BINARY_EFFICIENTx 1023 // A support macro for TRACE_EVENT_BINARY_EFFICIENTx
1006 #define INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED( \ 1024 #define INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED( \
1007 category, name, ...) \ 1025 category_group, name, ...) \
1008 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 1026 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
1009 trace_event_internal::ScopedTrace \ 1027 trace_event_internal::ScopedTrace \
1010 INTERNAL_TRACE_EVENT_UID(profileScope)( \ 1028 INTERNAL_TRACE_EVENT_UID(profileScope)( \
1011 &INTERNAL_TRACE_EVENT_UID(atomic), name); \ 1029 &INTERNAL_TRACE_EVENT_UID(atomic), name); \
1012 1030
1013 // This macro generates less code then TRACE_EVENT0 but is also 1031 // This macro generates less code then TRACE_EVENT0 but is also
1014 // slower to execute when tracing is off. It should generally only be 1032 // slower to execute when tracing is off. It should generally only be
1015 // used with code that is seldom executed or conditionally executed 1033 // used with code that is seldom executed or conditionally executed
1016 // when debugging. 1034 // when debugging.
1017 #define TRACE_EVENT_BINARY_EFFICIENT0(category, name) \ 1035 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \
1018 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category, name) 1036 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name)
1019 1037
1020 } // namespace trace_event_internal 1038 } // namespace trace_event_internal
1021 1039
1022 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ 1040 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698