OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 Google Inc. | |
2 // | |
3 // Use of this source code is governed by a BSD-style license that can be | |
4 // found in the LICENSE file. | |
5 | |
6 // This header file defines the set of trace_event macros without specifying | |
7 // how the events actually get collected and stored. If you need to expose trace | |
8 // events to some other universe, you can copy-and-paste this file as well as | |
9 // trace_event.h, modifying the macros contained there as necessary for the | |
10 // target platform. The end result is that multiple libraries can funnel events | |
11 // through to a shared trace event collector. | |
12 | |
13 // Trace events are for tracking application performance and resource usage. | |
14 // Macros are provided to track: | |
15 // Begin and end of function calls | |
16 // Counters | |
17 // | |
18 // Events are issued against categories. Whereas LOG's | |
19 // categories are statically defined, TRACE categories are created | |
20 // implicitly with a string. For example: | |
21 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent", | |
22 // TRACE_EVENT_SCOPE_THREAD) | |
23 // | |
24 // It is often the case that one trace may belong in multiple categories at the | |
25 // same time. The first argument to the trace can be a comma-separated list of | |
26 // categories, forming a category group, like: | |
27 // | |
28 // TRACE_EVENT_INSTANT0("input,views", "OnMouseOver", TRACE_EVENT_SCOPE_THREAD) | |
29 // | |
30 // We can enable/disable tracing of OnMouseOver by enabling/disabling either | |
31 // category. | |
32 // | |
33 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: | |
34 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") | |
35 // doSomethingCostly() | |
36 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") | |
37 // Note: our tools can't always determine the correct BEGIN/END pairs unless | |
38 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you | |
39 // need them to be in separate scopes. | |
40 // | |
41 // A common use case is to trace entire function scopes. This | |
42 // issues a trace BEGIN and END automatically: | |
43 // void doSomethingCostly() { | |
44 // TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly"); | |
45 // ... | |
46 // } | |
47 // | |
48 // Additional parameters can be associated with an event: | |
49 // void doSomethingCostly2(int howMuch) { | |
50 // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", | |
51 // "howMuch", howMuch); | |
52 // ... | |
53 // } | |
54 // | |
55 // The trace system will automatically add to this information the | |
56 // current process id, thread id, and a timestamp in microseconds. | |
57 // | |
58 // To trace an asynchronous procedure such as an IPC send/receive, use | |
59 // ASYNC_BEGIN and ASYNC_END: | |
60 // [single threaded sender code] | |
61 // static int send_count = 0; | |
62 // ++send_count; | |
63 // TRACE_EVENT_ASYNC_BEGIN0("ipc", "message", send_count); | |
64 // Send(new MyMessage(send_count)); | |
65 // [receive code] | |
66 // void OnMyMessage(send_count) { | |
67 // TRACE_EVENT_ASYNC_END0("ipc", "message", send_count); | |
68 // } | |
69 // The third parameter is a unique ID to match ASYNC_BEGIN/ASYNC_END pairs. | |
70 // ASYNC_BEGIN and ASYNC_END can occur on any thread of any traced process. | |
71 // Pointers can be used for the ID parameter, and they will be mangled | |
72 // internally so that the same pointer on two different processes will not | |
73 // match. For example: | |
74 // class MyTracedClass { | |
75 // public: | |
76 // MyTracedClass() { | |
77 // TRACE_EVENT_ASYNC_BEGIN0("category", "MyTracedClass", this); | |
78 // } | |
79 // ~MyTracedClass() { | |
80 // TRACE_EVENT_ASYNC_END0("category", "MyTracedClass", this); | |
81 // } | |
82 // } | |
83 // | |
84 // Trace event also supports counters, which is a way to track a quantity | |
85 // as it varies over time. Counters are created with the following macro: | |
86 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue); | |
87 // | |
88 // Counters are process-specific. The macro itself can be issued from any | |
89 // thread, however. | |
90 // | |
91 // Sometimes, you want to track two counters at once. You can do this with two | |
92 // counter macros: | |
93 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]); | |
94 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]); | |
95 // Or you can do it with a combined macro: | |
96 // TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter", | |
97 // "bytesPinned", g_myCounterValue[0], | |
98 // "bytesAllocated", g_myCounterValue[1]); | |
99 // This indicates to the tracing UI that these counters should be displayed | |
100 // in a single graph, as a summed area chart. | |
101 // | |
102 // Since counters are in a global namespace, you may want to disambiguate with a | |
103 // unique ID, by using the TRACE_COUNTER_ID* variations. | |
104 // | |
105 // By default, trace collection is compiled in, but turned off at runtime. | |
106 // Collecting trace data is the responsibility of the embedding | |
107 // application. In Chrome's case, navigating to about:tracing will turn on | |
108 // tracing and display data collected across all active processes. | |
109 // | |
110 // | |
111 // Memory scoping note: | |
112 // Tracing copies the pointers, not the string content, of the strings passed | |
113 // in for category_group, name, and arg_names. Thus, the following code will | |
114 // cause problems: | |
115 // char* str = strdup("importantName"); | |
116 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! | |
117 // free(str); // Trace system now has dangling pointer | |
118 // | |
119 // To avoid this issue with the |name| and |arg_name| parameters, use the | |
120 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. | |
121 // Notes: The category must always be in a long-lived char* (i.e. static const). | |
122 // The |arg_values|, when used, are always deep copied with the _COPY | |
123 // macros. | |
124 // | |
125 // When are string argument values copied: | |
126 // const char* arg_values are only referenced by default: | |
127 // TRACE_EVENT1("category", "name", | |
128 // "arg1", "literal string is only referenced"); | |
129 // Use TRACE_STR_COPY to force copying of a const char*: | |
130 // TRACE_EVENT1("category", "name", | |
131 // "arg1", TRACE_STR_COPY("string will be copied")); | |
132 // std::string arg_values are always copied: | |
133 // TRACE_EVENT1("category", "name", | |
134 // "arg1", std::string("string will be copied")); | |
135 // | |
136 // | |
137 // Thread Safety: | |
138 // A thread safe singleton and mutex are used for thread safety. Category | |
139 // enabled flags are used to limit the performance impact when the system | |
140 // is not enabled. | |
141 // | |
142 // TRACE_EVENT macros first cache a pointer to a category. The categories are | |
143 // statically allocated and safe at all times, even after exit. Fetching a | |
144 // category is protected by the TraceLog::lock_. Multiple threads initializing | |
145 // the static variable is safe, as they will be serialized by the lock and | |
146 // multiple calls will return the same pointer to the category. | |
147 // | |
148 // Then the category_group_enabled flag is checked. This is a unsigned char, and | |
149 // not intended to be multithread safe. It optimizes access to AddTraceEvent | |
150 // which is threadsafe internally via TraceLog::lock_. The enabled flag may | |
151 // cause some threads to incorrectly call or skip calling AddTraceEvent near | |
152 // the time of the system being enabled or disabled. This is acceptable as | |
153 // we tolerate some data loss while the system is being enabled/disabled and | |
154 // because AddTraceEvent is threadsafe internally and checks the enabled state | |
155 // again under lock. | |
156 // | |
157 // Without the use of these static category pointers and enabled flags all | |
158 // trace points would carry a significant performance cost of acquiring a lock | |
159 // and resolving the category. | |
160 | |
161 #ifndef SkTraceEvent_DEFINED | |
162 #define SkTraceEvent_DEFINED | |
163 | |
164 #include "SkEventTracer.h" | |
165 | |
166 // By default, const char* argument values are assumed to have long-lived scope | |
167 // and will not be copied. Use this macro to force a const char* to be copied. | |
168 #define TRACE_STR_COPY(str) \ | |
169 skia::tracing_internals::TraceStringWithCopy(str) | |
170 | |
171 // By default, uint64 ID argument values are not mangled with the Process ID in | |
172 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. | |
173 #define TRACE_ID_MANGLE(id) \ | |
174 skia::tracing_internals::TraceID::ForceMangle(id) | |
175 | |
176 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC | |
177 // macros. Use this macro to prevent Process ID mangling. | |
178 #define TRACE_ID_DONT_MANGLE(id) \ | |
179 skia::tracing_internals::TraceID::DontMangle(id) | |
180 | |
181 // Records a pair of begin and end events called "name" for the current | |
182 // scope, with 0, 1 or 2 associated arguments. If the category is not | |
183 // enabled, then this does nothing. | |
184 // - category and name strings must have application lifetime (statics or | |
185 // literals). They may not include " chars. | |
186 #define TRACE_EVENT0(category_group, name) \ | |
187 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name) | |
188 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
189 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val) | |
190 #define TRACE_EVENT2( \ | |
191 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | |
192 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | |
193 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
194 | |
195 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing. | |
196 // Use this where |name| is too generic to accurately aggregate allocations. | |
197 #define TRACE_EVENT_WITH_MEMORY_TAG2( \ | |
198 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \ | |
199 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | |
200 category, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
201 | |
202 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not | |
203 // included in official builds. | |
204 | |
205 #if OFFICIAL_BUILD | |
206 #undef TRACING_IS_OFFICIAL_BUILD | |
207 #define TRACING_IS_OFFICIAL_BUILD 1 | |
208 #elif !defined(TRACING_IS_OFFICIAL_BUILD) | |
209 #define TRACING_IS_OFFICIAL_BUILD 0 | |
210 #endif | |
211 | |
212 #if TRACING_IS_OFFICIAL_BUILD | |
213 #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0 | |
214 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
215 (void)0 | |
216 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ | |
217 arg2_name, arg2_val) (void)0 | |
218 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0 | |
219 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ | |
220 arg1_name, arg1_val) (void)0 | |
221 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ | |
222 arg1_name, arg1_val, \ | |
223 arg2_name, arg2_val) (void)0 | |
224 #else | |
225 #define UNSHIPPED_TRACE_EVENT0(category_group, name) \ | |
226 TRACE_EVENT0(category_group, name) | |
227 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
228 TRACE_EVENT1(category_group, name, arg1_name, arg1_val) | |
229 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ | |
230 arg2_name, arg2_val) \ | |
231 TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
232 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \ | |
233 TRACE_EVENT_INSTANT0(category_group, name, scope) | |
234 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ | |
235 arg1_name, arg1_val) \ | |
236 TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) | |
237 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ | |
238 arg1_name, arg1_val, \ | |
239 arg2_name, arg2_val) \ | |
240 TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ | |
241 arg2_name, arg2_val) | |
242 #endif | |
243 | |
244 // Records a single event called "name" immediately, with 0, 1 or 2 | |
245 // associated arguments. If the category is not enabled, then this | |
246 // does nothing. | |
247 // - category and name strings must have application lifetime (statics or | |
248 // literals). They may not include " chars. | |
249 #define TRACE_EVENT_INSTANT0(category_group, name, scope) \ | |
250 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
251 category_group, name, TRACE_EVENT_FLAG_NONE | scope) | |
252 #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \ | |
253 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
254 category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ | |
255 arg1_name, arg1_val) | |
256 #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ | |
257 arg2_name, arg2_val) \ | |
258 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
259 category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ | |
260 arg1_name, arg1_val, arg2_name, arg2_val) | |
261 #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \ | |
262 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
263 category_group, name, TRACE_EVENT_FLAG_COPY | scope) | |
264 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, \ | |
265 arg1_name, arg1_val) \ | |
266 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
267 category_group, name, TRACE_EVENT_FLAG_COPY | scope, arg1_name, \ | |
268 arg1_val) | |
269 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, \ | |
270 arg1_name, arg1_val, \ | |
271 arg2_name, arg2_val) \ | |
272 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
273 category_group, name, TRACE_EVENT_FLAG_COPY | scope, \ | |
274 arg1_name, arg1_val, arg2_name, arg2_val) | |
275 | |
276 // Sets the current sample state to the given category and name (both must be | |
277 // constant strings). These states are intended for a sampling profiler. | |
278 // Implementation note: we store category and name together because we don't | |
279 // want the inconsistency/expense of storing two pointers. | |
280 // |thread_bucket| is [0..2] and is used to statically isolate samples in one | |
281 // thread from others. | |
282 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ | |
283 bucket_number, category, name) \ | |
284 skia::tracing_internals:: \ | |
285 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) | |
mtklein
2014/01/30 14:18:26
This is a super cute way to require category and n
| |
286 | |
287 // Returns a current sampling state of the given bucket. | |
288 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ | |
289 skia::tracing_internals::TraceEventSamplingStateScope<bucket_number>::Curren t() | |
290 | |
291 // Creates a scope of a sampling state of the given bucket. | |
292 // | |
293 // { // The sampling state is set within this scope. | |
294 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); | |
295 // ...; | |
296 // } | |
297 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ | |
298 bucket_number, category, name) \ | |
299 skia::tracing_internals::TraceEventSamplingStateScope<bucket_number> \ | |
300 traceEventSamplingScope(category "\0" name); | |
301 | |
302 // Syntactic sugars for the sampling tracing in the main thread. | |
303 #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \ | |
304 TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name) | |
305 #define TRACE_EVENT_GET_SAMPLING_STATE() \ | |
306 TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0) | |
307 #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \ | |
308 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name) | |
309 | |
310 | |
311 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | |
312 // associated arguments. If the category is not enabled, then this | |
313 // does nothing. | |
314 // - category and name strings must have application lifetime (statics or | |
315 // literals). They may not include " chars. | |
316 #define TRACE_EVENT_BEGIN0(category_group, name) \ | |
317 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
318 category_group, name, TRACE_EVENT_FLAG_NONE) | |
319 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ | |
320 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
321 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
322 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \ | |
323 arg2_name, arg2_val) \ | |
324 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
325 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | |
326 arg2_name, arg2_val) | |
327 #define TRACE_EVENT_COPY_BEGIN0(category_group, name) \ | |
328 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
329 category_group, name, TRACE_EVENT_FLAG_COPY) | |
330 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \ | |
331 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
332 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
333 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \ | |
334 arg2_name, arg2_val) \ | |
335 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
336 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | |
337 arg2_name, arg2_val) | |
338 | |
339 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. | |
340 // - |id| is used to match the _BEGIN event with the _END event. | |
341 // Events are considered to match if their category_group, name and id values | |
342 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
343 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
344 // that the same pointer on two different processes will not collide. | |
345 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ | |
346 name, id, thread_id) \ | |
347 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
348 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ | |
349 timestamp, TRACE_EVENT_FLAG_NONE) | |
350 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ | |
351 category_group, name, id, thread_id) \ | |
352 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
353 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ | |
354 timestamp, TRACE_EVENT_FLAG_COPY) | |
355 | |
356 // Records a single END event for "name" immediately. If the category | |
357 // is not enabled, then this does nothing. | |
358 // - category and name strings must have application lifetime (statics or | |
359 // literals). They may not include " chars. | |
360 #define TRACE_EVENT_END0(category_group, name) \ | |
361 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
362 category_group, name, TRACE_EVENT_FLAG_NONE) | |
363 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \ | |
364 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
365 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
366 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, \ | |
367 arg2_name, arg2_val) \ | |
368 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
369 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | |
370 arg2_name, arg2_val) | |
371 #define TRACE_EVENT_COPY_END0(category_group, name) \ | |
372 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
373 category_group, name, TRACE_EVENT_FLAG_COPY) | |
374 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \ | |
375 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
376 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
377 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \ | |
378 arg2_name, arg2_val) \ | |
379 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
380 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | |
381 arg2_name, arg2_val) | |
382 | |
383 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. | |
384 // - |id| is used to match the _BEGIN event with the _END event. | |
385 // Events are considered to match if their category_group, name and id values | |
386 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
387 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
388 // that the same pointer on two different processes will not collide. | |
389 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ | |
390 name, id, thread_id) \ | |
391 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
392 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ | |
393 timestamp, TRACE_EVENT_FLAG_NONE) | |
394 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ | |
395 category_group, name, id, thread_id) \ | |
396 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
397 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ | |
398 timestamp, TRACE_EVENT_FLAG_COPY) | |
399 | |
400 // Records the value of a counter called "name" immediately. Value | |
401 // must be representable as a 32 bit integer. | |
402 // - category and name strings must have application lifetime (statics or | |
403 // literals). They may not include " chars. | |
404 #define TRACE_COUNTER1(category_group, name, value) \ | |
405 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
406 category_group, name, TRACE_EVENT_FLAG_NONE, \ | |
407 "value", static_cast<int>(value)) | |
408 #define TRACE_COPY_COUNTER1(category_group, name, value) \ | |
409 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
410 category_group, name, TRACE_EVENT_FLAG_COPY, \ | |
411 "value", static_cast<int>(value)) | |
412 | |
413 // Records the values of a multi-parted counter called "name" immediately. | |
414 // The UI will treat value1 and value2 as parts of a whole, displaying their | |
415 // values as a stacked-bar chart. | |
416 // - category and name strings must have application lifetime (statics or | |
417 // literals). They may not include " chars. | |
418 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \ | |
419 value2_name, value2_val) \ | |
420 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
421 category_group, name, TRACE_EVENT_FLAG_NONE, \ | |
422 value1_name, static_cast<int>(value1_val), \ | |
423 value2_name, static_cast<int>(value2_val)) | |
424 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \ | |
425 value2_name, value2_val) \ | |
426 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
427 category_group, name, TRACE_EVENT_FLAG_COPY, \ | |
428 value1_name, static_cast<int>(value1_val), \ | |
429 value2_name, static_cast<int>(value2_val)) | |
430 | |
431 // Records the value of a counter called "name" immediately. Value | |
432 // must be representable as a 32 bit integer. | |
433 // - category and name strings must have application lifetime (statics or | |
434 // literals). They may not include " chars. | |
435 // - |id| is used to disambiguate counters with the same name. It must either | |
436 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | |
437 // will be xored with a hash of the process ID so that the same pointer on | |
438 // two different processes will not collide. | |
439 #define TRACE_COUNTER_ID1(category_group, name, id, value) \ | |
440 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
441 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
442 "value", static_cast<int>(value)) | |
443 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \ | |
444 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
445 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
446 "value", static_cast<int>(value)) | |
447 | |
448 // Records the values of a multi-parted counter called "name" immediately. | |
449 // The UI will treat value1 and value2 as parts of a whole, displaying their | |
450 // values as a stacked-bar chart. | |
451 // - category and name strings must have application lifetime (statics or | |
452 // literals). They may not include " chars. | |
453 // - |id| is used to disambiguate counters with the same name. It must either | |
454 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | |
455 // will be xored with a hash of the process ID so that the same pointer on | |
456 // two different processes will not collide. | |
457 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \ | |
458 value2_name, value2_val) \ | |
459 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
460 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
461 value1_name, static_cast<int>(value1_val), \ | |
462 value2_name, static_cast<int>(value2_val)) | |
463 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \ | |
464 value1_val, value2_name, value2_val) \ | |
465 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
466 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
467 value1_name, static_cast<int>(value1_val), \ | |
468 value2_name, static_cast<int>(value2_val)) | |
469 | |
470 | |
471 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2 | |
472 // associated arguments. If the category is not enabled, then this | |
473 // does nothing. | |
474 // - category and name strings must have application lifetime (statics or | |
475 // literals). They may not include " chars. | |
476 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC | |
477 // events are considered to match if their category_group, name and id values | |
478 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
479 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
480 // that the same pointer on two different processes will not collide. | |
481 // | |
482 // An asynchronous operation can consist of multiple phases. The first phase is | |
483 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the | |
484 // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will | |
485 // annotate the block following the call. The ASYNC_STEP_PAST macro will | |
486 // annotate the block prior to the call. Note that any particular event must use | |
487 // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the | |
488 // operation completes, call ASYNC_END. | |
489 // | |
490 // An ASYNC trace typically occurs on a single thread (if not, they will only be | |
491 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that | |
492 // operation must use the same |name| and |id|. Each step can have its own | |
493 // args. | |
494 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \ | |
495 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
496 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
497 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ | |
498 arg1_val) \ | |
499 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
500 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
501 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ | |
502 arg1_val, arg2_name, arg2_val) \ | |
503 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
504 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
505 arg1_name, arg1_val, arg2_name, arg2_val) | |
506 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \ | |
507 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
508 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
509 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ | |
510 arg1_val) \ | |
511 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
512 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
513 arg1_name, arg1_val) | |
514 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ | |
515 arg1_val, arg2_name, arg2_val) \ | |
516 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
517 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
518 arg1_name, arg1_val, arg2_name, arg2_val) | |
519 | |
520 // Records a single ASYNC_STEP_INTO event for |step| immediately. If the | |
521 // category is not enabled, then this does nothing. The |name| and |id| must | |
522 // match the ASYNC_BEGIN event above. The |step| param identifies this step | |
523 // within the async event. This should be called at the beginning of the next | |
524 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any | |
525 // ASYNC_STEP_PAST events. | |
526 #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \ | |
527 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ | |
528 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
529 #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \ | |
530 arg1_name, arg1_val) \ | |
531 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ | |
532 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
533 arg1_name, arg1_val) | |
534 | |
535 // Records a single ASYNC_STEP_PAST event for |step| immediately. If the | |
536 // category is not enabled, then this does nothing. The |name| and |id| must | |
537 // match the ASYNC_BEGIN event above. The |step| param identifies this step | |
538 // within the async event. This should be called at the beginning of the next | |
539 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any | |
540 // ASYNC_STEP_INTO events. | |
541 #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \ | |
542 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ | |
543 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
544 #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \ | |
545 arg1_name, arg1_val) \ | |
546 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ | |
547 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
548 arg1_name, arg1_val) | |
549 | |
550 // Records a single ASYNC_END event for "name" immediately. If the category | |
551 // is not enabled, then this does nothing. | |
552 #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \ | |
553 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
554 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
555 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \ | |
556 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
557 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
558 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \ | |
559 arg2_name, arg2_val) \ | |
560 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
561 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
562 arg1_name, arg1_val, arg2_name, arg2_val) | |
563 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \ | |
564 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
565 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
566 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \ | |
567 arg1_val) \ | |
568 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
569 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
570 arg1_name, arg1_val) | |
571 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \ | |
572 arg1_val, arg2_name, arg2_val) \ | |
573 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
574 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
575 arg1_name, arg1_val, arg2_name, arg2_val) | |
576 | |
577 | |
578 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2 | |
579 // associated arguments. If the category is not enabled, then this | |
580 // does nothing. | |
581 // - category and name strings must have application lifetime (statics or | |
582 // literals). They may not include " chars. | |
583 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW | |
584 // events are considered to match if their category_group, name and id values | |
585 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
586 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
587 // that the same pointer on two different processes will not collide. | |
588 // FLOW events are different from ASYNC events in how they are drawn by the | |
589 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task | |
590 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be | |
591 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar | |
592 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined | |
593 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP | |
594 // macros. When the operation completes, call FLOW_END. An async operation can | |
595 // span threads and processes, but all events in that operation must use the | |
596 // same |name| and |id|. Each event can have its own args. | |
597 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \ | |
598 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
599 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
600 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \ | |
601 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
602 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
603 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \ | |
604 arg2_name, arg2_val) \ | |
605 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
606 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
607 arg1_name, arg1_val, arg2_name, arg2_val) | |
608 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \ | |
609 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
610 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
611 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \ | |
612 arg1_val) \ | |
613 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
614 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
615 arg1_name, arg1_val) | |
616 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \ | |
617 arg1_val, arg2_name, arg2_val) \ | |
618 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
619 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
620 arg1_name, arg1_val, arg2_name, arg2_val) | |
621 | |
622 // Records a single FLOW_STEP event for |step| immediately. If the category | |
623 // is not enabled, then this does nothing. The |name| and |id| must match the | |
624 // FLOW_BEGIN event above. The |step| param identifies this step within the | |
625 // async event. This should be called at the beginning of the next phase of an | |
626 // asynchronous operation. | |
627 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \ | |
628 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
629 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
630 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, \ | |
631 arg1_name, arg1_val) \ | |
632 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
633 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
634 arg1_name, arg1_val) | |
635 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \ | |
636 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
637 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step) | |
638 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, \ | |
639 arg1_name, arg1_val) \ | |
640 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
641 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ | |
642 arg1_name, arg1_val) | |
643 | |
644 // Records a single FLOW_END event for "name" immediately. If the category | |
645 // is not enabled, then this does nothing. | |
646 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \ | |
647 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
648 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
649 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \ | |
650 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
651 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
652 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \ | |
653 arg2_name, arg2_val) \ | |
654 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
655 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
656 arg1_name, arg1_val, arg2_name, arg2_val) | |
657 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \ | |
658 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
659 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
660 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \ | |
661 arg1_val) \ | |
662 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
663 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
664 arg1_name, arg1_val) | |
665 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \ | |
666 arg1_val, arg2_name, arg2_val) \ | |
667 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
668 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
669 arg1_name, arg1_val, arg2_name, arg2_val) | |
670 | |
671 // Macros to track the life time and value of arbitrary client objects. | |
672 // See also TraceTrackableObject. | |
673 #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \ | |
674 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_CREATE_OBJECT, \ | |
675 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) | |
676 | |
677 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) \ | |
678 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \ | |
679 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\ | |
680 "snapshot", snapshot) | |
681 | |
682 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \ | |
683 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \ | |
684 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) | |
685 | |
686 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | |
687 *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ | |
688 (SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags | \ | |
689 SkEventTracer::kEnabledForEventCallback_CategoryGroupEnabledFlags) | |
690 | |
691 // Macro to efficiently determine if a given category group is enabled. | |
692 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \ | |
693 do { \ | |
694 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
695 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
696 *ret = true; \ | |
697 } else { \ | |
698 *ret = false; \ | |
699 } \ | |
700 } while (0) | |
701 | |
702 // Macro to efficiently determine, through polling, if a new trace has begun. | |
703 #define TRACE_EVENT_IS_NEW_TRACE(ret) \ | |
704 do { \ | |
705 static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \ | |
706 int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \ | |
707 if (num_traces_recorded != -1 && \ | |
708 num_traces_recorded != \ | |
709 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \ | |
710 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = \ | |
711 num_traces_recorded; \ | |
712 *ret = true; \ | |
713 } else { \ | |
714 *ret = false; \ | |
715 } \ | |
716 } while (0) | |
717 | |
718 //////////////////////////////////////////////////////////////////////////////// | |
719 // Implementation specific tracing API definitions. | |
720 | |
721 // Get a pointer to the enabled state of the given trace category. Only | |
722 // long-lived literal strings should be given as the category group. The | |
723 // returned pointer can be held permanently in a local static for example. If | |
724 // the unsigned char is non-zero, tracing is enabled. If tracing is enabled, | |
725 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled | |
726 // between the load of the tracing state and the call to | |
727 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out | |
728 // for best performance when tracing is disabled. | |
729 // const unsigned char* | |
730 // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group) | |
731 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ | |
732 SkEventTracer::GetInstance()->getCategoryGroupEnabled | |
733 | |
734 // Get the number of times traces have been recorded. This is used to implement | |
735 // the TRACE_EVENT_IS_NEW_TRACE facility. | |
736 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED() | |
737 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \ | |
738 SkEventTracer::GetInstance()->getNumTracesRecorded | |
739 | |
740 // Add a trace event to the platform tracing system. | |
741 // SkTraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( | |
742 // char phase, | |
743 // const unsigned char* category_group_enabled, | |
744 // const char* name, | |
745 // unsigned long long id, | |
746 // int num_args, | |
747 // const char** arg_names, | |
748 // const unsigned char* arg_types, | |
749 // const unsigned long long* arg_values, | |
750 // unsigned char flags) | |
751 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | |
752 SkEventTracer::GetInstance()->addTraceEvent | |
753 | |
754 // Set the duration field of a COMPLETE trace event. | |
755 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | |
756 // const unsigned char* category_group_enabled, | |
757 // const char* name, | |
758 // SkTraceEventHandle id) | |
759 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | |
760 SkEventTracer::GetInstance()->updateTraceEventDuration | |
761 | |
762 // These operations are atomic in the Chrome tracing implementation | |
763 // to cater to ARM's weak memory consistency; we're just doing read/ | |
764 // write here because it's not strictly needed for correctness. | |
765 // So says Nat. | |
766 // FIXME | |
767 | |
768 #define TRACE_EVENT_API_ATOMIC_WORD intptr_t | |
769 #define TRACE_EVENT_API_ATOMIC_LOAD(var) (*(&var)) | |
770 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) (var=value) | |
771 | |
772 // Defines visibility for classes in trace_event.h | |
773 #define TRACE_EVENT_API_CLASS_EXPORT SK_API | |
774 | |
775 // The thread buckets for the sampling profiler. | |
776 TRACE_EVENT_API_CLASS_EXPORT extern \ | |
777 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; | |
778 | |
779 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ | |
780 g_trace_state[thread_bucket] | |
781 | |
782 //////////////////////////////////////////////////////////////////////////////// | |
783 | |
784 // Implementation detail: trace event macros create temporary variables | |
785 // to keep instrumentation overhead low. These macros give each temporary | |
786 // variable a unique name based on the line number to prevent name collisions. | |
787 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | |
788 trace_event_unique_##a##b | |
789 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | |
790 INTERNAL_TRACE_EVENT_UID3(a,b) | |
791 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | |
792 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) | |
793 | |
794 // Implementation detail: internal macro to create static category. | |
795 // No barriers are needed, because this code is designed to operate safely | |
796 // even when the unsigned char* points to garbage data (which may be the case | |
797 // on processors without cache coherency). | |
798 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \ | |
799 category_group, atomic, category_group_enabled) \ | |
800 category_group_enabled = \ | |
801 reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD( \ | |
802 atomic)); \ | |
803 if (!category_group_enabled) { \ | |
804 category_group_enabled = \ | |
805 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \ | |
806 TRACE_EVENT_API_ATOMIC_STORE(atomic, \ | |
807 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \ | |
808 category_group_enabled)); \ | |
809 } | |
810 | |
811 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ | |
812 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ | |
813 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ | |
814 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \ | |
815 INTERNAL_TRACE_EVENT_UID(atomic), \ | |
816 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); | |
817 | |
818 // Implementation detail: internal macro to create static category and add | |
819 // event if the category is enabled. | |
820 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ | |
821 do { \ | |
822 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
823 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
824 skia::tracing_internals::AddTraceEvent( \ | |
825 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | |
826 skia::tracing_internals::kNoEventId, flags, ##__VA_ARGS__); \ | |
827 } \ | |
828 } while (0) | |
829 | |
830 // Implementation detail: internal macro to create static category and add begin | |
831 // event if the category is enabled. Also adds the end event when the scope | |
832 // ends. | |
833 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ | |
834 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
835 skia::tracing_internals::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ | |
836 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
837 SkTraceEventHandle h = skia::tracing_internals::AddTraceEvent( \ | |
838 TRACE_EVENT_PHASE_COMPLETE, \ | |
839 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
840 name, skia::tracing_internals::kNoEventId, \ | |
841 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ | |
842 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ | |
843 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ | |
844 } | |
845 | |
846 // Implementation detail: internal macro to create static category and add | |
847 // event if the category is enabled. | |
848 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ | |
849 flags, ...) \ | |
850 do { \ | |
851 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
852 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
853 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
854 skia::tracing_internals::TraceID trace_event_trace_id( \ | |
855 id, &trace_event_flags); \ | |
856 skia::tracing_internals::AddTraceEvent( \ | |
857 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
858 name, trace_event_trace_id.data(), trace_event_flags, \ | |
859 ##__VA_ARGS__); \ | |
860 } \ | |
861 } while (0) | |
862 | |
863 // Implementation detail: internal macro to create static category and add | |
864 // event if the category is enabled. | |
865 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ | |
866 category_group, name, id, thread_id, flags, ...) \ | |
867 do { \ | |
868 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
869 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
870 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
871 skia::tracing_internals::TraceID trace_event_trace_id( \ | |
872 id, &trace_event_flags); \ | |
873 skia::tracing_internals::AddTraceEventWithThreadIdAndTimestamp( \ | |
874 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
875 name, trace_event_trace_id.data(), \ | |
876 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ | |
877 trace_event_flags, ##__VA_ARGS__); \ | |
878 } \ | |
879 } while (0) | |
880 | |
881 // Notes regarding the following definitions: | |
882 // New values can be added and propagated to third party libraries, but existing | |
883 // definitions must never be changed, because third party libraries may use old | |
884 // definitions. | |
885 | |
886 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | |
887 #define TRACE_EVENT_PHASE_BEGIN ('B') | |
888 #define TRACE_EVENT_PHASE_END ('E') | |
889 #define TRACE_EVENT_PHASE_COMPLETE ('X') | |
890 #define TRACE_EVENT_PHASE_INSTANT ('i') | |
891 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') | |
892 #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T') | |
893 #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p') | |
894 #define TRACE_EVENT_PHASE_ASYNC_END ('F') | |
895 #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s') | |
896 #define TRACE_EVENT_PHASE_FLOW_STEP ('t') | |
897 #define TRACE_EVENT_PHASE_FLOW_END ('f') | |
898 #define TRACE_EVENT_PHASE_METADATA ('M') | |
899 #define TRACE_EVENT_PHASE_COUNTER ('C') | |
900 #define TRACE_EVENT_PHASE_SAMPLE ('P') | |
901 #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N') | |
902 #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O') | |
903 #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D') | |
904 | |
905 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. | |
906 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned char>(0)) | |
907 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned char>(1 << 0)) | |
908 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned char>(1 << 1)) | |
909 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned char>(1 << 2)) | |
910 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned char>(1 << 3)) | |
911 | |
912 #define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast<unsigned char>( \ | |
913 TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1))) | |
914 | |
915 // Type values for identifying types in the TraceValue union. | |
916 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) | |
917 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) | |
918 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) | |
919 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) | |
920 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) | |
921 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) | |
922 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) | |
923 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) | |
924 | |
925 // Enum reflecting the scope of an INSTANT event. Must fit within | |
926 // TRACE_EVENT_FLAG_SCOPE_MASK. | |
927 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) | |
928 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) | |
929 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) | |
930 | |
931 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') | |
932 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') | |
933 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') | |
934 | |
935 namespace skia { | |
936 namespace tracing_internals { | |
937 | |
938 // Specify these values when the corresponding argument of AddTraceEvent is not | |
939 // used. | |
940 const int kZeroNumArgs = 0; | |
941 const unsigned long long kNoEventId = 0; | |
942 | |
943 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | |
944 // are by default mangled with the Process ID so that they are unlikely to | |
945 // collide when the same pointer is used on different processes. | |
946 class TraceID { | |
947 public: | |
948 class DontMangle { | |
949 public: | |
950 explicit DontMangle(const void* id) | |
951 : data_(static_cast<unsigned long long>( | |
952 reinterpret_cast<unsigned long>(id))) {} | |
953 explicit DontMangle(unsigned long long id) : data_(id) {} | |
954 explicit DontMangle(unsigned long id) : data_(id) {} | |
955 explicit DontMangle(unsigned int id) : data_(id) {} | |
956 explicit DontMangle(unsigned short id) : data_(id) {} | |
957 explicit DontMangle(unsigned char id) : data_(id) {} | |
958 explicit DontMangle(long long id) | |
959 : data_(static_cast<unsigned long long>(id)) {} | |
960 explicit DontMangle(long id) | |
961 : data_(static_cast<unsigned long long>(id)) {} | |
962 explicit DontMangle(int id) | |
963 : data_(static_cast<unsigned long long>(id)) {} | |
964 explicit DontMangle(short id) | |
965 : data_(static_cast<unsigned long long>(id)) {} | |
966 explicit DontMangle(signed char id) | |
967 : data_(static_cast<unsigned long long>(id)) {} | |
968 unsigned long long data() const { return data_; } | |
969 private: | |
970 unsigned long long data_; | |
971 }; | |
972 | |
973 class ForceMangle { | |
974 public: | |
975 explicit ForceMangle(unsigned long long id) : data_(id) {} | |
976 explicit ForceMangle(unsigned long id) : data_(id) {} | |
977 explicit ForceMangle(unsigned int id) : data_(id) {} | |
978 explicit ForceMangle(unsigned short id) : data_(id) {} | |
979 explicit ForceMangle(unsigned char id) : data_(id) {} | |
980 explicit ForceMangle(long long id) | |
981 : data_(static_cast<unsigned long long>(id)) {} | |
982 explicit ForceMangle(long id) | |
983 : data_(static_cast<unsigned long long>(id)) {} | |
984 explicit ForceMangle(int id) | |
985 : data_(static_cast<unsigned long long>(id)) {} | |
986 explicit ForceMangle(short id) | |
987 : data_(static_cast<unsigned long long>(id)) {} | |
988 explicit ForceMangle(signed char id) | |
989 : data_(static_cast<unsigned long long>(id)) {} | |
990 unsigned long long data() const { return data_; } | |
991 private: | |
992 unsigned long long data_; | |
993 }; | |
994 | |
995 TraceID(const void* id, unsigned char* flags) | |
996 : data_(static_cast<unsigned long long>( | |
997 reinterpret_cast<unsigned long>(id))) { | |
998 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | |
999 } | |
1000 TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) { | |
1001 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | |
1002 } | |
1003 TraceID(DontMangle id, unsigned char* flags) : data_(id.data()) { | |
1004 } | |
1005 TraceID(unsigned long long id, unsigned char* flags) | |
1006 : data_(id) { (void)flags; } | |
1007 TraceID(unsigned long id, unsigned char* flags) | |
1008 : data_(id) { (void)flags; } | |
1009 TraceID(unsigned int id, unsigned char* flags) | |
1010 : data_(id) { (void)flags; } | |
1011 TraceID(unsigned short id, unsigned char* flags) | |
1012 : data_(id) { (void)flags; } | |
1013 TraceID(unsigned char id, unsigned char* flags) | |
1014 : data_(id) { (void)flags; } | |
1015 TraceID(long long id, unsigned char* flags) | |
1016 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
1017 TraceID(long id, unsigned char* flags) | |
1018 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
1019 TraceID(int id, unsigned char* flags) | |
1020 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
1021 TraceID(short id, unsigned char* flags) | |
1022 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
1023 TraceID(signed char id, unsigned char* flags) | |
1024 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
1025 | |
1026 unsigned long long data() const { return data_; } | |
1027 | |
1028 private: | |
1029 unsigned long long data_; | |
1030 }; | |
1031 | |
1032 // Simple union to store various types as unsigned long long. | |
1033 union TraceValueUnion { | |
1034 bool as_bool; | |
1035 unsigned long long as_uint; | |
1036 long long as_int; | |
1037 double as_double; | |
1038 const void* as_pointer; | |
1039 const char* as_string; | |
1040 }; | |
1041 | |
1042 // Simple container for const char* that should be copied instead of retained. | |
1043 class TraceStringWithCopy { | |
1044 public: | |
1045 explicit TraceStringWithCopy(const char* str) : str_(str) {} | |
1046 operator const char* () const { return str_; } | |
1047 private: | |
1048 const char* str_; | |
1049 }; | |
1050 | |
1051 // Define SetTraceValue for each allowed type. It stores the type and | |
1052 // value in the return arguments. This allows this API to avoid declaring any | |
1053 // structures so that it is portable to third_party libraries. | |
1054 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ | |
1055 union_member, \ | |
1056 value_type_id) \ | |
1057 static inline void SetTraceValue( \ | |
1058 actual_type arg, \ | |
1059 unsigned char* type, \ | |
1060 unsigned long long* value) { \ | |
1061 TraceValueUnion type_value; \ | |
1062 type_value.union_member = arg; \ | |
1063 *type = value_type_id; \ | |
1064 *value = type_value.as_uint; \ | |
1065 } | |
1066 // Simpler form for int types that can be safely casted. | |
1067 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ | |
1068 value_type_id) \ | |
1069 static inline void SetTraceValue( \ | |
1070 actual_type arg, \ | |
1071 unsigned char* type, \ | |
1072 unsigned long long* value) { \ | |
1073 *type = value_type_id; \ | |
1074 *value = static_cast<unsigned long long>(arg); \ | |
1075 } | |
1076 | |
1077 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) | |
1078 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) | |
1079 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) | |
1080 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) | |
1081 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) | |
1082 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) | |
1083 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) | |
1084 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) | |
1085 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) | |
1086 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) | |
1087 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) | |
1088 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) | |
1089 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | |
1090 TRACE_VALUE_TYPE_POINTER) | |
1091 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | |
1092 TRACE_VALUE_TYPE_STRING) | |
1093 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | |
1094 TRACE_VALUE_TYPE_COPY_STRING) | |
1095 | |
1096 #undef INTERNAL_DECLARE_SET_TRACE_VALUE | |
1097 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT | |
1098 | |
1099 // These AddTraceEvent and AddTraceEvent template | |
1100 // functions are defined here instead of in the macro, because the arg_values | |
1101 // could be temporary objects, such as std::string. In order to store | |
1102 // pointers to the internal c_str and pass through to the tracing API, | |
1103 // the arg_values must live throughout these procedures. | |
1104 | |
1105 static inline SkTraceEventHandle | |
1106 AddTraceEvent( | |
1107 char phase, | |
1108 const unsigned char* category_group_enabled, | |
1109 const char* name, | |
1110 unsigned long long id, | |
1111 unsigned char flags) { | |
1112 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
1113 phase, category_group_enabled, name, id, | |
1114 kZeroNumArgs, NULL, NULL, NULL, flags); | |
1115 } | |
1116 | |
1117 template<class ARG1_TYPE> | |
1118 static inline SkTraceEventHandle | |
1119 AddTraceEvent( | |
1120 char phase, | |
1121 const unsigned char* category_group_enabled, | |
1122 const char* name, | |
1123 unsigned long long id, | |
1124 unsigned char flags, | |
1125 const char* arg1_name, | |
1126 const ARG1_TYPE& arg1_val) { | |
1127 const int num_args = 1; | |
1128 unsigned char arg_types[1]; | |
1129 unsigned long long arg_values[1]; | |
1130 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
1131 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
1132 phase, category_group_enabled, name, id, | |
1133 num_args, &arg1_name, arg_types, arg_values, flags); | |
1134 } | |
1135 | |
1136 template<class ARG1_TYPE, class ARG2_TYPE> | |
1137 static inline SkTraceEventHandle | |
1138 AddTraceEvent( | |
1139 char phase, | |
1140 const unsigned char* category_group_enabled, | |
1141 const char* name, | |
1142 unsigned long long id, | |
1143 unsigned char flags, | |
1144 const char* arg1_name, | |
1145 const ARG1_TYPE& arg1_val, | |
1146 const char* arg2_name, | |
1147 const ARG2_TYPE& arg2_val) { | |
1148 const int num_args = 2; | |
1149 const char* arg_names[2] = { arg1_name, arg2_name }; | |
1150 unsigned char arg_types[2]; | |
1151 unsigned long long arg_values[2]; | |
1152 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
1153 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | |
1154 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
1155 phase, category_group_enabled, name, id, | |
1156 num_args, arg_names, arg_types, arg_values, flags); | |
1157 } | |
1158 | |
1159 // Used by TRACE_EVENTx macros. Do not use directly. | |
1160 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | |
1161 public: | |
1162 // Note: members of data_ intentionally left uninitialized. See Initialize. | |
1163 ScopedTracer() : p_data_(NULL) {} | |
1164 | |
1165 ~ScopedTracer() { | |
1166 if (p_data_ && *data_.category_group_enabled) | |
1167 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | |
1168 data_.category_group_enabled, data_.name, data_.event_handle); | |
1169 } | |
1170 | |
1171 void Initialize(const unsigned char* category_group_enabled, | |
1172 const char* name, | |
1173 SkTraceEventHandle event_handle) { | |
1174 data_.category_group_enabled = category_group_enabled; | |
1175 data_.name = name; | |
1176 data_.event_handle = event_handle; | |
1177 p_data_ = &data_; | |
1178 } | |
1179 | |
1180 private: | |
1181 // This Data struct workaround is to avoid initializing all the members | |
1182 // in Data during construction of this object, since this object is always | |
1183 // constructed, even when tracing is disabled. If the members of Data were | |
1184 // members of this class instead, compiler warnings occur about potential | |
1185 // uninitialized accesses. | |
1186 struct Data { | |
1187 const unsigned char* category_group_enabled; | |
1188 const char* name; | |
1189 SkTraceEventHandle event_handle; | |
1190 }; | |
1191 Data* p_data_; | |
1192 Data data_; | |
1193 }; | |
1194 | |
1195 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. | |
1196 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient { | |
1197 public: | |
1198 ScopedTraceBinaryEfficient(const char* category_group, const char* name); | |
1199 ~ScopedTraceBinaryEfficient(); | |
1200 | |
1201 private: | |
1202 const unsigned char* category_group_enabled_; | |
1203 const char* name_; | |
1204 SkTraceEventHandle event_handle_; | |
1205 }; | |
1206 | |
1207 // This macro generates less code then TRACE_EVENT0 but is also | |
1208 // slower to execute when tracing is off. It should generally only be | |
1209 // used with code that is seldom executed or conditionally executed | |
1210 // when debugging. | |
1211 // For now the category_group must be "gpu". | |
1212 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ | |
1213 skia::tracing_internals::ScopedTraceBinaryEfficient \ | |
1214 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name); | |
1215 | |
1216 // TraceEventSamplingStateScope records the current sampling state | |
1217 // and sets a new sampling state. When the scope exists, it restores | |
1218 // the sampling state having recorded. | |
1219 template<size_t BucketNumber> | |
1220 class TraceEventSamplingStateScope { | |
1221 public: | |
1222 TraceEventSamplingStateScope(const char* category_and_name) { | |
1223 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current(); | |
1224 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name); | |
1225 } | |
1226 | |
1227 ~TraceEventSamplingStateScope() { | |
1228 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_); | |
1229 } | |
1230 | |
1231 static inline const char* Current() { | |
1232 return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( | |
1233 g_trace_state[BucketNumber])); | |
1234 } | |
1235 | |
1236 static inline void Set(const char* category_and_name) { | |
1237 TRACE_EVENT_API_ATOMIC_STORE( | |
1238 g_trace_state[BucketNumber], | |
1239 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | |
1240 const_cast<char*>(category_and_name))); | |
1241 } | |
1242 | |
1243 private: | |
1244 const char* previous_state_; | |
1245 }; | |
1246 | |
1247 } // namespace tracing_internals | |
1248 } // namespace skia | |
1249 | |
1250 #endif | |
OLD | NEW |