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 // Check that nobody includes this file directly.  Clients are supposed to
193 // include the surrounding "trace_event.h" of their project instead.
194 #if defined(TRACE_EVENT0)
195 #error "Another copy of this file has already been included."
196 #endif
197 
198 // This will mark the trace event as disabled by default. The user will need
199 // to explicitly enable the event.
200 #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
201 
202 // Records a pair of begin and end events called "name" for the current
203 // scope, with 0, 1 or 2 associated arguments. If the category is not
204 // enabled, then this does nothing.
205 // - category and name strings must have application lifetime (statics or
206 //   literals). They may not include " chars.
207 #define TRACE_EVENT0(category_group, name)    \
208   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
209 #define TRACE_EVENT_WITH_FLOW0(category_group, name, bind_id, flow_flags)  \
210   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
211                                             flow_flags)
212 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
213   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
214 #define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_flags,  \
215                                arg1_name, arg1_val)                        \
216   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
217                                             flow_flags, arg1_name, arg1_val)
218 #define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name,   \
219                      arg2_val)                                               \
220   INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, \
221                                   arg2_name, arg2_val)
222 #define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_flags,    \
223                                arg1_name, arg1_val, arg2_name, arg2_val)     \
224   INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id,   \
225                                             flow_flags, arg1_name, arg1_val, \
226                                             arg2_name, arg2_val)
227 
228 // Records a single event called "name" immediately, with 0, 1 or 2
229 // associated arguments. If the category is not enabled, then this
230 // does nothing.
231 // - category and name strings must have application lifetime (statics or
232 //   literals). They may not include " chars.
233 #define TRACE_EVENT_INSTANT0(category_group, name, scope)                   \
234   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
235                            TRACE_EVENT_FLAG_NONE | scope)
236 #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
237   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
238                            TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val)
239 #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
240                              arg2_name, arg2_val)                              \
241   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
242                            TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val, \
243                            arg2_name, arg2_val)
244 #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope)              \
245   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
246                            TRACE_EVENT_FLAG_COPY | scope)
247 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, arg1_name,   \
248                                   arg1_val)                                 \
249   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
250                            TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val)
251 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, arg1_name,      \
252                                   arg1_val, arg2_name, arg2_val)               \
253   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
254                            TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val, \
255                            arg2_name, arg2_val)
256 
257 #define TRACE_EVENT_INSTANT_WITH_TIMESTAMP0(category_group, name, scope, \
258                                             timestamp)                   \
259   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                               \
260       TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp,        \
261       TRACE_EVENT_FLAG_NONE | scope)
262 
263 #define TRACE_EVENT_INSTANT_WITH_TIMESTAMP1(category_group, name, scope,  \
264                                             timestamp, arg_name, arg_val) \
265   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                \
266       TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp,         \
267       TRACE_EVENT_FLAG_NONE | scope, arg_name, arg_val)
268 
269 // Records a single BEGIN 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_BEGIN(category_group, name, ...)                  \
275   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
276                            TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__)
277 #define TRACE_EVENT_BEGIN0(category_group, name)                          \
278   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
279                            TRACE_EVENT_FLAG_NONE)
280 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val)     \
281   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
282                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
283 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val,     \
284                            arg2_name, arg2_val)                           \
285   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
286                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val,    \
287                            arg2_name, arg2_val)
288 #define TRACE_EVENT_COPY_BEGIN0(category_group, name)                     \
289   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
290                            TRACE_EVENT_FLAG_COPY)
291 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
292   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name,  \
293                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
294 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
295                                 arg2_name, arg2_val)                       \
296   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name,  \
297                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val,     \
298                            arg2_name, arg2_val)
299 
300 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
301 // - |id| is used to match the _BEGIN event with the _END event.
302 //   Events are considered to match if their category_group, name and id values
303 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
304 //   If it's a pointer, the bits will be xored with a hash of the process ID so
305 //   that the same pointer on two different processes will not collide.
306 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
307                                                      thread_id, timestamp)     \
308   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
309       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id,      \
310       timestamp, TRACE_EVENT_FLAG_NONE)
311 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(                \
312     category_group, name, id, thread_id, timestamp)                       \
313   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
314       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
315       timestamp, TRACE_EVENT_FLAG_COPY)
316 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP1(                \
317     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val)  \
318   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
319       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
320       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
321 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP2(                \
322     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val,  \
323     arg2_name, arg2_val)                                                  \
324   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
325       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
326       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,   \
327       arg2_val)
328 
329 // Records a single END event for "name" immediately. If the category
330 // is not enabled, then this does nothing.
331 // - category and name strings must have application lifetime (statics or
332 //   literals). They may not include " chars.
333 #define TRACE_EVENT_END(category_group, name, ...)                      \
334   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
335                            TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__)
336 #define TRACE_EVENT_END0(category_group, name)                          \
337   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
338                            TRACE_EVENT_FLAG_NONE)
339 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val)     \
340   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
341                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
342 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, arg2_name, \
343                          arg2_val)                                             \
344   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,        \
345                            TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val,         \
346                            arg2_name, arg2_val)
347 #define TRACE_EVENT_COPY_END0(category_group, name)                     \
348   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
349                            TRACE_EVENT_FLAG_COPY)
350 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
351   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,  \
352                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
353 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
354                               arg2_name, arg2_val)                       \
355   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name,  \
356                            TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val,   \
357                            arg2_name, arg2_val)
358 
359 #define TRACE_EVENT_MARK_WITH_TIMESTAMP0(category_group, name, timestamp) \
360   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                \
361       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,            \
362       TRACE_EVENT_FLAG_NONE)
363 
364 #define TRACE_EVENT_MARK_WITH_TIMESTAMP1(category_group, name, timestamp, \
365                                          arg1_name, arg1_val)             \
366   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                \
367       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,            \
368       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
369 
370 #define TRACE_EVENT_MARK_WITH_TIMESTAMP2(                                      \
371     category_group, name, timestamp, arg1_name, arg1_val, arg2_name, arg2_val) \
372   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                     \
373       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,                 \
374       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
375 
376 #define TRACE_EVENT_COPY_MARK(category_group, name)                      \
377   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
378                            TRACE_EVENT_FLAG_COPY)
379 
380 #define TRACE_EVENT_COPY_MARK_WITH_TIMESTAMP(category_group, name, timestamp) \
381   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                    \
382       TRACE_EVENT_PHASE_MARK, category_group, name, timestamp,                \
383       TRACE_EVENT_FLAG_COPY)
384 
385 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
386 // - |id| is used to match the _BEGIN event with the _END event.
387 //   Events are considered to match if their category_group, name and id values
388 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
389 //   If it's a pointer, the bits will be xored with a hash of the process ID so
390 //   that the same pointer on two different processes will not collide.
391 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
392                                                    thread_id, timestamp)     \
393   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                        \
394       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,      \
395       timestamp, TRACE_EVENT_FLAG_NONE)
396 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0(                \
397     category_group, name, id, thread_id, timestamp)                     \
398   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
399       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
400       timestamp, TRACE_EVENT_FLAG_COPY)
401 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP1(                 \
402     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
403   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                    \
404       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,  \
405       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
406 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP2(                 \
407     category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
408     arg2_name, arg2_val)                                                 \
409   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                    \
410       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id,  \
411       timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,  \
412       arg2_val)
413 
414 // Records the value of a counter called "name" immediately. Value
415 // must be representable as a 32 bit integer.
416 // - category and name strings must have application lifetime (statics or
417 //   literals). They may not include " chars.
418 #define TRACE_COUNTER1(category_group, name, value)                         \
419   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
420                            TRACE_EVENT_FLAG_NONE, "value",                  \
421                            static_cast<int>(value))
422 #define TRACE_COPY_COUNTER1(category_group, name, value)                    \
423   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
424                            TRACE_EVENT_FLAG_COPY, "value",                  \
425                            static_cast<int>(value))
426 
427 // Records the values of a multi-parted counter called "name" immediately.
428 // The UI will treat value1 and value2 as parts of a whole, displaying their
429 // values as a stacked-bar chart.
430 // - category and name strings must have application lifetime (statics or
431 //   literals). They may not include " chars.
432 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val,       \
433                        value2_name, value2_val)                             \
434   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
435                            TRACE_EVENT_FLAG_NONE, value1_name,              \
436                            static_cast<int>(value1_val), value2_name,       \
437                            static_cast<int>(value2_val))
438 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val,  \
439                             value2_name, value2_val)                        \
440   INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
441                            TRACE_EVENT_FLAG_COPY, value1_name,              \
442                            static_cast<int>(value1_val), value2_name,       \
443                            static_cast<int>(value2_val))
444 
445 // Similar to TRACE_COUNTERx, but with a custom |timestamp| provided.
446 #define TRACE_COUNTER_WITH_TIMESTAMP1(category_group, name, timestamp, value) \
447   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                    \
448       TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp,             \
449       TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
450 
451 #define TRACE_COUNTER_WITH_TIMESTAMP2(category_group, name, timestamp,      \
452                                       value1_name, value1_val, value2_name, \
453                                       value2_val)                           \
454   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                  \
455       TRACE_EVENT_PHASE_COUNTER, category_group, name, timestamp,           \
456       TRACE_EVENT_FLAG_NONE, value1_name, static_cast<int>(value1_val),     \
457       value2_name, static_cast<int>(value2_val))
458 
459 // Records the value of a counter called "name" immediately. Value
460 // must be representable as a 32 bit integer.
461 // - category and name strings must have application lifetime (statics or
462 //   literals). They may not include " chars.
463 // - |id| is used to disambiguate counters with the same name. It must either
464 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
465 //   will be xored with a hash of the process ID so that the same pointer on
466 //   two different processes will not collide.
467 #define TRACE_COUNTER_ID1(category_group, name, id, value)                    \
468   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
469                                    name, id, TRACE_EVENT_FLAG_NONE, "value",  \
470                                    static_cast<int>(value))
471 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value)               \
472   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
473                                    name, id, TRACE_EVENT_FLAG_COPY, "value",  \
474                                    static_cast<int>(value))
475 
476 // Records the values of a multi-parted counter called "name" immediately.
477 // The UI will treat value1 and value2 as parts of a whole, displaying their
478 // values as a stacked-bar chart.
479 // - category and name strings must have application lifetime (statics or
480 //   literals). They may not include " chars.
481 // - |id| is used to disambiguate counters with the same name. It must either
482 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
483 //   will be xored with a hash of the process ID so that the same pointer on
484 //   two different processes will not collide.
485 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val,  \
486                           value2_name, value2_val)                            \
487   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
488                                    name, id, TRACE_EVENT_FLAG_NONE,           \
489                                    value1_name, static_cast<int>(value1_val), \
490                                    value2_name, static_cast<int>(value2_val))
491 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name,         \
492                                value1_val, value2_name, value2_val)           \
493   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
494                                    name, id, TRACE_EVENT_FLAG_COPY,           \
495                                    value1_name, static_cast<int>(value1_val), \
496                                    value2_name, static_cast<int>(value2_val))
497 
498 // TRACE_EVENT_SAMPLE_* events are injected by the sampling profiler.
499 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP0(category_group, name,       \
500                                                    thread_id, timestamp)       \
501   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
502       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
503       TRACE_EVENT_FLAG_NONE)
504 
505 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP1(                            \
506     category_group, name, thread_id, timestamp, arg1_name, arg1_val)           \
507   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
508       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
509       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
510 
511 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP2(category_group, name,       \
512                                                    thread_id, timestamp,       \
513                                                    arg1_name, arg1_val,        \
514                                                    arg2_name, arg2_val)        \
515   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
516       TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
517       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
518 
519 #define TRACE_EVENT_SAMPLE_WITH_ID1(category_group, name, id, arg1_name,       \
520                                     arg1_val)                                  \
521   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SAMPLE, category_group,   \
522                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
523                                    arg1_val)
524 
525 // ASYNC_STEP_* APIs should be only used by legacy code. New code should
526 // consider using NESTABLE_ASYNC_* APIs to describe substeps within an async
527 // event.
528 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
529 // associated arguments. If the category is not enabled, then this
530 // does nothing.
531 // - category and name strings must have application lifetime (statics or
532 //   literals). They may not include " chars.
533 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
534 //   events are considered to match if their category_group, name and id values
535 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
536 //   If it's a pointer, the bits will be xored with a hash of the process ID so
537 //   that the same pointer on two different processes will not collide.
538 //
539 // An asynchronous operation can consist of multiple phases. The first phase is
540 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
541 // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will
542 // annotate the block following the call. The ASYNC_STEP_PAST macro will
543 // annotate the block prior to the call. Note that any particular event must use
544 // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the
545 // operation completes, call ASYNC_END.
546 //
547 // An ASYNC trace typically occurs on a single thread (if not, they will only be
548 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
549 // operation must use the same |name| and |id|. Each step can have its own
550 // args.
551 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id)        \
552   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
553                                    category_group, name, id,      \
554                                    TRACE_EVENT_FLAG_NONE)
555 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
556                                  arg1_val)                            \
557   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,     \
558                                    category_group, name, id,          \
559                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
560 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
561                                  arg1_val, arg2_name, arg2_val)       \
562   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
563       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,        \
564       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
565 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id)   \
566   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
567                                    category_group, name, id,      \
568                                    TRACE_EVENT_FLAG_COPY)
569 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
570                                       arg1_val)                            \
571   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,          \
572                                    category_group, name, id,               \
573                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
574 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
575                                       arg1_val, arg2_name, arg2_val)       \
576   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                        \
577       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,             \
578       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
579 
580 // Similar to TRACE_EVENT_ASYNC_BEGINx but with a custom |at| timestamp
581 // provided.
582 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
583                                                 timestamp)                \
584   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
585       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,            \
586       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
587 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1(                           \
588     category_group, name, id, timestamp, arg1_name, arg1_val)              \
589   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                      \
590       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,             \
591       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
592       arg1_name, arg1_val)
593 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP2(category_group, name, id,      \
594                                                 timestamp, arg1_name,          \
595                                                 arg1_val, arg2_name, arg2_val) \
596   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
597       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,                 \
598       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,     \
599       arg1_name, arg1_val, arg2_name, arg2_val)
600 #define TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
601                                                      timestamp)                \
602   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
603       TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id,                 \
604       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
605 
606 // Records a single ASYNC_STEP_INTO event for |step| immediately. If the
607 // category is not enabled, then this does nothing. The |name| and |id| must
608 // match the ASYNC_BEGIN event above. The |step| param identifies this step
609 // within the async event. This should be called at the beginning of the next
610 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
611 // ASYNC_STEP_PAST events.
612 #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step)  \
613   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
614                                    category_group, name, id,          \
615                                    TRACE_EVENT_FLAG_NONE, "step", step)
616 #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \
617                                      arg1_name, arg1_val)            \
618   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
619       TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id,   \
620       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
621 
622 // Similar to TRACE_EVENT_ASYNC_STEP_INTOx but with a custom |at| timestamp
623 // provided.
624 #define TRACE_EVENT_ASYNC_STEP_INTO_WITH_TIMESTAMP0(category_group, name, id, \
625                                                     step, timestamp)          \
626   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
627       TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id,            \
628       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
629       "step", step)
630 
631 // Records a single ASYNC_STEP_PAST event for |step| immediately. If the
632 // category is not enabled, then this does nothing. The |name| and |id| must
633 // match the ASYNC_BEGIN event above. The |step| param identifies this step
634 // within the async event. This should be called at the beginning of the next
635 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
636 // ASYNC_STEP_INTO events.
637 #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step)  \
638   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
639                                    category_group, name, id,          \
640                                    TRACE_EVENT_FLAG_NONE, "step", step)
641 #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \
642                                      arg1_name, arg1_val)            \
643   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
644       TRACE_EVENT_PHASE_ASYNC_STEP_PAST, category_group, name, id,   \
645       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
646 
647 // Records a single ASYNC_END event for "name" immediately. If the category
648 // is not enabled, then this does nothing.
649 #define TRACE_EVENT_ASYNC_END0(category_group, name, id)        \
650   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
651                                    category_group, name, id,    \
652                                    TRACE_EVENT_FLAG_NONE)
653 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
654   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,               \
655                                    category_group, name, id,                  \
656                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
657 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
658                                arg2_name, arg2_val)                           \
659   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                           \
660       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
661       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
662 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id)   \
663   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
664                                    category_group, name, id,    \
665                                    TRACE_EVENT_FLAG_COPY)
666 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
667                                     arg1_val)                            \
668   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,          \
669                                    category_group, name, id,             \
670                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
671 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
672                                     arg1_val, arg2_name, arg2_val)       \
673   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                      \
674       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,             \
675       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
676 
677 // Similar to TRACE_EVENT_ASYNC_ENDx but with a custom |at| timestamp provided.
678 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(category_group, name, id, \
679                                               timestamp)                \
680   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
681       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,            \
682       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
683 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP1(category_group, name, id,       \
684                                               timestamp, arg1_name, arg1_val) \
685   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
686       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
687       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
688       arg1_name, arg1_val)
689 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP2(category_group, name, id,       \
690                                               timestamp, arg1_name, arg1_val, \
691                                               arg2_name, arg2_val)            \
692   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                         \
693       TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id,                  \
694       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE,    \
695       arg1_name, arg1_val, arg2_name, arg2_val)
696 
697 // NESTABLE_ASYNC_* APIs are used to describe an async operation, which can
698 // be nested within a NESTABLE_ASYNC event and/or have inner NESTABLE_ASYNC
699 // events.
700 // - category and name strings must have application lifetime (statics or
701 //   literals). They may not include " chars.
702 // - A pair of NESTABLE_ASYNC_BEGIN event and NESTABLE_ASYNC_END event is
703 //   considered as a match if their category_group, name and id all match.
704 // - |id| must either be a pointer or an integer value up to 64 bits.
705 //   If it's a pointer, the bits will be xored with a hash of the process ID so
706 //   that the same pointer on two different processes will not collide.
707 // - |id| is used to match a child NESTABLE_ASYNC event with its parent
708 //   NESTABLE_ASYNC event. Therefore, events in the same nested event tree must
709 //   be logged using the same id and category_group.
710 //
711 // Unmatched NESTABLE_ASYNC_END event will be parsed as an event that starts
712 // at the first NESTABLE_ASYNC event of that id, and unmatched
713 // NESTABLE_ASYNC_BEGIN event will be parsed as an event that ends at the last
714 // NESTABLE_ASYNC event of that id. Corresponding warning messages for
715 // unmatched events will be shown in the analysis view.
716 
717 // Records a single NESTABLE_ASYNC_BEGIN event called "name" immediately, with
718 // 0, 1 or 2 associated arguments. If the category is not enabled, then this
719 // does nothing.
720 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_group, name, id)        \
721   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
722                                    category_group, name, id,               \
723                                    TRACE_EVENT_FLAG_NONE)
724 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
725                                           arg1_val)                            \
726   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN,     \
727                                    category_group, name, id,                   \
728                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
729 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
730                                           arg1_val, arg2_name, arg2_val)       \
731   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
732       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
733       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
734 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0
735 // or 2 associated arguments. If the category is not enabled, then this does
736 // nothing.
737 #define TRACE_EVENT_NESTABLE_ASYNC_END0(category_group, name, id)        \
738   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
739                                    category_group, name, id,             \
740                                    TRACE_EVENT_FLAG_NONE)
741 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 1
742 // associated argument. If the category is not enabled, then this does nothing.
743 #define TRACE_EVENT_NESTABLE_ASYNC_END1(category_group, name, id, arg1_name, \
744                                         arg1_val)                            \
745   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END,     \
746                                    category_group, name, id,                 \
747                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
748 #define TRACE_EVENT_NESTABLE_ASYNC_END2(category_group, name, id, arg1_name, \
749                                         arg1_val, arg2_name, arg2_val)       \
750   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                          \
751       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,        \
752       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
753 
754 // Records a single NESTABLE_ASYNC_INSTANT event called "name" immediately,
755 // with none, one or two associated argument. If the category is not enabled,
756 // then this does nothing.
757 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT0(category_group, name, id)        \
758   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
759                                    category_group, name, id,                 \
760                                    TRACE_EVENT_FLAG_NONE)
761 
762 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(category_group, name, id,        \
763                                             arg1_name, arg1_val)             \
764   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
765                                    category_group, name, id,                 \
766                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
767 
768 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT2(                              \
769     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)   \
770   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
771       TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
772       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
773 
774 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TTS2(                       \
775     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)        \
776   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
777       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
778       TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
779       arg2_name, arg2_val)
780 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TTS2(                         \
781     category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val)        \
782   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
783       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,          \
784       TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
785       arg2_name, arg2_val)
786 
787 // Similar to TRACE_EVENT_NESTABLE_ASYNC_{BEGIN,END}x but with a custom
788 // |timestamp| provided.
789 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, \
790                                                          id, timestamp)        \
791   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
792       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id,        \
793       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
794 #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(category_group, name, \
795                                                        id, timestamp)        \
796   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                        \
797       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,        \
798       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
799 #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP1(                    \
800     category_group, name, id, timestamp, arg1_name, arg1_val)              \
801   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                      \
802       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id,      \
803       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
804       arg1_name, arg1_val)
805 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT_WITH_TIMESTAMP0(               \
806     category_group, name, id, timestamp)                                  \
807   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                     \
808       TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
809       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
810 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(          \
811     category_group, name, id, timestamp)                                \
812   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                   \
813       TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
814       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
815 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(          \
816     category_group, name, id, timestamp)                              \
817   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                 \
818       TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
819       TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
820 
821 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
822 // associated arguments. If the category is not enabled, then this
823 // does nothing.
824 // - category and name strings must have application lifetime (statics or
825 //   literals). They may not include " chars.
826 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
827 //   events are considered to match if their category_group, name and id values
828 //   all match. |id| must either be a pointer or an integer value up to 64 bits.
829 //   If it's a pointer, the bits will be xored with a hash of the process ID so
830 //   that the same pointer on two different processes will not collide.
831 // FLOW events are different from ASYNC events in how they are drawn by the
832 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task
833 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
834 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
835 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
836 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
837 // macros. When the operation completes, call FLOW_END. An async operation can
838 // span threads and processes, but all events in that operation must use the
839 // same |name| and |id|. Each event can have its own args.
840 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id)        \
841   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
842                                    category_group, name, id,     \
843                                    TRACE_EVENT_FLAG_NONE)
844 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
845   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN,               \
846                                    category_group, name, id,                   \
847                                    TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
848 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
849                                 arg2_name, arg2_val)                           \
850   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
851       TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id,                  \
852       TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
853 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id)   \
854   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
855                                    category_group, name, id,     \
856                                    TRACE_EVENT_FLAG_COPY)
857 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
858                                      arg1_val)                            \
859   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN,          \
860                                    category_group, name, id,              \
861                                    TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
862 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
863                                      arg1_val, arg2_name, arg2_val)       \
864   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
865       TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id,             \
866       TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
867 
868 // Records a single FLOW_STEP event for |step| immediately. If the category
869 // is not enabled, then this does nothing. The |name| and |id| must match the
870 // FLOW_BEGIN event above. The |step| param identifies this step within the
871 // async event. This should be called at the beginning of the next phase of an
872 // asynchronous operation.
873 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step)  \
874   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
875                                    category_group, name, id,    \
876                                    TRACE_EVENT_FLAG_NONE, "step", step)
877 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, arg1_name, \
878                                arg1_val)                                  \
879   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                       \
880       TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id,              \
881       TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
882 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
883   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP,     \
884                                    category_group, name, id,        \
885                                    TRACE_EVENT_FLAG_COPY, "step", step)
886 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, arg1_name, \
887                                     arg1_val)                                  \
888   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                            \
889       TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id,                   \
890       TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val)
891 
892 // Records a single FLOW_END event for "name" immediately. If the category
893 // is not enabled, then this does nothing.
894 #define TRACE_EVENT_FLOW_END0(category_group, name, id)                        \
895   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
896                                    name, id, TRACE_EVENT_FLAG_NONE)
897 #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id)      \
898   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
899                                    name, id,                                   \
900                                    TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
901 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val)   \
902   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
903                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
904                                    arg1_val)
905 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val,   \
906                               arg2_name, arg2_val)                             \
907   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
908                                    name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
909                                    arg1_val, arg2_name, arg2_val)
910 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id)                   \
911   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
912                                    name, id, TRACE_EVENT_FLAG_COPY)
913 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name,        \
914                                    arg1_val)                                   \
915   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
916                                    name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
917                                    arg1_val)
918 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name,        \
919                                    arg1_val, arg2_name, arg2_val)              \
920   INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
921                                    name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
922                                    arg1_val, arg2_name, arg2_val)
923 
924 // Special trace event macro to trace task execution with the location where it
925 // was posted from.
926 #define TRACE_TASK_EXECUTION(run_function, task) \
927   INTERNAL_TRACE_TASK_EXECUTION(run_function, task)
928 
929 // TRACE_EVENT_METADATA* events are information related to other
930 // injected events, not events in their own right.
931 #define TRACE_EVENT_METADATA1(category_group, name, arg1_name, arg1_val) \
932   INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, arg1_name, arg1_val)
933 
934 // Records a clock sync event.
935 #define TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id)                               \
936   INTERNAL_TRACE_EVENT_ADD(                                                    \
937       TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync",                \
938       TRACE_EVENT_FLAG_NONE, "sync_id", sync_id)
939 #define TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts)         \
940   INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(                                     \
941       TRACE_EVENT_PHASE_CLOCK_SYNC, "__metadata", "clock_sync",                \
942       issue_end_ts, TRACE_EVENT_FLAG_NONE,                                     \
943       "sync_id", sync_id, "issue_ts", issue_ts)
944 
945 // Macros to track the life time and value of arbitrary client objects.
946 // See also TraceTrackableObject.
947 #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
948   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
949       TRACE_EVENT_PHASE_CREATE_OBJECT, category_group, name, id,     \
950       TRACE_EVENT_FLAG_NONE)
951 
952 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, \
953                                             snapshot)                 \
954   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
955       TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name,        \
956       id, TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
957 
958 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID_AND_TIMESTAMP(                     \
959     category_group, name, id, timestamp, snapshot)                             \
960   INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(                          \
961       TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name,                 \
962       id, TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
963       "snapshot", snapshot)
964 
965 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
966   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
967       TRACE_EVENT_PHASE_DELETE_OBJECT, category_group, name, id,     \
968       TRACE_EVENT_FLAG_NONE)
969 
970 // Records entering and leaving trace event contexts. |category_group| and
971 // |name| specify the context category and type. |context| is a
972 // snapshotted context object id.
973 #define TRACE_EVENT_ENTER_CONTEXT(category_group, name, context)      \
974   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
975       TRACE_EVENT_PHASE_ENTER_CONTEXT, category_group, name, context, \
976       TRACE_EVENT_FLAG_NONE)
977 #define TRACE_EVENT_LEAVE_CONTEXT(category_group, name, context)      \
978   INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
979       TRACE_EVENT_PHASE_LEAVE_CONTEXT, category_group, name, context, \
980       TRACE_EVENT_FLAG_NONE)
981 #define TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
982   INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context)
983 
984 // Macro to specify that two trace IDs are identical. For example,
985 // TRACE_LINK_IDS(
986 //     "category", "name",
987 //     TRACE_ID_WITH_SCOPE("net::URLRequest", 0x1000),
988 //     TRACE_ID_WITH_SCOPE("blink::ResourceFetcher::FetchRequest", 0x2000))
989 // tells the trace consumer that events with ID ("net::URLRequest", 0x1000) from
990 // the current process have the same ID as events with ID
991 // ("blink::ResourceFetcher::FetchRequest", 0x2000).
992 #define TRACE_LINK_IDS(category_group, name, id, linked_id) \
993   INTERNAL_TRACE_EVENT_ADD_LINK_IDS(category_group, name, id, linked_id);
994 
995 // Macro to efficiently determine if a given category group is enabled.
996 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)             \
997   do {                                                                      \
998     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                 \
999     if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1000       *ret = true;                                                          \
1001     } else {                                                                \
1002       *ret = false;                                                         \
1003     }                                                                       \
1004   } while (0)
1005 
1006 // Macro to explicitly warm up a given category group. This could be useful in
1007 // cases where we want to initialize a category group before any trace events
1008 // for that category group is reported. For example, to have a category group
1009 // always show up in the "record categories" list for manually selecting
1010 // settings in about://tracing.
1011 #define TRACE_EVENT_WARMUP_CATEGORY(category_group) \
1012   INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group)
1013 
1014 // Macro to efficiently determine, through polling, if a new trace has begun.
1015 #define TRACE_EVENT_IS_NEW_TRACE(ret)                                      \
1016   do {                                                                     \
1017     static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0;          \
1018     int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED();   \
1019     if (num_traces_recorded != -1 &&                                       \
1020         num_traces_recorded !=                                             \
1021             INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) {               \
1022       INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = num_traces_recorded; \
1023       *ret = true;                                                         \
1024     } else {                                                               \
1025       *ret = false;                                                        \
1026     }                                                                      \
1027   } while (0)
1028 
1029 // Notes regarding the following definitions:
1030 // New values can be added and propagated to third party libraries, but existing
1031 // definitions must never be changed, because third party libraries may use old
1032 // definitions.
1033 
1034 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
1035 #define TRACE_EVENT_PHASE_BEGIN ('B')
1036 #define TRACE_EVENT_PHASE_END ('E')
1037 #define TRACE_EVENT_PHASE_COMPLETE ('X')
1038 #define TRACE_EVENT_PHASE_INSTANT ('I')
1039 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
1040 #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T')
1041 #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p')
1042 #define TRACE_EVENT_PHASE_ASYNC_END ('F')
1043 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN ('b')
1044 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_END ('e')
1045 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT ('n')
1046 #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
1047 #define TRACE_EVENT_PHASE_FLOW_STEP ('t')
1048 #define TRACE_EVENT_PHASE_FLOW_END ('f')
1049 #define TRACE_EVENT_PHASE_METADATA ('M')
1050 #define TRACE_EVENT_PHASE_COUNTER ('C')
1051 #define TRACE_EVENT_PHASE_SAMPLE ('P')
1052 #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N')
1053 #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O')
1054 #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D')
1055 #define TRACE_EVENT_PHASE_MEMORY_DUMP ('v')
1056 #define TRACE_EVENT_PHASE_MARK ('R')
1057 #define TRACE_EVENT_PHASE_CLOCK_SYNC ('c')
1058 #define TRACE_EVENT_PHASE_ENTER_CONTEXT ('(')
1059 #define TRACE_EVENT_PHASE_LEAVE_CONTEXT (')')
1060 #define TRACE_EVENT_PHASE_LINK_IDS ('=')
1061 
1062 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
1063 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
1064 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
1065 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
1066 // TODO(crbug.com/639003): Free this bit after ID mangling is deprecated.
1067 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2))
1068 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3))
1069 #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4))
1070 #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
1071 #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
1072 #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
1073 #define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
1074 #define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
1075 #define TRACE_EVENT_FLAG_HAS_CONTEXT_ID (static_cast<unsigned int>(1 << 10))
1076 #define TRACE_EVENT_FLAG_HAS_PROCESS_ID (static_cast<unsigned int>(1 << 11))
1077 #define TRACE_EVENT_FLAG_HAS_LOCAL_ID (static_cast<unsigned int>(1 << 12))
1078 #define TRACE_EVENT_FLAG_HAS_GLOBAL_ID (static_cast<unsigned int>(1 << 13))
1079 
1080 #define TRACE_EVENT_FLAG_SCOPE_MASK                          \
1081   (static_cast<unsigned int>(TRACE_EVENT_FLAG_SCOPE_OFFSET | \
1082                              TRACE_EVENT_FLAG_SCOPE_EXTRA))
1083 
1084 // Type values for identifying types in the TraceValue union.
1085 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
1086 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
1087 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
1088 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
1089 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
1090 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
1091 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
1092 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8))
1093 
1094 // Enum reflecting the scope of an INSTANT event. Must fit within
1095 // TRACE_EVENT_FLAG_SCOPE_MASK.
1096 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3))
1097 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
1098 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3))
1099 
1100 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
1101 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
1102 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
1103