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

Side by Side Diff: src/tracing/trace-event-common.h

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

Powered by Google App Engine
This is Rietveld 408576698