Chromium Code Reviews| 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! | |
|
mtklein
2014/01/29 20:57:55
Just curious. Would it be incompatible with Chrom
humper
2014/01/29 21:29:09
I don't know the answer to this -- shoudl probably
| |
| 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 // Convertable notes: | |
| 138 // Converting a large data type to a string can be costly. To help with this, | |
| 139 // the trace framework provides an interface ConvertableToTraceFormat. If you | |
| 140 // inherit from it and implement the AppendAsTraceFormat method the trace | |
| 141 // framework will call back to your object to convert a trace output time. This | |
| 142 // means, if the category for the event is disabled, the conversion will not | |
| 143 // happen. | |
| 144 // | |
| 145 // class MyData : public skia::tracing::ConvertableToTraceFormat { | |
|
mtklein
2014/01/29 20:57:55
: SkNonCopyable, public skia::tracing::...
humper
2014/01/29 21:29:09
Yeha, this convertable stuff was stripped pending
| |
| 146 // public: | |
| 147 // MyData() {} | |
| 148 // virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { | |
|
mtklein
2014/01/29 20:57:55
SK_OVERRIDE
| |
| 149 // out->append("{\"foo\":1}"); | |
| 150 // } | |
| 151 // private: | |
| 152 // virtual ~MyData() {} | |
| 153 // DISALLOW_COPY_AND_ASSIGN(MyData); | |
| 154 // }; | |
| 155 // | |
| 156 // TRACE_EVENT1("foo", "bar", "data", | |
| 157 // scoped_refptr<ConvertableToTraceFormat>(new MyData())); | |
|
mtklein
2014/01/29 20:57:55
I think we're pretty unlikely to be using scoped_r
| |
| 158 // | |
| 159 // The trace framework will take ownership if the passed pointer and it will | |
| 160 // be free'd when the trace buffer is flushed. | |
| 161 // | |
| 162 // Note, we only do the conversion when the buffer is flushed, so the provided | |
| 163 // data object should not be modified after it's passed to the trace framework. | |
| 164 // | |
| 165 // | |
| 166 // Thread Safety: | |
| 167 // A thread safe singleton and mutex are used for thread safety. Category | |
| 168 // enabled flags are used to limit the performance impact when the system | |
| 169 // is not enabled. | |
| 170 // | |
| 171 // TRACE_EVENT macros first cache a pointer to a category. The categories are | |
| 172 // statically allocated and safe at all times, even after exit. Fetching a | |
| 173 // category is protected by the TraceLog::lock_. Multiple threads initializing | |
| 174 // the static variable is safe, as they will be serialized by the lock and | |
| 175 // multiple calls will return the same pointer to the category. | |
| 176 // | |
| 177 // Then the category_group_enabled flag is checked. This is a unsigned char, and | |
| 178 // not intended to be multithread safe. It optimizes access to AddTraceEvent | |
| 179 // which is threadsafe internally via TraceLog::lock_. The enabled flag may | |
| 180 // cause some threads to incorrectly call or skip calling AddTraceEvent near | |
| 181 // the time of the system being enabled or disabled. This is acceptable as | |
| 182 // we tolerate some data loss while the system is being enabled/disabled and | |
| 183 // because AddTraceEvent is threadsafe internally and checks the enabled state | |
| 184 // again under lock. | |
| 185 // | |
| 186 // Without the use of these static category pointers and enabled flags all | |
| 187 // trace points would carry a significant performance cost of acquiring a lock | |
| 188 // and resolving the category. | |
| 189 | |
| 190 #ifndef SkTraceEvent_DEFINED | |
| 191 #define SkTraceEvent_DEFINED | |
| 192 | |
| 193 #include "SkEventTracer.h" | |
| 194 | |
| 195 // By default, const char* argument values are assumed to have long-lived scope | |
| 196 // and will not be copied. Use this macro to force a const char* to be copied. | |
| 197 #define TRACE_STR_COPY(str) \ | |
| 198 skia::tracing_internals::TraceStringWithCopy(str) | |
| 199 | |
| 200 // This will mark the trace event as disabled by default. The user will need | |
| 201 // to explicitly enable the event. | |
| 202 #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name | |
| 203 | |
| 204 // By default, uint64 ID argument values are not mangled with the Process ID in | |
| 205 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. | |
| 206 #define TRACE_ID_MANGLE(id) \ | |
| 207 skia::tracing_internals::TraceID::ForceMangle(id) | |
| 208 | |
| 209 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC | |
| 210 // macros. Use this macro to prevent Process ID mangling. | |
| 211 #define TRACE_ID_DONT_MANGLE(id) \ | |
| 212 skia::tracing_internals::TraceID::DontMangle(id) | |
| 213 | |
| 214 // Records a pair of begin and end events called "name" for the current | |
| 215 // scope, with 0, 1 or 2 associated arguments. If the category is not | |
| 216 // enabled, then this does nothing. | |
| 217 // - category and name strings must have application lifetime (statics or | |
| 218 // literals). They may not include " chars. | |
| 219 #define TRACE_EVENT0(category_group, name) \ | |
| 220 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name) | |
| 221 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
| 222 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val) | |
| 223 #define TRACE_EVENT2( \ | |
| 224 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | |
| 225 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | |
| 226 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
| 227 | |
| 228 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing. | |
| 229 // Use this where |name| is too generic to accurately aggregate allocations. | |
| 230 #define TRACE_EVENT_WITH_MEMORY_TAG2( \ | |
| 231 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \ | |
| 232 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | |
| 233 category, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
| 234 | |
| 235 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not | |
| 236 // included in official builds. | |
| 237 | |
| 238 #if OFFICIAL_BUILD | |
| 239 #undef TRACING_IS_OFFICIAL_BUILD | |
| 240 #define TRACING_IS_OFFICIAL_BUILD 1 | |
| 241 #elif !defined(TRACING_IS_OFFICIAL_BUILD) | |
| 242 #define TRACING_IS_OFFICIAL_BUILD 0 | |
| 243 #endif | |
| 244 | |
| 245 #if TRACING_IS_OFFICIAL_BUILD | |
| 246 #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0 | |
| 247 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
| 248 (void)0 | |
| 249 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ | |
| 250 arg2_name, arg2_val) (void)0 | |
| 251 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0 | |
| 252 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ | |
| 253 arg1_name, arg1_val) (void)0 | |
| 254 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ | |
| 255 arg1_name, arg1_val, \ | |
| 256 arg2_name, arg2_val) (void)0 | |
| 257 #else | |
| 258 #define UNSHIPPED_TRACE_EVENT0(category_group, name) \ | |
| 259 TRACE_EVENT0(category_group, name) | |
| 260 #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ | |
| 261 TRACE_EVENT1(category_group, name, arg1_name, arg1_val) | |
| 262 #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ | |
| 263 arg2_name, arg2_val) \ | |
| 264 TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) | |
| 265 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \ | |
| 266 TRACE_EVENT_INSTANT0(category_group, name, scope) | |
| 267 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ | |
| 268 arg1_name, arg1_val) \ | |
| 269 TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) | |
| 270 #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ | |
| 271 arg1_name, arg1_val, \ | |
| 272 arg2_name, arg2_val) \ | |
| 273 TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ | |
| 274 arg2_name, arg2_val) | |
| 275 #endif | |
| 276 | |
| 277 // Records a single event called "name" immediately, with 0, 1 or 2 | |
| 278 // associated arguments. If the category is not enabled, then this | |
| 279 // does nothing. | |
| 280 // - category and name strings must have application lifetime (statics or | |
| 281 // literals). They may not include " chars. | |
| 282 #define TRACE_EVENT_INSTANT0(category_group, name, scope) \ | |
| 283 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 284 category_group, name, TRACE_EVENT_FLAG_NONE | scope) | |
| 285 #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \ | |
| 286 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 287 category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ | |
| 288 arg1_name, arg1_val) | |
| 289 #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ | |
| 290 arg2_name, arg2_val) \ | |
| 291 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 292 category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ | |
| 293 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 294 #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \ | |
| 295 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 296 category_group, name, TRACE_EVENT_FLAG_COPY | scope) | |
| 297 #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, \ | |
| 298 arg1_name, arg1_val) \ | |
| 299 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 300 category_group, name, TRACE_EVENT_FLAG_COPY | scope, arg1_name, \ | |
| 301 arg1_val) | |
| 302 #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, \ | |
| 303 arg1_name, arg1_val, \ | |
| 304 arg2_name, arg2_val) \ | |
| 305 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | |
| 306 category_group, name, TRACE_EVENT_FLAG_COPY | scope, \ | |
| 307 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 308 | |
| 309 // Sets the current sample state to the given category and name (both must be | |
| 310 // constant strings). These states are intended for a sampling profiler. | |
| 311 // Implementation note: we store category and name together because we don't | |
| 312 // want the inconsistency/expense of storing two pointers. | |
| 313 // |thread_bucket| is [0..2] and is used to statically isolate samples in one | |
| 314 // thread from others. | |
| 315 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ | |
| 316 bucket_number, category, name) \ | |
| 317 skia::tracing_internals:: \ | |
| 318 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) | |
| 319 | |
| 320 // Returns a current sampling state of the given bucket. | |
| 321 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ | |
| 322 skia::tracing_internals::TraceEventSamplingStateScope<bucket_number>::Curren t() | |
| 323 | |
| 324 // Creates a scope of a sampling state of the given bucket. | |
| 325 // | |
| 326 // { // The sampling state is set within this scope. | |
| 327 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); | |
| 328 // ...; | |
| 329 // } | |
| 330 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ | |
| 331 bucket_number, category, name) \ | |
| 332 skia::tracing_internals::TraceEventSamplingStateScope<bucket_number> \ | |
| 333 traceEventSamplingScope(category "\0" name); | |
| 334 | |
| 335 // Syntactic sugars for the sampling tracing in the main thread. | |
| 336 #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \ | |
| 337 TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name) | |
| 338 #define TRACE_EVENT_GET_SAMPLING_STATE() \ | |
| 339 TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0) | |
| 340 #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \ | |
| 341 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name) | |
| 342 | |
| 343 | |
| 344 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | |
| 345 // associated arguments. If the category is not enabled, then this | |
| 346 // does nothing. | |
| 347 // - category and name strings must have application lifetime (statics or | |
| 348 // literals). They may not include " chars. | |
| 349 #define TRACE_EVENT_BEGIN0(category_group, name) \ | |
| 350 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 351 category_group, name, TRACE_EVENT_FLAG_NONE) | |
| 352 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ | |
| 353 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 354 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 355 #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \ | |
| 356 arg2_name, arg2_val) \ | |
| 357 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 358 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | |
| 359 arg2_name, arg2_val) | |
| 360 #define TRACE_EVENT_COPY_BEGIN0(category_group, name) \ | |
| 361 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 362 category_group, name, TRACE_EVENT_FLAG_COPY) | |
| 363 #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \ | |
| 364 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 365 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
| 366 #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \ | |
| 367 arg2_name, arg2_val) \ | |
| 368 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | |
| 369 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | |
| 370 arg2_name, arg2_val) | |
| 371 | |
| 372 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. | |
| 373 // - |id| is used to match the _BEGIN event with the _END event. | |
| 374 // Events are considered to match if their category_group, name and id values | |
| 375 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
| 376 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
| 377 // that the same pointer on two different processes will not collide. | |
| 378 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ | |
| 379 name, id, thread_id) \ | |
| 380 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
| 381 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ | |
| 382 timestamp, TRACE_EVENT_FLAG_NONE) | |
| 383 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ | |
| 384 category_group, name, id, thread_id) \ | |
| 385 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
| 386 TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ | |
| 387 timestamp, TRACE_EVENT_FLAG_COPY) | |
| 388 | |
| 389 // Records a single END event for "name" immediately. If the category | |
| 390 // is not enabled, then this does nothing. | |
| 391 // - category and name strings must have application lifetime (statics or | |
| 392 // literals). They may not include " chars. | |
| 393 #define TRACE_EVENT_END0(category_group, name) \ | |
| 394 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 395 category_group, name, TRACE_EVENT_FLAG_NONE) | |
| 396 #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \ | |
| 397 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 398 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 399 #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, \ | |
| 400 arg2_name, arg2_val) \ | |
| 401 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 402 category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | |
| 403 arg2_name, arg2_val) | |
| 404 #define TRACE_EVENT_COPY_END0(category_group, name) \ | |
| 405 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 406 category_group, name, TRACE_EVENT_FLAG_COPY) | |
| 407 #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \ | |
| 408 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 409 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
| 410 #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \ | |
| 411 arg2_name, arg2_val) \ | |
| 412 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | |
| 413 category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | |
| 414 arg2_name, arg2_val) | |
| 415 | |
| 416 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. | |
| 417 // - |id| is used to match the _BEGIN event with the _END event. | |
| 418 // Events are considered to match if their category_group, name and id values | |
| 419 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
| 420 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
| 421 // that the same pointer on two different processes will not collide. | |
| 422 #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ | |
| 423 name, id, thread_id) \ | |
| 424 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
| 425 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ | |
| 426 timestamp, TRACE_EVENT_FLAG_NONE) | |
| 427 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ | |
| 428 category_group, name, id, thread_id) \ | |
| 429 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
| 430 TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ | |
| 431 timestamp, TRACE_EVENT_FLAG_COPY) | |
| 432 | |
| 433 // Records the value of a counter called "name" immediately. Value | |
| 434 // must be representable as a 32 bit integer. | |
| 435 // - category and name strings must have application lifetime (statics or | |
| 436 // literals). They may not include " chars. | |
| 437 #define TRACE_COUNTER1(category_group, name, value) \ | |
| 438 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
| 439 category_group, name, TRACE_EVENT_FLAG_NONE, \ | |
| 440 "value", static_cast<int>(value)) | |
| 441 #define TRACE_COPY_COUNTER1(category_group, name, value) \ | |
| 442 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
| 443 category_group, name, TRACE_EVENT_FLAG_COPY, \ | |
| 444 "value", static_cast<int>(value)) | |
| 445 | |
| 446 // Records the values of a multi-parted counter called "name" immediately. | |
| 447 // The UI will treat value1 and value2 as parts of a whole, displaying their | |
| 448 // values as a stacked-bar chart. | |
| 449 // - category and name strings must have application lifetime (statics or | |
| 450 // literals). They may not include " chars. | |
| 451 #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \ | |
| 452 value2_name, value2_val) \ | |
| 453 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
| 454 category_group, name, TRACE_EVENT_FLAG_NONE, \ | |
| 455 value1_name, static_cast<int>(value1_val), \ | |
| 456 value2_name, static_cast<int>(value2_val)) | |
| 457 #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \ | |
| 458 value2_name, value2_val) \ | |
| 459 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | |
| 460 category_group, name, TRACE_EVENT_FLAG_COPY, \ | |
| 461 value1_name, static_cast<int>(value1_val), \ | |
| 462 value2_name, static_cast<int>(value2_val)) | |
| 463 | |
| 464 // Records the value of a counter called "name" immediately. Value | |
| 465 // must be representable as a 32 bit integer. | |
| 466 // - category and name strings must have application lifetime (statics or | |
| 467 // literals). They may not include " chars. | |
| 468 // - |id| is used to disambiguate counters with the same name. It must either | |
| 469 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | |
| 470 // will be xored with a hash of the process ID so that the same pointer on | |
| 471 // two different processes will not collide. | |
| 472 #define TRACE_COUNTER_ID1(category_group, name, id, value) \ | |
| 473 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
| 474 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 475 "value", static_cast<int>(value)) | |
| 476 #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \ | |
| 477 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
| 478 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 479 "value", static_cast<int>(value)) | |
| 480 | |
| 481 // Records the values of a multi-parted counter called "name" immediately. | |
| 482 // The UI will treat value1 and value2 as parts of a whole, displaying their | |
| 483 // values as a stacked-bar chart. | |
| 484 // - category and name strings must have application lifetime (statics or | |
| 485 // literals). They may not include " chars. | |
| 486 // - |id| is used to disambiguate counters with the same name. It must either | |
| 487 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | |
| 488 // will be xored with a hash of the process ID so that the same pointer on | |
| 489 // two different processes will not collide. | |
| 490 #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \ | |
| 491 value2_name, value2_val) \ | |
| 492 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
| 493 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 494 value1_name, static_cast<int>(value1_val), \ | |
| 495 value2_name, static_cast<int>(value2_val)) | |
| 496 #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \ | |
| 497 value1_val, value2_name, value2_val) \ | |
| 498 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ | |
| 499 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 500 value1_name, static_cast<int>(value1_val), \ | |
| 501 value2_name, static_cast<int>(value2_val)) | |
| 502 | |
| 503 | |
| 504 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2 | |
| 505 // associated arguments. If the category is not enabled, then this | |
| 506 // does nothing. | |
| 507 // - category and name strings must have application lifetime (statics or | |
| 508 // literals). They may not include " chars. | |
| 509 // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC | |
| 510 // events are considered to match if their category_group, name and id values | |
| 511 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
| 512 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
| 513 // that the same pointer on two different processes will not collide. | |
| 514 // | |
| 515 // An asynchronous operation can consist of multiple phases. The first phase is | |
| 516 // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the | |
| 517 // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will | |
| 518 // annotate the block following the call. The ASYNC_STEP_PAST macro will | |
| 519 // annotate the block prior to the call. Note that any particular event must use | |
| 520 // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the | |
| 521 // operation completes, call ASYNC_END. | |
| 522 // | |
| 523 // An ASYNC trace typically occurs on a single thread (if not, they will only be | |
| 524 // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that | |
| 525 // operation must use the same |name| and |id|. Each step can have its own | |
| 526 // args. | |
| 527 #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \ | |
| 528 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 529 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
| 530 #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ | |
| 531 arg1_val) \ | |
| 532 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 533 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 534 #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ | |
| 535 arg1_val, arg2_name, arg2_val) \ | |
| 536 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 537 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 538 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 539 #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \ | |
| 540 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 541 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
| 542 #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ | |
| 543 arg1_val) \ | |
| 544 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 545 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 546 arg1_name, arg1_val) | |
| 547 #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ | |
| 548 arg1_val, arg2_name, arg2_val) \ | |
| 549 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 550 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 551 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 552 | |
| 553 // Records a single ASYNC_STEP_INTO event for |step| immediately. If the | |
| 554 // category is not enabled, then this does nothing. The |name| and |id| must | |
| 555 // match the ASYNC_BEGIN event above. The |step| param identifies this step | |
| 556 // within the async event. This should be called at the beginning of the next | |
| 557 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any | |
| 558 // ASYNC_STEP_PAST events. | |
| 559 #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \ | |
| 560 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ | |
| 561 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
| 562 #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \ | |
| 563 arg1_name, arg1_val) \ | |
| 564 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ | |
| 565 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
| 566 arg1_name, arg1_val) | |
| 567 | |
| 568 // Records a single ASYNC_STEP_PAST event for |step| immediately. If the | |
| 569 // category is not enabled, then this does nothing. The |name| and |id| must | |
| 570 // match the ASYNC_BEGIN event above. The |step| param identifies this step | |
| 571 // within the async event. This should be called at the beginning of the next | |
| 572 // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any | |
| 573 // ASYNC_STEP_INTO events. | |
| 574 #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \ | |
| 575 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ | |
| 576 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
| 577 #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \ | |
| 578 arg1_name, arg1_val) \ | |
| 579 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ | |
| 580 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
| 581 arg1_name, arg1_val) | |
| 582 | |
| 583 // Records a single ASYNC_END event for "name" immediately. If the category | |
| 584 // is not enabled, then this does nothing. | |
| 585 #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \ | |
| 586 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 587 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
| 588 #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \ | |
| 589 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 590 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 591 #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \ | |
| 592 arg2_name, arg2_val) \ | |
| 593 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 594 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 595 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 596 #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \ | |
| 597 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 598 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
| 599 #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \ | |
| 600 arg1_val) \ | |
| 601 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 602 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 603 arg1_name, arg1_val) | |
| 604 #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \ | |
| 605 arg1_val, arg2_name, arg2_val) \ | |
| 606 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 607 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 608 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 609 | |
| 610 | |
| 611 // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2 | |
| 612 // associated arguments. If the category is not enabled, then this | |
| 613 // does nothing. | |
| 614 // - category and name strings must have application lifetime (statics or | |
| 615 // literals). They may not include " chars. | |
| 616 // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW | |
| 617 // events are considered to match if their category_group, name and id values | |
| 618 // all match. |id| must either be a pointer or an integer value up to 64 bits. | |
| 619 // If it's a pointer, the bits will be xored with a hash of the process ID so | |
| 620 // that the same pointer on two different processes will not collide. | |
| 621 // FLOW events are different from ASYNC events in how they are drawn by the | |
| 622 // tracing UI. A FLOW defines asynchronous data flow, such as posting a task | |
| 623 // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be | |
| 624 // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar | |
| 625 // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined | |
| 626 // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP | |
| 627 // macros. When the operation completes, call FLOW_END. An async operation can | |
| 628 // span threads and processes, but all events in that operation must use the | |
| 629 // same |name| and |id|. Each event can have its own args. | |
| 630 #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \ | |
| 631 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 632 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
| 633 #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \ | |
| 634 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 635 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 636 #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \ | |
| 637 arg2_name, arg2_val) \ | |
| 638 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 639 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 640 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 641 #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \ | |
| 642 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 643 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
| 644 #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \ | |
| 645 arg1_val) \ | |
| 646 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 647 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 648 arg1_name, arg1_val) | |
| 649 #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \ | |
| 650 arg1_val, arg2_name, arg2_val) \ | |
| 651 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ | |
| 652 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 653 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 654 | |
| 655 // Records a single FLOW_STEP event for |step| immediately. If the category | |
| 656 // is not enabled, then this does nothing. The |name| and |id| must match the | |
| 657 // FLOW_BEGIN event above. The |step| param identifies this step within the | |
| 658 // async event. This should be called at the beginning of the next phase of an | |
| 659 // asynchronous operation. | |
| 660 #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \ | |
| 661 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
| 662 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) | |
| 663 #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, \ | |
| 664 arg1_name, arg1_val) \ | |
| 665 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
| 666 category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ | |
| 667 arg1_name, arg1_val) | |
| 668 #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \ | |
| 669 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
| 670 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step) | |
| 671 #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, \ | |
| 672 arg1_name, arg1_val) \ | |
| 673 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ | |
| 674 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ | |
| 675 arg1_name, arg1_val) | |
| 676 | |
| 677 // Records a single FLOW_END event for "name" immediately. If the category | |
| 678 // is not enabled, then this does nothing. | |
| 679 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \ | |
| 680 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 681 category_group, name, id, TRACE_EVENT_FLAG_NONE) | |
| 682 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \ | |
| 683 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 684 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 685 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \ | |
| 686 arg2_name, arg2_val) \ | |
| 687 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 688 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ | |
| 689 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 690 #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \ | |
| 691 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 692 category_group, name, id, TRACE_EVENT_FLAG_COPY) | |
| 693 #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \ | |
| 694 arg1_val) \ | |
| 695 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 696 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 697 arg1_name, arg1_val) | |
| 698 #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \ | |
| 699 arg1_val, arg2_name, arg2_val) \ | |
| 700 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | |
| 701 category_group, name, id, TRACE_EVENT_FLAG_COPY, \ | |
| 702 arg1_name, arg1_val, arg2_name, arg2_val) | |
| 703 | |
| 704 // Macros to track the life time and value of arbitrary client objects. | |
| 705 // See also TraceTrackableObject. | |
| 706 #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \ | |
| 707 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_CREATE_OBJECT, \ | |
| 708 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) | |
| 709 | |
| 710 #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) \ | |
| 711 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \ | |
| 712 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\ | |
| 713 "snapshot", snapshot) | |
| 714 | |
| 715 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \ | |
| 716 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \ | |
| 717 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) | |
| 718 | |
| 719 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | |
| 720 *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ | |
| 721 (skia::tracing::SkEventTracer::ENABLED_FOR_RECORDING | \ | |
| 722 skia::tracing::SkEventTracer::ENABLED_FOR_EVENT_CALLBACK) | |
| 723 | |
| 724 // Macro to efficiently determine if a given category group is enabled. | |
| 725 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \ | |
| 726 do { \ | |
| 727 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
| 728 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
| 729 *ret = true; \ | |
| 730 } else { \ | |
| 731 *ret = false; \ | |
| 732 } \ | |
| 733 } while (0) | |
| 734 | |
| 735 // Macro to efficiently determine, through polling, if a new trace has begun. | |
| 736 #define TRACE_EVENT_IS_NEW_TRACE(ret) \ | |
| 737 do { \ | |
| 738 static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \ | |
| 739 int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \ | |
| 740 if (num_traces_recorded != -1 && \ | |
| 741 num_traces_recorded != \ | |
| 742 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \ | |
| 743 INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = \ | |
| 744 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 unsigned char* | |
| 763 // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group) | |
| 764 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ | |
| 765 skia::tracing::SkEventTracer::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 skia::tracing::SkEventTracer::GetInstance()->GetNumTracesRecorded | |
| 772 | |
| 773 // Add a trace event to the platform tracing system. | |
| 774 // skia::tracing::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 775 // char phase, | |
| 776 // const unsigned char* category_group_enabled, | |
| 777 // const char* name, | |
| 778 // unsigned long long id, | |
| 779 // int num_args, | |
| 780 // const char** arg_names, | |
| 781 // const unsigned char* arg_types, | |
| 782 // const unsigned long long* arg_values, | |
| 783 // unsigned char flags) | |
| 784 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | |
| 785 skia::tracing::SkEventTracer::GetInstance()->AddTraceEvent | |
| 786 | |
| 787 // Set the duration field of a COMPLETE trace event. | |
| 788 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | |
| 789 // const unsigned char* category_group_enabled, | |
| 790 // const char* name, | |
| 791 // skia::tracing::TraceEventHandle id) | |
| 792 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | |
| 793 skia::tracing::SkEventTracer::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 SK_API | |
| 807 | |
| 808 // The thread buckets for the sampling profiler. | |
| 809 TRACE_EVENT_API_CLASS_EXPORT extern \ | |
| 810 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; | |
| 811 | |
| 812 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ | |
| 813 g_trace_state[thread_bucket] | |
| 814 | |
| 815 //////////////////////////////////////////////////////////////////////////////// | |
| 816 | |
| 817 // Implementation detail: trace event macros create temporary variables | |
| 818 // to keep instrumentation overhead low. These macros give each temporary | |
| 819 // variable a unique name based on the line number to prevent name collisions. | |
| 820 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | |
| 821 trace_event_unique_##a##b | |
| 822 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | |
| 823 INTERNAL_TRACE_EVENT_UID3(a,b) | |
| 824 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | |
| 825 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) | |
| 826 | |
| 827 // Implementation detail: internal macro to create static category. | |
| 828 // No barriers are needed, because this code is designed to operate safely | |
| 829 // even when the unsigned char* points to garbage data (which may be the case | |
| 830 // on processors without cache coherency). | |
| 831 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \ | |
| 832 category_group, atomic, category_group_enabled) \ | |
| 833 category_group_enabled = \ | |
| 834 reinterpret_cast<const unsigned char*>(TRACE_EVENT_API_ATOMIC_LOAD( \ | |
| 835 atomic)); \ | |
| 836 if (!category_group_enabled) { \ | |
| 837 category_group_enabled = \ | |
| 838 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \ | |
| 839 TRACE_EVENT_API_ATOMIC_STORE(atomic, \ | |
| 840 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \ | |
| 841 category_group_enabled)); \ | |
| 842 } | |
| 843 | |
| 844 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ | |
| 845 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ | |
| 846 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ | |
| 847 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \ | |
| 848 INTERNAL_TRACE_EVENT_UID(atomic), \ | |
| 849 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); | |
| 850 | |
| 851 // Implementation detail: internal macro to create static category and add | |
| 852 // event if the category is enabled. | |
| 853 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ | |
| 854 do { \ | |
| 855 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
| 856 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
| 857 skia::tracing_internals::AddTraceEvent( \ | |
| 858 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | |
| 859 skia::tracing_internals::kNoEventId, flags, ##__VA_ARGS__); \ | |
| 860 } \ | |
| 861 } while (0) | |
| 862 | |
| 863 // Implementation detail: internal macro to create static category and add begin | |
| 864 // event if the category is enabled. Also adds the end event when the scope | |
| 865 // ends. | |
| 866 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ | |
| 867 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
| 868 skia::tracing_internals::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ | |
| 869 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
| 870 skia::tracing::TraceEventHandle h = skia::tracing_internals::AddTraceEvent ( \ | |
| 871 TRACE_EVENT_PHASE_COMPLETE, \ | |
| 872 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
| 873 name, skia::tracing_internals::kNoEventId, \ | |
| 874 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ | |
| 875 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ | |
| 876 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ | |
| 877 } | |
| 878 | |
| 879 // Implementation detail: internal macro to create static category and add | |
| 880 // event if the category is enabled. | |
| 881 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ | |
| 882 flags, ...) \ | |
| 883 do { \ | |
| 884 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
| 885 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
| 886 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
| 887 skia::tracing_internals::TraceID trace_event_trace_id( \ | |
| 888 id, &trace_event_flags); \ | |
| 889 skia::tracing_internals::AddTraceEvent( \ | |
| 890 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
| 891 name, trace_event_trace_id.data(), trace_event_flags, \ | |
| 892 ##__VA_ARGS__); \ | |
| 893 } \ | |
| 894 } while (0) | |
| 895 | |
| 896 // Implementation detail: internal macro to create static category and add | |
| 897 // event if the category is enabled. | |
| 898 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ | |
| 899 category_group, name, id, thread_id, flags, ...) \ | |
| 900 do { \ | |
| 901 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | |
| 902 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | |
| 903 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
| 904 skia::tracing_internals::TraceID trace_event_trace_id( \ | |
| 905 id, &trace_event_flags); \ | |
| 906 skia::tracing_internals::AddTraceEventWithThreadIdAndTimestamp( \ | |
| 907 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
| 908 name, trace_event_trace_id.data(), \ | |
| 909 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ | |
| 910 trace_event_flags, ##__VA_ARGS__); \ | |
| 911 } \ | |
| 912 } while (0) | |
| 913 | |
| 914 // Notes regarding the following definitions: | |
| 915 // New values can be added and propagated to third party libraries, but existing | |
| 916 // definitions must never be changed, because third party libraries may use old | |
| 917 // definitions. | |
| 918 | |
| 919 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | |
| 920 #define TRACE_EVENT_PHASE_BEGIN ('B') | |
| 921 #define TRACE_EVENT_PHASE_END ('E') | |
| 922 #define TRACE_EVENT_PHASE_COMPLETE ('X') | |
| 923 #define TRACE_EVENT_PHASE_INSTANT ('i') | |
| 924 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') | |
| 925 #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T') | |
| 926 #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p') | |
| 927 #define TRACE_EVENT_PHASE_ASYNC_END ('F') | |
| 928 #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s') | |
| 929 #define TRACE_EVENT_PHASE_FLOW_STEP ('t') | |
| 930 #define TRACE_EVENT_PHASE_FLOW_END ('f') | |
| 931 #define TRACE_EVENT_PHASE_METADATA ('M') | |
| 932 #define TRACE_EVENT_PHASE_COUNTER ('C') | |
| 933 #define TRACE_EVENT_PHASE_SAMPLE ('P') | |
| 934 #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N') | |
| 935 #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O') | |
| 936 #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D') | |
| 937 | |
| 938 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. | |
| 939 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned char>(0)) | |
| 940 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned char>(1 << 0)) | |
| 941 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned char>(1 << 1)) | |
| 942 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned char>(1 << 2)) | |
| 943 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned char>(1 << 3)) | |
| 944 | |
| 945 #define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast<unsigned char>( \ | |
| 946 TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1))) | |
| 947 | |
| 948 // Type values for identifying types in the TraceValue union. | |
| 949 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) | |
| 950 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) | |
| 951 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) | |
| 952 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) | |
| 953 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) | |
| 954 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) | |
| 955 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) | |
| 956 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) | |
| 957 | |
| 958 // Enum reflecting the scope of an INSTANT event. Must fit within | |
| 959 // TRACE_EVENT_FLAG_SCOPE_MASK. | |
| 960 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) | |
| 961 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) | |
| 962 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) | |
| 963 | |
| 964 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') | |
| 965 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') | |
| 966 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') | |
| 967 | |
| 968 namespace skia { | |
| 969 namespace tracing_internals { | |
| 970 | |
| 971 // Specify these values when the corresponding argument of AddTraceEvent is not | |
| 972 // used. | |
| 973 const int kZeroNumArgs = 0; | |
| 974 const unsigned long long kNoEventId = 0; | |
| 975 | |
| 976 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | |
| 977 // are by default mangled with the Process ID so that they are unlikely to | |
| 978 // collide when the same pointer is used on different processes. | |
| 979 class TraceID { | |
| 980 public: | |
| 981 class DontMangle { | |
| 982 public: | |
| 983 explicit DontMangle(const void* id) | |
| 984 : data_(static_cast<unsigned long long>( | |
| 985 reinterpret_cast<unsigned long>(id))) {} | |
| 986 explicit DontMangle(unsigned long long id) : data_(id) {} | |
| 987 explicit DontMangle(unsigned long id) : data_(id) {} | |
| 988 explicit DontMangle(unsigned int id) : data_(id) {} | |
| 989 explicit DontMangle(unsigned short id) : data_(id) {} | |
| 990 explicit DontMangle(unsigned char id) : data_(id) {} | |
| 991 explicit DontMangle(long long id) | |
| 992 : data_(static_cast<unsigned long long>(id)) {} | |
| 993 explicit DontMangle(long id) | |
| 994 : data_(static_cast<unsigned long long>(id)) {} | |
| 995 explicit DontMangle(int id) | |
| 996 : data_(static_cast<unsigned long long>(id)) {} | |
| 997 explicit DontMangle(short id) | |
| 998 : data_(static_cast<unsigned long long>(id)) {} | |
| 999 explicit DontMangle(signed char id) | |
| 1000 : data_(static_cast<unsigned long long>(id)) {} | |
| 1001 unsigned long long data() const { return data_; } | |
| 1002 private: | |
| 1003 unsigned long long data_; | |
| 1004 }; | |
| 1005 | |
| 1006 class ForceMangle { | |
| 1007 public: | |
| 1008 explicit ForceMangle(unsigned long long id) : data_(id) {} | |
| 1009 explicit ForceMangle(unsigned long id) : data_(id) {} | |
| 1010 explicit ForceMangle(unsigned int id) : data_(id) {} | |
| 1011 explicit ForceMangle(unsigned short id) : data_(id) {} | |
| 1012 explicit ForceMangle(unsigned char id) : data_(id) {} | |
| 1013 explicit ForceMangle(long long id) | |
| 1014 : data_(static_cast<unsigned long long>(id)) {} | |
| 1015 explicit ForceMangle(long id) | |
| 1016 : data_(static_cast<unsigned long long>(id)) {} | |
| 1017 explicit ForceMangle(int id) | |
| 1018 : data_(static_cast<unsigned long long>(id)) {} | |
| 1019 explicit ForceMangle(short id) | |
| 1020 : data_(static_cast<unsigned long long>(id)) {} | |
| 1021 explicit ForceMangle(signed char id) | |
| 1022 : data_(static_cast<unsigned long long>(id)) {} | |
| 1023 unsigned long long data() const { return data_; } | |
| 1024 private: | |
| 1025 unsigned long long data_; | |
| 1026 }; | |
| 1027 | |
| 1028 TraceID(const void* id, unsigned char* flags) | |
| 1029 : data_(static_cast<unsigned long long>( | |
| 1030 reinterpret_cast<unsigned long>(id))) { | |
| 1031 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | |
| 1032 } | |
| 1033 TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) { | |
| 1034 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | |
| 1035 } | |
| 1036 TraceID(DontMangle id, unsigned char* flags) : data_(id.data()) { | |
| 1037 } | |
| 1038 TraceID(unsigned long long id, unsigned char* flags) | |
| 1039 : data_(id) { (void)flags; } | |
| 1040 TraceID(unsigned long id, unsigned char* flags) | |
| 1041 : data_(id) { (void)flags; } | |
| 1042 TraceID(unsigned int id, unsigned char* flags) | |
| 1043 : data_(id) { (void)flags; } | |
| 1044 TraceID(unsigned short id, unsigned char* flags) | |
| 1045 : data_(id) { (void)flags; } | |
| 1046 TraceID(unsigned char id, unsigned char* flags) | |
| 1047 : data_(id) { (void)flags; } | |
| 1048 TraceID(long long id, unsigned char* flags) | |
| 1049 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
| 1050 TraceID(long id, unsigned char* flags) | |
| 1051 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
| 1052 TraceID(int id, unsigned char* flags) | |
| 1053 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
| 1054 TraceID(short id, unsigned char* flags) | |
| 1055 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
| 1056 TraceID(signed char id, unsigned char* flags) | |
| 1057 : data_(static_cast<unsigned long long>(id)) { (void)flags; } | |
| 1058 | |
| 1059 unsigned long long data() const { return data_; } | |
| 1060 | |
| 1061 private: | |
| 1062 unsigned long long data_; | |
| 1063 }; | |
| 1064 | |
| 1065 // Simple union to store various types as unsigned long long. | |
| 1066 union TraceValueUnion { | |
| 1067 bool as_bool; | |
| 1068 unsigned long long as_uint; | |
| 1069 long long as_int; | |
| 1070 double as_double; | |
| 1071 const void* as_pointer; | |
| 1072 const char* as_string; | |
| 1073 }; | |
| 1074 | |
| 1075 // Simple container for const char* that should be copied instead of retained. | |
| 1076 class TraceStringWithCopy { | |
| 1077 public: | |
| 1078 explicit TraceStringWithCopy(const char* str) : str_(str) {} | |
| 1079 operator const char* () const { return str_; } | |
| 1080 private: | |
| 1081 const char* str_; | |
| 1082 }; | |
| 1083 | |
| 1084 // Define SetTraceValue for each allowed type. It stores the type and | |
| 1085 // value in the return arguments. This allows this API to avoid declaring any | |
| 1086 // structures so that it is portable to third_party libraries. | |
| 1087 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ | |
| 1088 union_member, \ | |
| 1089 value_type_id) \ | |
| 1090 static inline void SetTraceValue( \ | |
| 1091 actual_type arg, \ | |
| 1092 unsigned char* type, \ | |
| 1093 unsigned long long* value) { \ | |
| 1094 TraceValueUnion type_value; \ | |
| 1095 type_value.union_member = arg; \ | |
| 1096 *type = value_type_id; \ | |
| 1097 *value = type_value.as_uint; \ | |
| 1098 } | |
| 1099 // Simpler form for int types that can be safely casted. | |
| 1100 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ | |
| 1101 value_type_id) \ | |
| 1102 static inline void SetTraceValue( \ | |
| 1103 actual_type arg, \ | |
| 1104 unsigned char* type, \ | |
| 1105 unsigned long long* value) { \ | |
| 1106 *type = value_type_id; \ | |
| 1107 *value = static_cast<unsigned long long>(arg); \ | |
| 1108 } | |
| 1109 | |
| 1110 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) | |
| 1111 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) | |
| 1112 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) | |
| 1113 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) | |
| 1114 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) | |
| 1115 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) | |
| 1116 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) | |
| 1117 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) | |
| 1118 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) | |
| 1119 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) | |
| 1120 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) | |
| 1121 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) | |
| 1122 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | |
| 1123 TRACE_VALUE_TYPE_POINTER) | |
| 1124 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | |
| 1125 TRACE_VALUE_TYPE_STRING) | |
| 1126 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | |
| 1127 TRACE_VALUE_TYPE_COPY_STRING) | |
| 1128 | |
| 1129 #undef INTERNAL_DECLARE_SET_TRACE_VALUE | |
| 1130 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT | |
| 1131 | |
| 1132 // std::string version of SetTraceValue so that trace arguments can be strings. | |
| 1133 static inline void SetTraceValue(const std::string& arg, | |
| 1134 unsigned char* type, | |
| 1135 unsigned long long* value) { | |
| 1136 TraceValueUnion type_value; | |
| 1137 type_value.as_string = arg.c_str(); | |
| 1138 *type = TRACE_VALUE_TYPE_COPY_STRING; | |
| 1139 *value = type_value.as_uint; | |
| 1140 } | |
| 1141 | |
| 1142 // These AddTraceEvent and AddTraceEvent template | |
| 1143 // functions are defined here instead of in the macro, because the arg_values | |
| 1144 // could be temporary objects, such as std::string. In order to store | |
| 1145 // pointers to the internal c_str and pass through to the tracing API, | |
| 1146 // the arg_values must live throughout these procedures. | |
| 1147 | |
| 1148 static inline skia::tracing::TraceEventHandle | |
| 1149 AddTraceEvent( | |
| 1150 char phase, | |
| 1151 const unsigned char* category_group_enabled, | |
| 1152 const char* name, | |
| 1153 unsigned long long id, | |
| 1154 unsigned char flags) { | |
| 1155 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 1156 phase, category_group_enabled, name, id, | |
| 1157 kZeroNumArgs, NULL, NULL, NULL, flags); | |
| 1158 } | |
| 1159 | |
| 1160 template<class ARG1_TYPE> | |
| 1161 static inline skia::tracing::TraceEventHandle | |
| 1162 AddTraceEvent( | |
| 1163 char phase, | |
| 1164 const unsigned char* category_group_enabled, | |
| 1165 const char* name, | |
| 1166 unsigned long long id, | |
| 1167 unsigned char flags, | |
| 1168 const char* arg1_name, | |
| 1169 const ARG1_TYPE& arg1_val) { | |
| 1170 const int num_args = 1; | |
| 1171 unsigned char arg_types[1]; | |
| 1172 unsigned long long arg_values[1]; | |
| 1173 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
| 1174 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 1175 phase, category_group_enabled, name, id, | |
| 1176 num_args, &arg1_name, arg_types, arg_values, flags); | |
| 1177 } | |
| 1178 | |
| 1179 template<class ARG1_TYPE, class ARG2_TYPE> | |
| 1180 static inline skia::tracing::TraceEventHandle | |
| 1181 AddTraceEvent( | |
| 1182 char phase, | |
| 1183 const unsigned char* category_group_enabled, | |
| 1184 const char* name, | |
| 1185 unsigned long long id, | |
| 1186 unsigned char flags, | |
| 1187 const char* arg1_name, | |
| 1188 const ARG1_TYPE& arg1_val, | |
| 1189 const char* arg2_name, | |
| 1190 const ARG2_TYPE& arg2_val) { | |
| 1191 const int num_args = 2; | |
| 1192 const char* arg_names[2] = { arg1_name, arg2_name }; | |
| 1193 unsigned char arg_types[2]; | |
| 1194 unsigned long long arg_values[2]; | |
| 1195 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
| 1196 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | |
| 1197 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 1198 phase, category_group_enabled, name, id, | |
| 1199 num_args, arg_names, arg_types, arg_values, flags); | |
| 1200 } | |
| 1201 | |
| 1202 // Used by TRACE_EVENTx macros. Do not use directly. | |
| 1203 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | |
| 1204 public: | |
| 1205 // Note: members of data_ intentionally left uninitialized. See Initialize. | |
| 1206 ScopedTracer() : p_data_(NULL) {} | |
| 1207 | |
| 1208 ~ScopedTracer() { | |
| 1209 if (p_data_ && *data_.category_group_enabled) | |
| 1210 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | |
| 1211 data_.category_group_enabled, data_.name, data_.event_handle); | |
| 1212 } | |
| 1213 | |
| 1214 void Initialize(const unsigned char* category_group_enabled, | |
| 1215 const char* name, | |
| 1216 skia::tracing::TraceEventHandle event_handle) { | |
| 1217 data_.category_group_enabled = category_group_enabled; | |
| 1218 data_.name = name; | |
| 1219 data_.event_handle = event_handle; | |
| 1220 p_data_ = &data_; | |
| 1221 } | |
| 1222 | |
| 1223 private: | |
| 1224 // This Data struct workaround is to avoid initializing all the members | |
| 1225 // in Data during construction of this object, since this object is always | |
| 1226 // constructed, even when tracing is disabled. If the members of Data were | |
| 1227 // members of this class instead, compiler warnings occur about potential | |
| 1228 // uninitialized accesses. | |
| 1229 struct Data { | |
| 1230 const unsigned char* category_group_enabled; | |
| 1231 const char* name; | |
| 1232 skia::tracing::TraceEventHandle event_handle; | |
| 1233 }; | |
| 1234 Data* p_data_; | |
| 1235 Data data_; | |
| 1236 }; | |
| 1237 | |
| 1238 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. | |
| 1239 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient { | |
| 1240 public: | |
| 1241 ScopedTraceBinaryEfficient(const char* category_group, const char* name); | |
| 1242 ~ScopedTraceBinaryEfficient(); | |
| 1243 | |
| 1244 private: | |
| 1245 const unsigned char* category_group_enabled_; | |
| 1246 const char* name_; | |
| 1247 skia::tracing::TraceEventHandle event_handle_; | |
| 1248 }; | |
| 1249 | |
| 1250 // This macro generates less code then TRACE_EVENT0 but is also | |
| 1251 // slower to execute when tracing is off. It should generally only be | |
| 1252 // used with code that is seldom executed or conditionally executed | |
| 1253 // when debugging. | |
| 1254 // For now the category_group must be "gpu". | |
| 1255 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ | |
| 1256 skia::tracing_internals::ScopedTraceBinaryEfficient \ | |
| 1257 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name); | |
| 1258 | |
| 1259 // TraceEventSamplingStateScope records the current sampling state | |
| 1260 // and sets a new sampling state. When the scope exists, it restores | |
| 1261 // the sampling state having recorded. | |
| 1262 template<size_t BucketNumber> | |
| 1263 class TraceEventSamplingStateScope { | |
| 1264 public: | |
| 1265 TraceEventSamplingStateScope(const char* category_and_name) { | |
| 1266 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current(); | |
| 1267 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name); | |
| 1268 } | |
| 1269 | |
| 1270 ~TraceEventSamplingStateScope() { | |
| 1271 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_); | |
| 1272 } | |
| 1273 | |
| 1274 static inline const char* Current() { | |
| 1275 return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( | |
| 1276 g_trace_state[BucketNumber])); | |
| 1277 } | |
| 1278 | |
| 1279 static inline void Set(const char* category_and_name) { | |
| 1280 TRACE_EVENT_API_ATOMIC_STORE( | |
| 1281 g_trace_state[BucketNumber], | |
| 1282 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | |
| 1283 const_cast<char*>(category_and_name))); | |
| 1284 } | |
| 1285 | |
| 1286 private: | |
| 1287 const char* previous_state_; | |
| 1288 }; | |
| 1289 | |
| 1290 } // namespace tracing_internals | |
| 1291 } // namespace skia | |
| 1292 | |
| 1293 #endif | |
| OLD | NEW |