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