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