1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
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
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
9 // target platform. The end result is that multiple libraries can funnel events
10 // through to a shared trace event collector.
11 
12 // IMPORTANT: To avoid conflicts, if you need to modify this file for a library,
13 // land your change in base/ first, and then copy-and-paste it.
14 
15 // Trace events are for tracking application performance and resource usage.
16 // Macros are provided to track:
17 //    Begin and end of function calls
18 //    Counters
19 //
20 // Events are issued against categories. Whereas LOG's
21 // categories are statically defined, TRACE categories are created
22 // implicitly with a string. For example:
23 //   TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent",
24 //                        TRACE_EVENT_SCOPE_THREAD)
25 //
26 // It is often the case that one trace may belong in multiple categories at the
27 // same time. The first argument to the trace can be a comma-separated list of
28 // categories, forming a category group, like:
29 //
30 // TRACE_EVENT_INSTANT0("input,views", "OnMouseOver", TRACE_EVENT_SCOPE_THREAD)
31 //
32 // We can enable/disable tracing of OnMouseOver by enabling/disabling either
33 // category.
34 //
35 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope:
36 //   TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly")
37 //   doSomethingCostly()
38 //   TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly")
39 // Note: our tools can't always determine the correct BEGIN/END pairs unless
40 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you
41 // need them to be in separate scopes.
42 //
43 // A common use case is to trace entire function scopes. This
44 // issues a trace BEGIN and END automatically:
45 //   void doSomethingCostly() {
46 //     TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly");
47 //     ...
48 //   }
49 //
50 // Additional parameters can be associated with an event:
51 //   void doSomethingCostly2(int howMuch) {
52 //     TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly",
53 //         "howMuch", howMuch);
54 //     ...
55 //   }
56 //
57 // The trace system will automatically add to this information the
58 // current process id, thread id, and a timestamp in microseconds.
59 //
60 // To trace an asynchronous procedure such as an IPC send/receive, use
61 // ASYNC_BEGIN and ASYNC_END:
62 //   [single threaded sender code]
63 //     static int send_count = 0;
64 //     ++send_count;
65 //     TRACE_EVENT_ASYNC_BEGIN0("ipc", "message", send_count);
66 //     Send(new MyMessage(send_count));
67 //   [receive code]
68 //     void OnMyMessage(send_count) {
69 //       TRACE_EVENT_ASYNC_END0("ipc", "message", send_count);
70 //     }
71 // The third parameter is a unique ID to match ASYNC_BEGIN/ASYNC_END pairs.
72 // ASYNC_BEGIN and ASYNC_END can occur on any thread of any traced process.
73 // Pointers can be used for the ID parameter, and they will be mangled
74 // internally so that the same pointer on two different processes will not
75 // match. For example:
76 //   class MyTracedClass {
77 //    public:
78 //     MyTracedClass() {
79 //       TRACE_EVENT_ASYNC_BEGIN0("category", "MyTracedClass", this);
80 //     }
81 //     ~MyTracedClass() {
82 //       TRACE_EVENT_ASYNC_END0("category", "MyTracedClass", this);
83 //     }
84 //   }
85 //
86 // Trace event also supports counters, which is a way to track a quantity
87 // as it varies over time. Counters are created with the following macro:
88 //   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue);
89 //
90 // Counters are process-specific. The macro itself can be issued from any
91 // thread, however.
92 //
93 // Sometimes, you want to track two counters at once. You can do this with two
94 // counter macros:
95 //   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]);
96 //   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]);
97 // Or you can do it with a combined macro:
98 //   TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter",
99 //       "bytesPinned", g_myCounterValue[0],
100 //       "bytesAllocated", g_myCounterValue[1]);
101 // This indicates to the tracing UI that these counters should be displayed
102 // in a single graph, as a summed area chart.
103 //
104 // Since counters are in a global namespace, you may want to disambiguate with a
105 // unique ID, by using the TRACE_COUNTER_ID* variations.
106 //
107 // By default, trace collection is compiled in, but turned off at runtime.
108 // Collecting trace data is the responsibility of the embedding
109 // application. In Chrome's case, navigating to about:tracing will turn on
110 // tracing and display data collected across all active processes.
111 //
112 //
113 // Memory scoping note:
114 // Tracing copies the pointers, not the string content, of the strings passed
115 // in for category_group, name, and arg_names.  Thus, the following code will
116 // cause problems:
117 //     char* str = strdup("importantName");
118 //     TRACE_EVENT_INSTANT0("SUBSYSTEM", str);  // BAD!
119 //     free(str);                   // Trace system now has dangling pointer
120 //
121 // To avoid this issue with the |name| and |arg_name| parameters, use the
122 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead.
123 // Notes: The category must always be in a long-lived char* (i.e. static const).
124 //        The |arg_values|, when used, are always deep copied with the _COPY
125 //        macros.
126 //
127 // When are string argument values copied:
128 // const char* arg_values are only referenced by default:
129 //     TRACE_EVENT1("category", "name",
130 //                  "arg1", "literal string is only referenced");
131 // Use TRACE_STR_COPY to force copying of a const char*:
132 //     TRACE_EVENT1("category", "name",
133 //                  "arg1", TRACE_STR_COPY("string will be copied"));
134 // std::string arg_values are always copied:
135 //     TRACE_EVENT1("category", "name",
136 //                  "arg1", std::string("string will be copied"));
137 //
138 //
139 // Convertable notes:
140 // Converting a large data type to a string can be costly. To help with this,
141 // the trace framework provides an interface ConvertableToTraceFormat. If you
142 // inherit from it and implement the AppendAsTraceFormat method the trace
143 // framework will call back to your object to convert a trace output time. This
144 // means, if the category for the event is disabled, the conversion will not
145 // happen.
146 //
147 //   class MyData : public base::trace_event::ConvertableToTraceFormat {
148 //    public:
149 //     MyData() {}
150 //     void AppendAsTraceFormat(std::string* out) const override {
151 //       out->append("{\"foo\":1}");
152 //     }
153 //    private:
154 //     ~MyData() override {}
155 //     DISALLOW_COPY_AND_ASSIGN(MyData);
156 //   };
157 //
158 //   TRACE_EVENT1("foo", "bar", "data",
159 //                std::unique_ptr<ConvertableToTraceFormat>(new MyData()));
160 //
161 // The trace framework will take ownership if the passed pointer and it will
162 // be free'd when the trace buffer is flushed.
163 //
164 // Note, we only do the conversion when the buffer is flushed, so the provided
165 // data object should not be modified after it's passed to the trace framework.
166 //
167 //
168 // Thread Safety:
169 // A thread safe singleton and mutex are used for thread safety. Category
170 // enabled flags are used to limit the performance impact when the system
171 // is not enabled.
172 //
173 // TRACE_EVENT macros first cache a pointer to a category. The categories are
174 // statically allocated and safe at all times, even after exit. Fetching a
175 // category is protected by the TraceLog::lock_. Multiple threads initializing
176 // the static variable is safe, as they will be serialized by the lock and
177 // multiple calls will return the same pointer to the category.
178 //
179 // Then the category_group_enabled flag is checked. This is a unsigned char, and
180 // not intended to be multithread safe. It optimizes access to AddTraceEvent
181 // which is threadsafe internally via TraceLog::lock_. The enabled flag may
182 // cause some threads to incorrectly call or skip calling AddTraceEvent near
183 // the time of the system being enabled or disabled. This is acceptable as
184 // we tolerate some data loss while the system is being enabled/disabled and
185 // because AddTraceEvent is threadsafe internally and checks the enabled state
186 // again under lock.
187 //
188 // Without the use of these static category pointers and enabled flags all
189 // trace points would carry a significant performance cost of acquiring a lock
190 // and resolving the category.
191 
192 #if defined(TRACE_EVENT0)
193 #error "Another copy of this file has already been included."
194 #endif
195 
196 // This will mark the trace event as disabled by default. The user will need
197 // to explicitly enable the event.
198 #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
199 
200 // Records a pair of begin and end events called "name" for the current
201 // scope, with 0, 1 or 2 associated arguments. If the category is not
202 // enabled, then this does nothing.
203 // - category and name strings must have application lifetime (statics or
204 //   literals). They may not include " chars.
205 #define TRACE_EVENT0(category_group, name)    \
206   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
207 #define TRACE_EVENT_WITH_FLOW0(category_group, name, bind_id, flow_flags)  \
208   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
209                                             flow_flags)
210 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
211   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
212 #define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_flags,  \
213                                arg1_name, arg1_val)                        \
214   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
215                                             flow_flags, arg1_name, arg1_val)
216 #define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name,   \
217                      arg2_val)                                               \
218   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, \
219                                   arg2_name, arg2_val)
220 #define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_flags,    \
221                                arg1_name, arg1_val, arg2_name, arg2_val)     \
222   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id,   \
223                                             flow_flags, arg1_name, arg1_val, \
224                                             arg2_name, arg2_val)
225 
226 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
227 // included in official builds.
228 
229 #if OFFICIAL_BUILD
230 #undef TRACING_IS_OFFICIAL_BUILD
231 #define TRACING_IS_OFFICIAL_BUILD 1
232 #elif !defined(TRACING_IS_OFFICIAL_BUILD)
233 #define TRACING_IS_OFFICIAL_BUILD 0
234 #endif
235 
236 #if TRACING_IS_OFFICIAL_BUILD
237 #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0
238 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
239   (void)0
240 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
241                                arg2_name, arg2_val)                       \
242   (void)0
243 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0
244 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, \
245                                        arg1_val)                               \
246   (void)0
247 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, \
248                                        arg1_val, arg2_name, arg2_val)          \
249   (void)0
250 #else
251 #define UNSHIPPED_TRACE_EVENT0(category_group, name) \
252   TRACE_EVENT0(category_group, name)
253 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
254   TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
255 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
256                                arg2_name, arg2_val)                       \
257   TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
258 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \
259   TRACE_EVENT_INSTANT0(category_group, name, scope)
260 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, \
261                                        arg1_val)                               \
262   TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val)
263 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, \
264                                        arg1_val, arg2_name, arg2_val)          \
265   TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val,       \
266                        arg2_name, arg2_val)
267 #endif
268 
269 // Records a single event called "name" immediately, with 0, 1 or 2
270 // associated arguments. If the category is not enabled, then this
271 // does nothing.
272 // - category and name strings must have application lifetime (statics or
273 //   literals). They may not include " chars.
274 #define TRACE_EVENT_INSTANT0(category_group, name, scope)                   \
275   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
276                            TRACE_EVENT_FLAG_NONE | scope)
277 #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
278   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
279                            TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val)
280 #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
281                              arg2_name, arg2_val)                              \
282   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
283                            TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val, \
284                            arg2_name, arg2_val)
285 #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope)              \
286   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
287                            TRACE_EVENT_FLAG_COPY | scope)
288 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, arg1_name,   \
289                                   arg1_val)                                 \
290   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
291                            TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val)
292 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, arg1_name,      \
293                                   arg1_val, arg2_name, arg2_val)               \
294   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
295                            TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val, \
296                            arg2_name, arg2_val)
297 
298 #define TRACE_EVENT_INSTANT_WITH_TIMESTAMP0(category_group, name, scope, \
299                                             timestamp)                   \
300   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                               \
301       TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp,        \
302       TRACE_EVENT_FLAG_NONE | scope)
303 
304 // Syntactic sugars for the sampling tracing in the main thread.
305 #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \
306   TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name)
307 #define TRACE_EVENT_GET_SAMPLING_STATE() \
308   TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0)
309 #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \
310   TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name)
311 #define TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(category_and_name) \
312   TRACE_EVENT_SET_NONCONST_SAMPLING_STATE_FOR_BUCKET(0, category_and_name)
313 
314 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2
315 // associated arguments. If the category is not enabled, then this
316 // does nothing.
317 // - category and name strings must have application lifetime (statics or
318 //   literals). They may not include " chars.
319 #define TRACE_EVENT_BEGIN0(category_group, name)                          \
320   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
321                            TRACE_EVENT_FLAG_NONE)
322 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val)     \
323   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
324                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
325 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val,     \
326                            arg2_name, arg2_val)                           \
327   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
328                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val,    \
329                            arg2_name, arg2_val)
330 #define TRACE_EVENT_COPY_BEGIN0(category_group, name)                     \
331   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
332                            TRACE_EVENT_FLAG_COPY)
333 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
334   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name,  \
335                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
336 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
337                                 arg2_name, arg2_val)                       \
338   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name,  \
339                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val,     \
340                            arg2_name, arg2_val)
341 
342 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
343 // - |id| is used to match the _BEGIN event with the _END event.
344 //   Events are considered to match if their category_group, name and id values
345 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
346 //   If it's a pointer, the bits will be xored with a hash of the process ID so
347 //   that the same pointer on two different processes will not collide.
348 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
349                                                      thread_id, timestamp)     \
350   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
351       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id,      \
352       timestamp, TRACE_EVENT_FLAG_NONE)
353 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(                \
354     category_group, name, id, thread_id, timestamp)                       \
355   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
356       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
357       timestamp, TRACE_EVENT_FLAG_COPY)
358 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP1(                \
359     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val)  \
360   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
361       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
362       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
363 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP2(                \
364     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val,  \
365     arg2_name, arg2_val)                                                  \
366   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
367       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
368       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,   \
369       arg2_val)
370 
371 // Records a single END event for "name" immediately. If the category
372 // is not enabled, then this does nothing.
373 // - category and name strings must have application lifetime (statics or
374 //   literals). They may not include " chars.
375 #define TRACE_EVENT_END0(category_group, name)                          \
376   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
377                            TRACE_EVENT_FLAG_NONE)
378 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val)     \
379   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
380                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
381 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, arg2_name, \
382                          arg2_val)                                             \
383   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,        \
384                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val,         \
385                            arg2_name, arg2_val)
386 #define TRACE_EVENT_COPY_END0(category_group, name)                     \
387   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
388                            TRACE_EVENT_FLAG_COPY)
389 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
390   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,  \
391                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
392 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
393                               arg2_name, arg2_val)                       \
394   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,  \
395                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val,   \
396                            arg2_name, arg2_val)
397 
398 #define TRACE_EVENT_MARK_WITH_TIMESTAMP0(category_group, name, timestamp) \
399   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                \
400       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,            \
401       TRACE_EVENT_FLAG_NONE)
402 
403 #define TRACE_EVENT_MARK_WITH_TIMESTAMP1(category_group, name, timestamp, \
404                                          arg1_name, arg1_val)             \
405   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                \
406       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,            \
407       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
408 
409 #define TRACE_EVENT_COPY_MARK(category_group, name)                      \
410   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
411                            TRACE_EVENT_FLAG_COPY)
412 
413 #define TRACE_EVENT_COPY_MARK_WITH_TIMESTAMP(category_group, name, timestamp) \
414   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                    \
415       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,                \
416       TRACE_EVENT_FLAG_COPY)
417 
418 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
419 // - |id| is used to match the _BEGIN event with the _END event.
420 //   Events are considered to match if their category_group, name and id values
421 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
422 //   If it's a pointer, the bits will be xored with a hash of the process ID so
423 //   that the same pointer on two different processes will not collide.
424 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
425                                                    thread_id, timestamp)     \
426   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                        \
427       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,      \
428       timestamp, TRACE_EVENT_FLAG_NONE)
429 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0(                \
430     category_group, name, id, thread_id, timestamp)                     \
431   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
432       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
433       timestamp, TRACE_EVENT_FLAG_COPY)
434 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP1(                 \
435     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
436   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                    \
437       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,  \
438       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
439 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP2(                 \
440     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
441     arg2_name, arg2_val)                                                 \
442   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                    \
443       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,  \
444       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,  \
445       arg2_val)
446 
447 // Records the value of a counter called "name" immediately. Value
448 // must be representable as a 32 bit integer.
449 // - category and name strings must have application lifetime (statics or
450 //   literals). They may not include " chars.
451 #define TRACE_COUNTER1(category_group, name, value)                         \
452   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
453                            TRACE_EVENT_FLAG_NONE, "value",                  \
454                            static_cast<int>(value))
455 #define TRACE_COPY_COUNTER1(category_group, name, value)                    \
456   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
457                            TRACE_EVENT_FLAG_COPY, "value",                  \
458                            static_cast<int>(value))
459 
460 // Records the values of a multi-parted counter called "name" immediately.
461 // The UI will treat value1 and value2 as parts of a whole, displaying their
462 // values as a stacked-bar chart.
463 // - category and name strings must have application lifetime (statics or
464 //   literals). They may not include " chars.
465 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val,       \
466                        value2_name, value2_val)                             \
467   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
468                            TRACE_EVENT_FLAG_NONE, value1_name,              \
469                            static_cast<int>(value1_val), value2_name,       \
470                            static_cast<int>(value2_val))
471 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val,  \
472                             value2_name, value2_val)                        \
473   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
474                            TRACE_EVENT_FLAG_COPY, value1_name,              \
475                            static_cast<int>(value1_val), value2_name,       \
476                            static_cast<int>(value2_val))
477 
478 // Similar to TRACE_COUNTERx, but with a custom |timestamp| provided.
479 #define TRACE_COUNTER_WITH_TIMESTAMP1(category_group, name, timestamp, value) \
480   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                    \
481       TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp,             \
482       TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
483 
484 #define TRACE_COUNTER_WITH_TIMESTAMP2(category_group, name, timestamp,      \
485                                       value1_name, value1_val, value2_name, \
486                                       value2_val)                           \
487   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                  \
488       TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp,           \
489       TRACE_EVENT_FLAG_NONE, value1_name, static_cast<int>(value1_val),     \
490       value2_name, static_cast<int>(value2_val))
491 
492 // Records the value of a counter called "name" immediately. Value
493 // must be representable as a 32 bit integer.
494 // - category and name strings must have application lifetime (statics or
495 //   literals). They may not include " chars.
496 // - |id| is used to disambiguate counters with the same name. It must either
497 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
498 //   will be xored with a hash of the process ID so that the same pointer on
499 //   two different processes will not collide.
500 #define TRACE_COUNTER_ID1(category_group, name, id, value)                    \
501   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
502                                    name, id, TRACE_EVENT_FLAG_NONE, "value",  \
503                                    static_cast<int>(value))
504 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value)               \
505   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
506                                    name, id, TRACE_EVENT_FLAG_COPY, "value",  \
507                                    static_cast<int>(value))
508 
509 // Records the values of a multi-parted counter called "name" immediately.
510 // The UI will treat value1 and value2 as parts of a whole, displaying their
511 // values as a stacked-bar chart.
512 // - category and name strings must have application lifetime (statics or
513 //   literals). They may not include " chars.
514 // - |id| is used to disambiguate counters with the same name. It must either
515 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
516 //   will be xored with a hash of the process ID so that the same pointer on
517 //   two different processes will not collide.
518 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val,  \
519                           value2_name, value2_val)                            \
520   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
521                                    name, id, TRACE_EVENT_FLAG_NONE,           \
522                                    value1_name, static_cast<int>(value1_val), \
523                                    value2_name, static_cast<int>(value2_val))
524 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name,         \
525                                value1_val, value2_name, value2_val)           \
526   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
527                                    name, id, TRACE_EVENT_FLAG_COPY,           \
528                                    value1_name, static_cast<int>(value1_val), \
529                                    value2_name, static_cast<int>(value2_val))
530 
531 // TRACE_EVENT_SAMPLE_* events are injected by the sampling profiler.
532 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP0(category_group, name,       \
533                                                    thread_id, timestamp)       \
534   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
535       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
536       TRACE_EVENT_FLAG_NONE)
537 
538 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP1(                            \
539     category_group, name, thread_id, timestamp, arg1_name, arg1_val)           \
540   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
541       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
542       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
543 
544 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP2(category_group, name,       \
545                                                    thread_id, timestamp,       \
546                                                    arg1_name, arg1_val,        \
547                                                    arg2_name, arg2_val)        \
548   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
549       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
550       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
551 
552 #define TRACE_EVENT_SAMPLE_WITH_ID1(category_group, name, id, arg1_name,       \
553                                     arg1_val)                                  \
554   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SAMPLE, category_group,   \
555                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
556                                    arg1_val)
557 
558 // ASYNC_STEP_* APIs should be only used by legacy code. New code should
559 // consider using NESTABLE_ASYNC_* APIs to describe substeps within an async
560 // event.
561 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
562 // associated arguments. If the category is not enabled, then this
563 // does nothing.
564 // - category and name strings must have application lifetime (statics or
565 //   literals). They may not include " chars.
566 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
567 //   events are considered to match if their category_group, name and id values
568 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
569 //   If it's a pointer, the bits will be xored with a hash of the process ID so
570 //   that the same pointer on two different processes will not collide.
571 //
572 // An asynchronous operation can consist of multiple phases. The first phase is
573 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
574 // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will
575 // annotate the block following the call. The ASYNC_STEP_PAST macro will
576 // annotate the block prior to the call. Note that any particular event must use
577 // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the
578 // operation completes, call ASYNC_END.
579 //
580 // An ASYNC trace typically occurs on a single thread (if not, they will only be
581 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
582 // operation must use the same |name| and |id|. Each step can have its own
583 // args.
584 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id)        \
585   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
586                                    category_group, name, id,      \
587                                    TRACE_EVENT_FLAG_NONE)
588 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
589                                  arg1_val)                            \
590   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,     \
591                                    category_group, name, id,          \
592                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
593 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
594                                  arg1_val, arg2_name, arg2_val)       \
595   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
596       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,        \
597       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
598 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id)   \
599   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
600                                    category_group, name, id,      \
601                                    TRACE_EVENT_FLAG_COPY)
602 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
603                                       arg1_val)                            \
604   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,          \
605                                    category_group, name, id,               \
606                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
607 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
608                                       arg1_val, arg2_name, arg2_val)       \
609   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                        \
610       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,             \
611       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
612 
613 // Similar to TRACE_EVENT_ASYNC_BEGINx but with a custom |at| timestamp
614 // provided.
615 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
616                                                 timestamp)                \
617   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
618       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,            \
619       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
620 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1(                           \
621     category_group, name, id, timestamp, arg1_name, arg1_val)              \
622   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                      \
623       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,             \
624       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
625       arg1_name, arg1_val)
626 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP2(category_group, name, id,      \
627                                                 timestamp, arg1_name,          \
628                                                 arg1_val, arg2_name, arg2_val) \
629   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
630       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,                 \
631       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,     \
632       arg1_name, arg1_val, arg2_name, arg2_val)
633 #define TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
634                                                      timestamp)                \
635   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
636       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,                 \
637       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
638 
639 // Records a single ASYNC_STEP_INTO event for |step| immediately. If the
640 // category is not enabled, then this does nothing. The |name| and |id| must
641 // match the ASYNC_BEGIN event above. The |step| param identifies this step
642 // within the async event. This should be called at the beginning of the next
643 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
644 // ASYNC_STEP_PAST events.
645 #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step)  \
646   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
647                                    category_group, name, id,          \
648                                    TRACE_EVENT_FLAG_NONE, "step", step)
649 #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \
650                                      arg1_name, arg1_val)            \
651   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
652       TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id,   \
653       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
654 
655 // Similar to TRACE_EVENT_ASYNC_STEP_INTOx but with a custom |at| timestamp
656 // provided.
657 #define TRACE_EVENT_ASYNC_STEP_INTO_WITH_TIMESTAMP0(category_group, name, id, \
658                                                     step, timestamp)          \
659   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
660       TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id,            \
661       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
662       "step", step)
663 
664 // Records a single ASYNC_STEP_PAST event for |step| immediately. If the
665 // category is not enabled, then this does nothing. The |name| and |id| must
666 // match the ASYNC_BEGIN event above. The |step| param identifies this step
667 // within the async event. This should be called at the beginning of the next
668 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
669 // ASYNC_STEP_INTO events.
670 #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step)  \
671   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
672                                    category_group, name, id,          \
673                                    TRACE_EVENT_FLAG_NONE, "step", step)
674 #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \
675                                      arg1_name, arg1_val)            \
676   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
677       TRACE_EVENT_PHASE_ASYNC_STEP_PAST, category_group, name, id,   \
678       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
679 
680 // Records a single ASYNC_END event for "name" immediately. If the category
681 // is not enabled, then this does nothing.
682 #define TRACE_EVENT_ASYNC_END0(category_group, name, id)        \
683   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
684                                    category_group, name, id,    \
685                                    TRACE_EVENT_FLAG_NONE)
686 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
687   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,               \
688                                    category_group, name, id,                  \
689                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
690 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
691                                arg2_name, arg2_val)                           \
692   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                           \
693       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
694       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
695 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id)   \
696   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
697                                    category_group, name, id,    \
698                                    TRACE_EVENT_FLAG_COPY)
699 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
700                                     arg1_val)                            \
701   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,          \
702                                    category_group, name, id,             \
703                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
704 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
705                                     arg1_val, arg2_name, arg2_val)       \
706   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                      \
707       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,             \
708       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
709 
710 // Similar to TRACE_EVENT_ASYNC_ENDx but with a custom |at| timestamp provided.
711 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(category_group, name, id, \
712                                               timestamp)                \
713   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
714       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,            \
715       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
716 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1(category_group, name, id,       \
717                                               timestamp, arg1_name, arg1_val) \
718   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
719       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
720       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
721       arg1_name, arg1_val)
722 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP2(category_group, name, id,       \
723                                               timestamp, arg1_name, arg1_val, \
724                                               arg2_name, arg2_val)            \
725   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
726       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
727       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
728       arg1_name, arg1_val, arg2_name, arg2_val)
729 
730 // NESTABLE_ASYNC_* APIs are used to describe an async operation, which can
731 // be nested within a NESTABLE_ASYNC event and/or have inner NESTABLE_ASYNC
732 // events.
733 // - category and name strings must have application lifetime (statics or
734 //   literals). They may not include " chars.
735 // - A pair of NESTABLE_ASYNC_BEGIN event and NESTABLE_ASYNC_END event is
736 //   considered as a match if their category_group, name and id all match.
737 // - |id| must either be a pointer or an integer value up to 64 bits.
738 //   If it's a pointer, the bits will be xored with a hash of the process ID so
739 //   that the same pointer on two different processes will not collide.
740 // - |id| is used to match a child NESTABLE_ASYNC event with its parent
741 //   NESTABLE_ASYNC event. Therefore, events in the same nested event tree must
742 //   be logged using the same id and category_group.
743 //
744 // Unmatched NESTABLE_ASYNC_END event will be parsed as an event that starts
745 // at the first NESTABLE_ASYNC event of that id, and unmatched
746 // NESTABLE_ASYNC_BEGIN event will be parsed as an event that ends at the last
747 // NESTABLE_ASYNC event of that id. Corresponding warning messages for
748 // unmatched events will be shown in the analysis view.
749 
750 // Records a single NESTABLE_ASYNC_BEGIN event called "name" immediately, with
751 // 0, 1 or 2 associated arguments. If the category is not enabled, then this
752 // does nothing.
753 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_group, name, id)        \
754   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
755                                    category_group, name, id,               \
756                                    TRACE_EVENT_FLAG_NONE)
757 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
758                                           arg1_val)                            \
759   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN,     \
760                                    category_group, name, id,                   \
761                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
762 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
763                                           arg1_val, arg2_name, arg2_val)       \
764   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
765       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
766       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
767 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0
768 // or 2 associated arguments. If the category is not enabled, then this does
769 // nothing.
770 #define TRACE_EVENT_NESTABLE_ASYNC_END0(category_group, name, id)        \
771   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
772                                    category_group, name, id,             \
773                                    TRACE_EVENT_FLAG_NONE)
774 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 1
775 // associated argument. If the category is not enabled, then this does nothing.
776 #define TRACE_EVENT_NESTABLE_ASYNC_END1(category_group, name, id, arg1_name, \
777                                         arg1_val)                            \
778   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END,     \
779                                    category_group, name, id,                 \
780                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
781 #define TRACE_EVENT_NESTABLE_ASYNC_END2(category_group, name, id, arg1_name, \
782                                         arg1_val, arg2_name, arg2_val)       \
783   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                          \
784       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,        \
785       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
786 
787 // Records a single NESTABLE_ASYNC_INSTANT event called "name" immediately,
788 // with none, one or two associated argument. If the category is not enabled,
789 // then this does nothing.
790 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT0(category_group, name, id)        \
791   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
792                                    category_group, name, id,                 \
793                                    TRACE_EVENT_FLAG_NONE)
794 
795 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(category_group, name, id,        \
796                                             arg1_name, arg1_val)             \
797   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
798                                    category_group, name, id,                 \
799                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
800 
801 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT2(                              \
802     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)   \
803   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
804       TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
805       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
806 
807 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TTS2(                       \
808     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)        \
809   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
810       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
811       TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
812       arg2_name, arg2_val)
813 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TTS2(                         \
814     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)        \
815   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
816       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,          \
817       TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
818       arg2_name, arg2_val)
819 
820 // Similar to TRACE_EVENT_NESTABLE_ASYNC_{BEGIN,END}x but with a custom
821 // |timestamp| provided.
822 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, \
823                                                          id, timestamp)        \
824   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
825       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
826       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
827 
828 #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(category_group, name, \
829                                                        id, timestamp)        \
830   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                        \
831       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,        \
832       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
833 
834 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(          \
835     category_group, name, id, timestamp)                                \
836   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
837       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
838       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
839 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(          \
840     category_group, name, id, timestamp)                              \
841   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                 \
842       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
843       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
844 
845 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
846 // associated arguments. If the category is not enabled, then this
847 // does nothing.
848 // - category and name strings must have application lifetime (statics or
849 //   literals). They may not include " chars.
850 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
851 //   events are considered to match if their category_group, name and id values
852 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
853 //   If it's a pointer, the bits will be xored with a hash of the process ID so
854 //   that the same pointer on two different processes will not collide.
855 // FLOW events are different from ASYNC events in how they are drawn by the
856 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task
857 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
858 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
859 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
860 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
861 // macros. When the operation completes, call FLOW_END. An async operation can
862 // span threads and processes, but all events in that operation must use the
863 // same |name| and |id|. Each event can have its own args.
864 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id)        \
865   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
866                                    category_group, name, id,     \
867                                    TRACE_EVENT_FLAG_NONE)
868 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
869   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN,               \
870                                    category_group, name, id,                   \
871                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
872 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
873                                 arg2_name, arg2_val)                           \
874   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
875       TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id,                  \
876       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
877 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id)   \
878   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
879                                    category_group, name, id,     \
880                                    TRACE_EVENT_FLAG_COPY)
881 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
882                                      arg1_val)                            \
883   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN,          \
884                                    category_group, name, id,              \
885                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
886 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
887                                      arg1_val, arg2_name, arg2_val)       \
888   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
889       TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id,             \
890       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
891 
892 // Records a single FLOW_STEP event for |step| immediately. If the category
893 // is not enabled, then this does nothing. The |name| and |id| must match the
894 // FLOW_BEGIN event above. The |step| param identifies this step within the
895 // async event. This should be called at the beginning of the next phase of an
896 // asynchronous operation.
897 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step)  \
898   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
899                                    category_group, name, id,    \
900                                    TRACE_EVENT_FLAG_NONE, "step", step)
901 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, arg1_name, \
902                                arg1_val)                                  \
903   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
904       TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id,              \
905       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
906 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
907   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP,     \
908                                    category_group, name, id,        \
909                                    TRACE_EVENT_FLAG_COPY, "step", step)
910 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, arg1_name, \
911                                     arg1_val)                                  \
912   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
913       TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id,                   \
914       TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val)
915 
916 // Records a single FLOW_END event for "name" immediately. If the category
917 // is not enabled, then this does nothing.
918 #define TRACE_EVENT_FLOW_END0(category_group, name, id)                        \
919   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
920                                    name, id, TRACE_EVENT_FLAG_NONE)
921 #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id)      \
922   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
923                                    name, id,                                   \
924                                    TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
925 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val)   \
926   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
927                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
928                                    arg1_val)
929 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val,   \
930                               arg2_name, arg2_val)                             \
931   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
932                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
933                                    arg1_val, arg2_name, arg2_val)
934 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id)                   \
935   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
936                                    name, id, TRACE_EVENT_FLAG_COPY)
937 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name,        \
938                                    arg1_val)                                   \
939   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
940                                    name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
941                                    arg1_val)
942 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name,        \
943                                    arg1_val, arg2_name, arg2_val)              \
944   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
945                                    name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
946                                    arg1_val, arg2_name, arg2_val)
947 
948 // Special trace event macro to trace task execution with the location where it
949 // was posted from.
950 #define TRACE_TASK_EXECUTION(run_function, task) \
951   INTERNAL_TRACE_TASK_EXECUTION(run_function, task)
952 
953 // TRACE_EVENT_METADATA* events are information related to other
954 // injected events, not events in their own right.
955 #define TRACE_EVENT_METADATA1(category_group, name, arg1_name, arg1_val) \
956   INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, arg1_name, arg1_val)
957 
958 // Records a clock sync event.
959 #define TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id)                               \
960   INTERNAL_TRACE_EVENT_ADD(                                                    \
961       TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync",                \
962       TRACE_EVENT_FLAG_NONE, "sync_id", sync_id)
963 #define TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts)         \
964   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                     \
965       TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync",                \
966       issue_end_ts, TRACE_EVENT_FLAG_NONE,                                     \
967       "sync_id", sync_id, "issue_ts", issue_ts)
968 
969 // Macros to track the life time and value of arbitrary client objects.
970 // See also TraceTrackableObject.
971 #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
972   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
973       TRACE_EVENT_PHASE_CREATE_OBJECT, category_group, name, id,     \
974       TRACE_EVENT_FLAG_NONE)
975 
976 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, \
977                                             snapshot)                 \
978   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
979       TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name,        \
980       id, TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
981 
982 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID_AND_TIMESTAMP(                     \
983     category_group, name, id, timestamp, snapshot)                             \
984   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
985       TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name,                 \
986       id, TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
987       "snapshot", snapshot)
988 
989 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
990   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
991       TRACE_EVENT_PHASE_DELETE_OBJECT, category_group, name, id,     \
992       TRACE_EVENT_FLAG_NONE)
993 
994 // Records entering and leaving trace event contexts. |category_group| and
995 // |name| specify the context category and type. |context| is a
996 // snapshotted context object id.
997 #define TRACE_EVENT_ENTER_CONTEXT(category_group, name, context)      \
998   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
999       TRACE_EVENT_PHASE_ENTER_CONTEXT, category_group, name, context, \
1000       TRACE_EVENT_FLAG_NONE)
1001 #define TRACE_EVENT_LEAVE_CONTEXT(category_group, name, context)      \
1002   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
1003       TRACE_EVENT_PHASE_LEAVE_CONTEXT, category_group, name, context, \
1004       TRACE_EVENT_FLAG_NONE)
1005 #define TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
1006   INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context)
1007 
1008 // Macro to specify that two trace IDs are identical. For example,
1009 // TRACE_BIND_IDS(
1010 //     "category", "name",
1011 //     TRACE_ID_WITH_SCOPE("net::URLRequest", 0x1000),
1012 //     TRACE_ID_WITH_SCOPE("blink::ResourceFetcher::FetchRequest", 0x2000))
1013 // tells the trace consumer that events with ID ("net::URLRequest", 0x1000) from
1014 // the current process have the same ID as events with ID
1015 // ("blink::ResourceFetcher::FetchRequest", 0x2000).
1016 #define TRACE_BIND_IDS(category_group, name, id, bind_id) \
1017   INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id);
1018 
1019 // Macro to efficiently determine if a given category group is enabled.
1020 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)             \
1021   do {                                                                      \
1022     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                 \
1023     if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1024       *ret = true;                                                          \
1025     } else {                                                                \
1026       *ret = false;                                                         \
1027     }                                                                       \
1028   } while (0)
1029 
1030 // Macro to explicitly warm up a given category group. This could be useful in
1031 // cases where we want to initialize a category group before any trace events
1032 // for that category group is reported. For example, to have a category group
1033 // always show up in the "record categories" list for manually selecting
1034 // settings in about://tracing.
1035 #define TRACE_EVENT_WARMUP_CATEGORY(category_group) \
1036   INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group)
1037 
1038 // Macro to efficiently determine, through polling, if a new trace has begun.
1039 #define TRACE_EVENT_IS_NEW_TRACE(ret)                                      \
1040   do {                                                                     \
1041     static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0;          \
1042     int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED();   \
1043     if (num_traces_recorded != -1 &&                                       \
1044         num_traces_recorded !=                                             \
1045             INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) {               \
1046       INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = num_traces_recorded; \
1047       *ret = true;                                                         \
1048     } else {                                                               \
1049       *ret = false;                                                        \
1050     }                                                                      \
1051   } while (0)
1052 
1053 // Notes regarding the following definitions:
1054 // New values can be added and propagated to third party libraries, but existing
1055 // definitions must never be changed, because third party libraries may use old
1056 // definitions.
1057 
1058 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
1059 #define TRACE_EVENT_PHASE_BEGIN ('B')
1060 #define TRACE_EVENT_PHASE_END ('E')
1061 #define TRACE_EVENT_PHASE_COMPLETE ('X')
1062 #define TRACE_EVENT_PHASE_INSTANT ('I')
1063 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
1064 #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T')
1065 #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p')
1066 #define TRACE_EVENT_PHASE_ASYNC_END ('F')
1067 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN ('b')
1068 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_END ('e')
1069 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT ('n')
1070 #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
1071 #define TRACE_EVENT_PHASE_FLOW_STEP ('t')
1072 #define TRACE_EVENT_PHASE_FLOW_END ('f')
1073 #define TRACE_EVENT_PHASE_METADATA ('M')
1074 #define TRACE_EVENT_PHASE_COUNTER ('C')
1075 #define TRACE_EVENT_PHASE_SAMPLE ('P')
1076 #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N')
1077 #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O')
1078 #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D')
1079 #define TRACE_EVENT_PHASE_MEMORY_DUMP ('v')
1080 #define TRACE_EVENT_PHASE_MARK ('R')
1081 #define TRACE_EVENT_PHASE_CLOCK_SYNC ('c')
1082 #define TRACE_EVENT_PHASE_ENTER_CONTEXT ('(')
1083 #define TRACE_EVENT_PHASE_LEAVE_CONTEXT (')')
1084 #define TRACE_EVENT_PHASE_BIND_IDS ('=')
1085 
1086 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
1087 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
1088 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
1089 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
1090 // TODO(crbug.com/639003): Free this bit after ID mangling is deprecated.
1091 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2))
1092 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3))
1093 #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4))
1094 #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
1095 #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
1096 #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
1097 #define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
1098 #define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
1099 #define TRACE_EVENT_FLAG_HAS_CONTEXT_ID (static_cast<unsigned int>(1 << 10))
1100 #define TRACE_EVENT_FLAG_HAS_PROCESS_ID (static_cast<unsigned int>(1 << 11))
1101 #define TRACE_EVENT_FLAG_HAS_LOCAL_ID (static_cast<unsigned int>(1 << 12))
1102 #define TRACE_EVENT_FLAG_HAS_GLOBAL_ID (static_cast<unsigned int>(1 << 13))
1103 
1104 #define TRACE_EVENT_FLAG_SCOPE_MASK                          \
1105   (static_cast<unsigned int>(TRACE_EVENT_FLAG_SCOPE_OFFSET | \
1106                              TRACE_EVENT_FLAG_SCOPE_EXTRA))
1107 
1108 // Type values for identifying types in the TraceValue union.
1109 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
1110 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
1111 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
1112 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
1113 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
1114 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
1115 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
1116 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8))
1117 
1118 // Enum reflecting the scope of an INSTANT event. Must fit within
1119 // TRACE_EVENT_FLAG_SCOPE_MASK.
1120 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3))
1121 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
1122 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3))
1123 
1124 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
1125 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
1126 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
1127