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

Side by Side Diff: third_party/WebKit/Source/platform/TraceEventCommon.h

Issue 2341333003: Use chromium trace_event implementation in blink (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 // Unlike base's trace framework, no convertable support in Blink because of
141 // the way we estimate tracing memory overhead. All objects passed to the
142 // tracing framework should be allocated by malloc to calculate overhead
143 // correctly, while many Blink objects use PartitionAlloc/Oilpan. Convertable
144 // is an interface to avoid unnecessary conversion but if we allow to use
145 // PartitionAlloc/Oilpan backed objects, overhead estimation could be wrong.
146 // For structured objects, you can use TracedValue.
147 //
148 // class MyData {
149 // public:
150 // MyData() {}
151 // std::unique_ptr<TracedValue> toTracedValue() {
152 // std::unique_ptr<TracedValue> tracedValue = TracedValue::create();
153 // tracedValue->setInteger("foo", 1);
154 // tracedValue->beginArray("bar");
155 // tracedValue->pushInteger(2);
156 // tracedValue->pushInteger(3);
157 // tracedValue->endArray();
158 // return tracedValue.release();
159 // }
160 // private:
161 // ~MyData() override {}
162 // };
163 //
164 // TRACE_EVENT1("foo", "bar", "data", myData.toTracedValue());
165 //
166 // The trace framework will take ownership.
167 //
168 //
169 // Thread Safety:
170 // A thread safe singleton and mutex are used for thread safety. Category
171 // enabled flags are used to limit the performance impact when the system
172 // is not enabled.
173 //
174 // TRACE_EVENT macros first cache a pointer to a category. The categories are
175 // statically allocated and safe at all times, even after exit. Fetching a
176 // category is protected by the TraceLog::lock_. Multiple threads initializing
177 // the static variable is safe, as they will be serialized by the lock and
178 // multiple calls will return the same pointer to the category.
179 //
180 // Then the category_group_enabled flag is checked. This is a unsigned char, and
181 // not intended to be multithread safe. It optimizes access to AddTraceEvent
182 // which is threadsafe internally via TraceLog::lock_. The enabled flag may
183 // cause some threads to incorrectly call or skip calling AddTraceEvent near
184 // the time of the system being enabled or disabled. This is acceptable as
185 // we tolerate some data loss while the system is being enabled/disabled and
186 // because AddTraceEvent is threadsafe internally and checks the enabled state
187 // again under lock.
188 //
189 // Without the use of these static category pointers and enabled flags all
190 // trace points would carry a significant performance cost of acquiring a lock
191 // and resolving the category.
192
193 #if defined(TRACE_EVENT0)
194 #error "Another copy of this file has already been included."
195 #endif
196
197 // This will mark the trace event as disabled by default. The user will need
198 // to explicitly enable the event.
199 #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
200
201 // Records a pair of begin and end events called "name" for the current
202 // scope, with 0, 1 or 2 associated arguments. If the category is not
203 // enabled, then this does nothing.
204 // - category and name strings must have application lifetime (statics or
205 // literals). They may not include " chars.
206 #define TRACE_EVENT0(category_group, name) \
207 INTERNAL_TRACE_MEMORY(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_MEMORY(category_group, name) \
211 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
212 flow_flags)
213 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
214 INTERNAL_TRACE_MEMORY(category_group, name) \
215 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
216 #define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_flags, \
217 arg1_name, arg1_val) \
218 INTERNAL_TRACE_MEMORY(category_group, name) \
219 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
220 flow_flags, arg1_name, arg1_val)
221 #define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, \
222 arg2_val) \
223 INTERNAL_TRACE_MEMORY(category_group, name) \
224 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, \
225 arg2_name, arg2_val)
226 #define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_flags, \
227 arg1_name, arg1_val, arg2_name, arg2_val) \
228 INTERNAL_TRACE_MEMORY(category_group, name) \
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 events like TRACE_EVENT2 but uses |memory_tag| for memory tracing.
234 // Use this where |name| is too generic to accurately aggregate allocations.
235 #define TRACE_EVENT_WITH_MEMORY_TAG2(category, name, memory_tag, arg1_name, \
236 arg1_val, arg2_name, arg2_val) \
237 INTERNAL_TRACE_MEMORY(category, memory_tag) \
238 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \
239 arg2_name, arg2_val)
240
241 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
242 // included in official builds.
243
244 #if OFFICIAL_BUILD
245 #undef TRACING_IS_OFFICIAL_BUILD
246 #define TRACING_IS_OFFICIAL_BUILD 1
247 #elif !defined(TRACING_IS_OFFICIAL_BUILD)
248 #define TRACING_IS_OFFICIAL_BUILD 0
249 #endif
250
251 #if TRACING_IS_OFFICIAL_BUILD
252 #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0
253 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
254 (void)0
255 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
256 arg2_name, arg2_val) \
257 (void)0
258 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0
259 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, \
260 arg1_val) \
261 (void)0
262 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, \
263 arg1_val, arg2_name, arg2_val) \
264 (void)0
265 #else
266 #define UNSHIPPED_TRACE_EVENT0(category_group, name) \
267 TRACE_EVENT0(category_group, name)
268 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
269 TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
270 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \
271 arg2_name, arg2_val) \
272 TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
273 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \
274 TRACE_EVENT_INSTANT0(category_group, name, scope)
275 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, \
276 arg1_val) \
277 TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val)
278 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, \
279 arg1_val, arg2_name, arg2_val) \
280 TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
281 arg2_name, arg2_val)
282 #endif
283
284 // Records a single event called "name" immediately, with 0, 1 or 2
285 // associated arguments. If the category is not enabled, then this
286 // does nothing.
287 // - category and name strings must have application lifetime (statics or
288 // literals). They may not include " chars.
289 #define TRACE_EVENT_INSTANT0(category_group, name, scope) \
290 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
291 TRACE_EVENT_FLAG_NONE | scope)
292 #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
293 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
294 TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val)
295 #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
296 arg2_name, arg2_val) \
297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
298 TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val, \
299 arg2_name, arg2_val)
300 #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \
301 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
302 TRACE_EVENT_FLAG_COPY | scope)
303 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, arg1_name, \
304 arg1_val) \
305 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
306 TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val)
307 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, arg1_name, \
308 arg1_val, arg2_name, arg2_val) \
309 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
310 TRACE_EVENT_FLAG_COPY | scope, arg1_name, arg1_val, \
311 arg2_name, arg2_val)
312
313 // Syntactic sugars for the sampling tracing in the main thread.
314 #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \
315 TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name)
316 #define TRACE_EVENT_GET_SAMPLING_STATE() \
317 TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0)
318 #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \
319 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name)
320 #define TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(categoryAndName) \
321 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE_FOR_BUCKET(0, categoryAndName)
322
323 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2
324 // associated arguments. If the category is not enabled, then this
325 // does nothing.
326 // - category and name strings must have application lifetime (statics or
327 // literals). They may not include " chars.
328 #define TRACE_EVENT_BEGIN0(category_group, name) \
329 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
330 TRACE_EVENT_FLAG_NONE)
331 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \
332 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
333 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
334 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \
335 arg2_name, arg2_val) \
336 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
337 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
338 arg2_name, arg2_val)
339 #define TRACE_EVENT_COPY_BEGIN0(category_group, name) \
340 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
341 TRACE_EVENT_FLAG_COPY)
342 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \
343 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
344 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
345 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \
346 arg2_name, arg2_val) \
347 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category_group, name, \
348 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
349 arg2_name, arg2_val)
350
351 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
352 // - |id| is used to match the _BEGIN event with the _END event.
353 // Events are considered to match if their category_group, name and id values
354 // all match. |id| must either be a pointer or an integer value up to 64 bits.
355 // If it's a pointer, the bits will be xored with a hash of the process ID so
356 // that the same pointer on two different processes will not collide.
357 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
358 thread_id, timestamp) \
359 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
360 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
361 timestamp, TRACE_EVENT_FLAG_NONE)
362 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
363 category_group, name, id, thread_id, timestamp) \
364 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
365 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
366 timestamp, TRACE_EVENT_FLAG_COPY)
367 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP1( \
368 category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
369 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
370 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
371 timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
372 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP2( \
373 category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
374 arg2_name, arg2_val) \
375 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
376 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \
377 timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, \
378 arg2_val)
379
380 // Records a single END event for "name" immediately. If the category
381 // is not enabled, then this does nothing.
382 // - category and name strings must have application lifetime (statics or
383 // literals). They may not include " chars.
384 #define TRACE_EVENT_END0(category_group, name) \
385 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
386 TRACE_EVENT_FLAG_NONE)
387 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \
388 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
389 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
390 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, arg2_name, \
391 arg2_val) \
392 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
393 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
394 arg2_name, arg2_val)
395 #define TRACE_EVENT_COPY_END0(category_group, name) \
396 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
397 TRACE_EVENT_FLAG_COPY)
398 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \
399 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
400 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
401 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \
402 arg2_name, arg2_val) \
403 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category_group, name, \
404 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
405 arg2_name, arg2_val)
406
407 #define TRACE_EVENT_MARK_WITH_TIMESTAMP0(category_group, name, timestamp) \
408 INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(TRACE_EVENT_PHASE_MARK, \
409 category_group, name, timestamp, \
410 TRACE_EVENT_FLAG_NONE)
411 #define TRACE_EVENT_MARK_WITH_TIMESTAMP1(category_group, name, timestamp, \
412 arg1_name, arg1_val) \
413 INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(TRACE_EVENT_PHASE_MARK, \
414 category_group, name, timestamp, \
415 TRACE_EVENT_FLAG_NONE, \
416 arg1_name, arg1_val)
417
418 #define TRACE_EVENT_COPY_MARK(category_group, name) \
419 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
420 TRACE_EVENT_FLAG_COPY)
421
422 #define TRACE_EVENT_COPY_MARK_WITH_TIMESTAMP(category_group, name, timestamp) \
423 INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(TRACE_EVENT_PHASE_MARK, \
424 category_group, name, timestamp, \
425 TRACE_EVENT_FLAG_COPY)
426
427 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
428 // - |id| is used to match the _BEGIN event with the _END event.
429 // Events are considered to match if their category_group, name and id values
430 // all match. |id| must either be a pointer or an integer value up to 64 bits.
431 // If it's a pointer, the bits will be xored with a hash of the process ID so
432 // that the same pointer on two different processes will not collide.
433 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, name, id, \
434 thread_id, timestamp) \
435 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
436 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
437 timestamp, TRACE_EVENT_FLAG_NONE)
438 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
439 category_group, name, id, thread_id, timestamp) \
440 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
441 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
442 timestamp, TRACE_EVENT_FLAG_COPY)
443 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP1( \
444 category_group, name, id, thread_id, timestamp, arg1_name, arg1_val) \
445 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
446 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
447 timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
448 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP2( \
449 category_group, name, id, thread_id, timestamp, arg1_name, arg1_val, \
450 arg2_name, arg2_val) \
451 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
452 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \
453 timestamp, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, \
454 arg2_val)
455
456 // Records the value of a counter called "name" immediately. Value
457 // must be representable as a 32 bit integer.
458 // - category and name strings must have application lifetime (statics or
459 // literals). They may not include " chars.
460 #define TRACE_COUNTER1(category_group, name, value) \
461 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
462 TRACE_EVENT_FLAG_NONE, "value", \
463 static_cast<int>(value))
464 #define TRACE_COPY_COUNTER1(category_group, name, value) \
465 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
466 TRACE_EVENT_FLAG_COPY, "value", \
467 static_cast<int>(value))
468
469 // Records the values of a multi-parted counter called "name" immediately.
470 // The UI will treat value1 and value2 as parts of a whole, displaying their
471 // values as a stacked-bar chart.
472 // - category and name strings must have application lifetime (statics or
473 // literals). They may not include " chars.
474 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \
475 value2_name, value2_val) \
476 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
477 TRACE_EVENT_FLAG_NONE, value1_name, \
478 static_cast<int>(value1_val), value2_name, \
479 static_cast<int>(value2_val))
480 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \
481 value2_name, value2_val) \
482 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
483 TRACE_EVENT_FLAG_COPY, value1_name, \
484 static_cast<int>(value1_val), value2_name, \
485 static_cast<int>(value2_val))
486
487 // Records the value of a counter called "name" immediately. Value
488 // must be representable as a 32 bit integer.
489 // - category and name strings must have application lifetime (statics or
490 // literals). They may not include " chars.
491 // - |id| is used to disambiguate counters with the same name. It must either
492 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
493 // will be xored with a hash of the process ID so that the same pointer on
494 // two different processes will not collide.
495 #define TRACE_COUNTER_ID1(category_group, name, id, value) \
496 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
497 name, id, TRACE_EVENT_FLAG_NONE, "value", \
498 static_cast<int>(value))
499 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \
500 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
501 name, id, TRACE_EVENT_FLAG_COPY, "value", \
502 static_cast<int>(value))
503
504 // Records the values of a multi-parted counter called "name" immediately.
505 // The UI will treat value1 and value2 as parts of a whole, displaying their
506 // values as a stacked-bar chart.
507 // - category and name strings must have application lifetime (statics or
508 // literals). They may not include " chars.
509 // - |id| is used to disambiguate counters with the same name. It must either
510 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
511 // will be xored with a hash of the process ID so that the same pointer on
512 // two different processes will not collide.
513 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \
514 value2_name, value2_val) \
515 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
516 name, id, TRACE_EVENT_FLAG_NONE, \
517 value1_name, static_cast<int>(value1_val), \
518 value2_name, static_cast<int>(value2_val))
519 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \
520 value1_val, value2_name, value2_val) \
521 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category_group, \
522 name, id, TRACE_EVENT_FLAG_COPY, \
523 value1_name, static_cast<int>(value1_val), \
524 value2_name, static_cast<int>(value2_val))
525
526 // TRACE_EVENT_SAMPLE_* events are injected by the sampling profiler.
527 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP0(category_group, name, \
528 thread_id, timestamp) \
529 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
530 TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
531 TRACE_EVENT_FLAG_NONE)
532
533 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP1( \
534 category_group, name, thread_id, timestamp, arg1_name, arg1_val) \
535 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
536 TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
537 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
538
539 #define TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP2(category_group, name, \
540 thread_id, timestamp, \
541 arg1_name, arg1_val, \
542 arg2_name, arg2_val) \
543 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
544 TRACE_EVENT_PHASE_SAMPLE, category_group, name, 0, thread_id, timestamp, \
545 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
546
547 // ASYNC_STEP_* APIs should be only used by legacy code. New code should
548 // consider using NESTABLE_ASYNC_* APIs to describe substeps within an async
549 // event.
550 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
551 // associated arguments. If the category is not enabled, then this
552 // does nothing.
553 // - category and name strings must have application lifetime (statics or
554 // literals). They may not include " chars.
555 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC
556 // events are considered to match if their category_group, name and id values
557 // all match. |id| must either be a pointer or an integer value up to 64 bits.
558 // If it's a pointer, the bits will be xored with a hash of the process ID so
559 // that the same pointer on two different processes will not collide.
560 //
561 // An asynchronous operation can consist of multiple phases. The first phase is
562 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the
563 // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will
564 // annotate the block following the call. The ASYNC_STEP_PAST macro will
565 // annotate the block prior to the call. Note that any particular event must use
566 // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the
567 // operation completes, call ASYNC_END.
568 //
569 // An ASYNC trace typically occurs on a single thread (if not, they will only be
570 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that
571 // operation must use the same |name| and |id|. Each step can have its own
572 // args.
573 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \
574 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
575 category_group, name, id, \
576 TRACE_EVENT_FLAG_NONE)
577 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
578 arg1_val) \
579 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
580 category_group, name, id, \
581 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
582 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
583 arg1_val, arg2_name, arg2_val) \
584 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
585 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
586 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
587 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \
588 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
589 category_group, name, id, \
590 TRACE_EVENT_FLAG_COPY)
591 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
592 arg1_val) \
593 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \
594 category_group, name, id, \
595 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
596 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
597 arg1_val, arg2_name, arg2_val) \
598 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
599 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
600 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
601
602 // Similar to TRACE_EVENT_ASYNC_BEGINx but with a custom |at| timestamp
603 // provided.
604 #define TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
605 timestamp) \
606 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
607 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
608 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
609 #define TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, id, \
610 timestamp) \
611 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
612 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, \
613 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_COPY)
614
615 // Records a single ASYNC_STEP_INTO event for |step| immediately. If the
616 // category is not enabled, then this does nothing. The |name| and |id| must
617 // match the ASYNC_BEGIN event above. The |step| param identifies this step
618 // within the async event. This should be called at the beginning of the next
619 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
620 // ASYNC_STEP_PAST events.
621 #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \
622 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \
623 category_group, name, id, \
624 TRACE_EVENT_FLAG_NONE, "step", step)
625 #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \
626 arg1_name, arg1_val) \
627 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
628 TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id, \
629 TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
630
631 // Similar to TRACE_EVENT_ASYNC_STEP_INTOx but with a custom |at| timestamp
632 // provided.
633 #define TRACE_EVENT_ASYNC_STEP_INTO_WITH_TIMESTAMP0(category_group, name, id, \
634 step, timestamp) \
635 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
636 TRACE_EVENT_PHASE_ASYNC_STEP_INTO, category_group, name, id, \
637 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
638 "step", step)
639
640 // Records a single ASYNC_STEP_PAST event for |step| immediately. If the
641 // category is not enabled, then this does nothing. The |name| and |id| must
642 // match the ASYNC_BEGIN event above. The |step| param identifies this step
643 // within the async event. This should be called at the beginning of the next
644 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any
645 // ASYNC_STEP_INTO events.
646 #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \
647 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \
648 category_group, name, id, \
649 TRACE_EVENT_FLAG_NONE, "step", step)
650 #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \
651 arg1_name, arg1_val) \
652 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
653 TRACE_EVENT_PHASE_ASYNC_STEP_PAST, category_group, name, id, \
654 TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
655
656 // Records a single ASYNC_END event for "name" immediately. If the category
657 // is not enabled, then this does nothing.
658 #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \
659 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
660 category_group, name, id, \
661 TRACE_EVENT_FLAG_NONE)
662 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \
663 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
664 category_group, name, id, \
665 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
666 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \
667 arg2_name, arg2_val) \
668 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
669 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
670 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
671 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \
672 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
673 category_group, name, id, \
674 TRACE_EVENT_FLAG_COPY)
675 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \
676 arg1_val) \
677 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \
678 category_group, name, id, \
679 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
680 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \
681 arg1_val, arg2_name, arg2_val) \
682 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
683 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
684 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
685
686 // Similar to TRACE_EVENT_ASYNC_ENDx but with a custom |at| timestamp provided.
687 #define TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(category_group, name, id, \
688 timestamp) \
689 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
690 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, \
691 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
692
693 // NESTABLE_ASYNC_* APIs are used to describe an async operation, which can
694 // be nested within a NESTABLE_ASYNC event and/or have inner NESTABLE_ASYNC
695 // events.
696 // - category and name strings must have application lifetime (statics or
697 // literals). They may not include " chars.
698 // - A pair of NESTABLE_ASYNC_BEGIN event and NESTABLE_ASYNC_END event is
699 // considered as a match if their category_group, name and id all match.
700 // - |id| must either be a pointer or an integer value up to 64 bits.
701 // If it's a pointer, the bits will be xored with a hash of the process ID so
702 // that the same pointer on two different processes will not collide.
703 // - |id| is used to match a child NESTABLE_ASYNC event with its parent
704 // NESTABLE_ASYNC event. Therefore, events in the same nested event tree must
705 // be logged using the same id and category_group.
706 //
707 // Unmatched NESTABLE_ASYNC_END event will be parsed as an event that starts
708 // at the first NESTABLE_ASYNC event of that id, and unmatched
709 // NESTABLE_ASYNC_BEGIN event will be parsed as an event that ends at the last
710 // NESTABLE_ASYNC event of that id. Corresponding warning messages for
711 // unmatched events will be shown in the analysis view.
712
713 // Records a single NESTABLE_ASYNC_BEGIN event called "name" immediately, with
714 // 0, 1 or 2 associated arguments. If the category is not enabled, then this
715 // does nothing.
716 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_group, name, id) \
717 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
718 category_group, name, id, \
719 TRACE_EVENT_FLAG_NONE)
720 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(category_group, name, id, arg1_name, \
721 arg1_val) \
722 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
723 category_group, name, id, \
724 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
725 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(category_group, name, id, arg1_name, \
726 arg1_val, arg2_name, arg2_val) \
727 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
728 TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
729 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
730 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0
731 // or 2 associated arguments. If the category is not enabled, then this does
732 // nothing.
733 #define TRACE_EVENT_NESTABLE_ASYNC_END0(category_group, name, id) \
734 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
735 category_group, name, id, \
736 TRACE_EVENT_FLAG_NONE)
737 // Records a single NESTABLE_ASYNC_END event called "name" immediately, with 1
738 // associated argument. If the category is not enabled, then this does nothing.
739 #define TRACE_EVENT_NESTABLE_ASYNC_END1(category_group, name, id, arg1_name, \
740 arg1_val) \
741 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
742 category_group, name, id, \
743 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
744 #define TRACE_EVENT_NESTABLE_ASYNC_END2(category_group, name, id, arg1_name, \
745 arg1_val, arg2_name, arg2_val) \
746 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
747 TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
748 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
749
750 // Records a single NESTABLE_ASYNC_INSTANT event called "name" immediately,
751 // with none, one or two associated argument. If the category is not enabled,
752 // then this does nothing.
753 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT0(category_group, name, id) \
754 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
755 category_group, name, id, \
756 TRACE_EVENT_FLAG_NONE)
757 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(category_group, name, id, \
758 arg1_name, arg1_val) \
759 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, \
760 category_group, name, id, \
761 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
762 #define TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( \
763 category_group, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
764 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
765 TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
766 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
767
768 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TTS2( \
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_BEGIN, category_group, name, id, \
772 TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
773 arg2_name, arg2_val)
774 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_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_END, category_group, name, id, \
778 TRACE_EVENT_FLAG_ASYNC_TTS | TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
779 arg2_name, arg2_val)
780
781 // Similar to TRACE_EVENT_NESTABLE_ASYNC_{BEGIN,END}x but with a custom
782 // |timestamp| provided.
783 #define TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(category_group, name, \
784 id, timestamp) \
785 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
786 TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
787 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
788
789 #define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(category_group, name, \
790 id, timestamp) \
791 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
792 TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
793 TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
794
795 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( \
796 category_group, name, id, timestamp) \
797 INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
798 TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
799 timestamp, TRACE_EVENT_FLAG_COPY)
800 #define TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( \
801 category_group, name, id, timestamp) \
802 INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
803 TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
804 timestamp, TRACE_EVENT_FLAG_COPY)
805
806 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2
807 // associated arguments. If the category is not enabled, then this
808 // does nothing.
809 // - category and name strings must have application lifetime (statics or
810 // literals). They may not include " chars.
811 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW
812 // events are considered to match if their category_group, name and id values
813 // all match. |id| must either be a pointer or an integer value up to 64 bits.
814 // If it's a pointer, the bits will be xored with a hash of the process ID so
815 // that the same pointer on two different processes will not collide.
816 // FLOW events are different from ASYNC events in how they are drawn by the
817 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task
818 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be
819 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar
820 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined
821 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP
822 // macros. When the operation completes, call FLOW_END. An async operation can
823 // span threads and processes, but all events in that operation must use the
824 // same |name| and |id|. Each event can have its own args.
825 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \
826 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
827 category_group, name, id, \
828 TRACE_EVENT_FLAG_NONE)
829 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \
830 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
831 category_group, name, id, \
832 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
833 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \
834 arg2_name, arg2_val) \
835 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
836 TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id, \
837 TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
838 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \
839 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
840 category_group, name, id, \
841 TRACE_EVENT_FLAG_COPY)
842 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \
843 arg1_val) \
844 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \
845 category_group, name, id, \
846 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
847 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \
848 arg1_val, arg2_name, arg2_val) \
849 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
850 TRACE_EVENT_PHASE_FLOW_BEGIN, category_group, name, id, \
851 TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
852
853 // Records a single FLOW_STEP event for |step| immediately. If the category
854 // is not enabled, then this does nothing. The |name| and |id| must match the
855 // FLOW_BEGIN event above. The |step| param identifies this step within the
856 // async event. This should be called at the beginning of the next phase of an
857 // asynchronous operation.
858 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \
859 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
860 category_group, name, id, \
861 TRACE_EVENT_FLAG_NONE, "step", step)
862 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, arg1_name, \
863 arg1_val) \
864 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
865 TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id, \
866 TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
867 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \
868 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
869 category_group, name, id, \
870 TRACE_EVENT_FLAG_COPY, "step", step)
871 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, arg1_name, \
872 arg1_val) \
873 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
874 TRACE_EVENT_PHASE_FLOW_STEP, category_group, name, id, \
875 TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val)
876
877 // Records a single FLOW_END event for "name" immediately. If the category
878 // is not enabled, then this does nothing.
879 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \
880 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
881 name, id, TRACE_EVENT_FLAG_NONE)
882 #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id) \
883 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
884 name, id, \
885 TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
886 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \
887 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
888 name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
889 arg1_val)
890 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \
891 arg2_name, arg2_val) \
892 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
893 name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \
894 arg1_val, arg2_name, arg2_val)
895 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \
896 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
897 name, id, TRACE_EVENT_FLAG_COPY)
898 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \
899 arg1_val) \
900 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
901 name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
902 arg1_val)
903 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \
904 arg1_val, arg2_name, arg2_val) \
905 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category_group, \
906 name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \
907 arg1_val, arg2_name, arg2_val)
908
909 // Macros to track the life time and value of arbitrary client objects.
910 // See also TraceTrackableObject.
911 #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
912 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
913 TRACE_EVENT_PHASE_CREATE_OBJECT, category_group, name, \
914 TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
915
916 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, \
917 snapshot) \
918 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
919 TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name, \
920 TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
921
922 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID_AND_TIMESTAMP( \
923 category_group, name, id, timestamp, snapshot) \
924 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
925 TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name, \
926 TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, \
927 TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
928
929 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
930 INTERNAL_TRACE_EVENT_ADD_WITH_ID( \
931 TRACE_EVENT_PHASE_DELETE_OBJECT, category_group, name, \
932 TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
933
934 // Entering and leaving trace event contexts. |category_group| and |name|
935 // specify the context category and type. |context| represents a snapshotted
936 // context object.
937 #define TRACE_EVENT_ENTER_CONTEXT(category_group, name, context) \
938 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ENTER_CONTEXT, category_g roup, \
939 name, TRACE_ID_DONT_MANGLE(context), \
940 TRACE_EVENT_FLAG_NONE)
941 #define TRACE_EVENT_LEAVE_CONTEXT(category_group, name, context) \
942 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_LEAVE_CONTEXT, category_g roup, \
943 name, TRACE_ID_DONT_MANGLE(context), \
944 TRACE_EVENT_FLAG_NONE)
945 #define TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
946 INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, \
947 TRACE_ID_DONT_MANGLE(context))
948
949 // Macro to efficiently determine if a given category group is enabled.
950 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \
951 do { \
952 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
953 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
954 *ret = true; \
955 } else { \
956 *ret = false; \
957 } \
958 } while (0)
959
960 // Macro to explicitly warm up a given category group. This could be useful in
961 // cases where we want to initialize a category group before any trace events
962 // for that category group is reported. For example, to have a category group
963 // always show up in the "record categories" list for manually selecting
964 // settings in about://tracing.
965 #define TRACE_EVENT_WARMUP_CATEGORY(category_group) \
966 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group)
967
968 // Macro to efficiently determine, through polling, if a new trace has begun.
969 #define TRACE_EVENT_IS_NEW_TRACE(ret) \
970 do { \
971 static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \
972 int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \
973 if (num_traces_recorded != -1 && \
974 num_traces_recorded != \
975 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \
976 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = num_traces_recorded; \
977 *ret = true; \
978 } else { \
979 *ret = false; \
980 } \
981 } while (0)
982
983 // Notes regarding the following definitions:
984 // New values can be added and propagated to third party libraries, but existing
985 // definitions must never be changed, because third party libraries may use old
986 // definitions.
987
988 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
989 #define TRACE_EVENT_PHASE_BEGIN ('B')
990 #define TRACE_EVENT_PHASE_END ('E')
991 #define TRACE_EVENT_PHASE_COMPLETE ('X')
992 #define TRACE_EVENT_PHASE_INSTANT ('I')
993 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
994 #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T')
995 #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p')
996 #define TRACE_EVENT_PHASE_ASYNC_END ('F')
997 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN ('b')
998 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_END ('e')
999 #define TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT ('n')
1000 #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s')
1001 #define TRACE_EVENT_PHASE_FLOW_STEP ('t')
1002 #define TRACE_EVENT_PHASE_FLOW_END ('f')
1003 #define TRACE_EVENT_PHASE_METADATA ('M')
1004 #define TRACE_EVENT_PHASE_COUNTER ('C')
1005 #define TRACE_EVENT_PHASE_SAMPLE ('P')
1006 #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N')
1007 #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O')
1008 #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D')
1009 #define TRACE_EVENT_PHASE_MEMORY_DUMP ('v')
1010 #define TRACE_EVENT_PHASE_MARK ('R')
1011 #define TRACE_EVENT_PHASE_ENTER_CONTEXT ('(')
1012 #define TRACE_EVENT_PHASE_LEAVE_CONTEXT (')')
1013
1014 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
1015 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
1016 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
1017 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
1018 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2))
1019 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3))
1020 #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4))
1021 #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
1022 #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
1023 #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
1024 #define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
1025 #define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
1026 #define TRACE_EVENT_FLAG_HAS_CONTEXT_ID (static_cast<unsigned int>(1 << 10))
1027
1028 #define TRACE_EVENT_FLAG_SCOPE_MASK \
1029 (static_cast<unsigned int>(TRACE_EVENT_FLAG_SCOPE_OFFSET | \
1030 TRACE_EVENT_FLAG_SCOPE_EXTRA))
1031
1032 // Type values for identifying types in the TraceValue union.
1033 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
1034 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
1035 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
1036 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
1037 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
1038 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
1039 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
1040 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8))
1041
1042 // Enum reflecting the scope of an INSTANT event. Must fit within
1043 // TRACE_EVENT_FLAG_SCOPE_MASK.
1044 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3))
1045 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
1046 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3))
1047
1048 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
1049 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
1050 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/TraceEvent.h ('k') | third_party/WebKit/Source/platform/TracedValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698