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