michael@0: // Copyright (c) 2014 Google Inc. michael@0: // michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: // This header file defines the set of trace_event macros without specifying michael@0: // how the events actually get collected and stored. If you need to expose trace michael@0: // events to some other universe, you can copy-and-paste this file as well as michael@0: // trace_event.h, modifying the macros contained there as necessary for the michael@0: // target platform. The end result is that multiple libraries can funnel events michael@0: // through to a shared trace event collector. michael@0: michael@0: // Trace events are for tracking application performance and resource usage. michael@0: // Macros are provided to track: michael@0: // Begin and end of function calls michael@0: // Counters michael@0: // michael@0: // Events are issued against categories. Whereas LOG's michael@0: // categories are statically defined, TRACE categories are created michael@0: // implicitly with a string. For example: michael@0: // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent", michael@0: // TRACE_EVENT_SCOPE_THREAD) michael@0: // michael@0: // It is often the case that one trace may belong in multiple categories at the michael@0: // same time. The first argument to the trace can be a comma-separated list of michael@0: // categories, forming a category group, like: michael@0: // michael@0: // TRACE_EVENT_INSTANT0("input,views", "OnMouseOver", TRACE_EVENT_SCOPE_THREAD) michael@0: // michael@0: // We can enable/disable tracing of OnMouseOver by enabling/disabling either michael@0: // category. michael@0: // michael@0: // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: michael@0: // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") michael@0: // doSomethingCostly() michael@0: // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") michael@0: // Note: our tools can't always determine the correct BEGIN/END pairs unless michael@0: // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you michael@0: // need them to be in separate scopes. michael@0: // michael@0: // A common use case is to trace entire function scopes. This michael@0: // issues a trace BEGIN and END automatically: michael@0: // void doSomethingCostly() { michael@0: // TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly"); michael@0: // ... michael@0: // } michael@0: // michael@0: // Additional parameters can be associated with an event: michael@0: // void doSomethingCostly2(int howMuch) { michael@0: // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", michael@0: // "howMuch", howMuch); michael@0: // ... michael@0: // } michael@0: // michael@0: // The trace system will automatically add to this information the michael@0: // current process id, thread id, and a timestamp in microseconds. michael@0: // michael@0: // To trace an asynchronous procedure such as an IPC send/receive, use michael@0: // ASYNC_BEGIN and ASYNC_END: michael@0: // [single threaded sender code] michael@0: // static int send_count = 0; michael@0: // ++send_count; michael@0: // TRACE_EVENT_ASYNC_BEGIN0("ipc", "message", send_count); michael@0: // Send(new MyMessage(send_count)); michael@0: // [receive code] michael@0: // void OnMyMessage(send_count) { michael@0: // TRACE_EVENT_ASYNC_END0("ipc", "message", send_count); michael@0: // } michael@0: // The third parameter is a unique ID to match ASYNC_BEGIN/ASYNC_END pairs. michael@0: // ASYNC_BEGIN and ASYNC_END can occur on any thread of any traced process. michael@0: // Pointers can be used for the ID parameter, and they will be mangled michael@0: // internally so that the same pointer on two different processes will not michael@0: // match. For example: michael@0: // class MyTracedClass { michael@0: // public: michael@0: // MyTracedClass() { michael@0: // TRACE_EVENT_ASYNC_BEGIN0("category", "MyTracedClass", this); michael@0: // } michael@0: // ~MyTracedClass() { michael@0: // TRACE_EVENT_ASYNC_END0("category", "MyTracedClass", this); michael@0: // } michael@0: // } michael@0: // michael@0: // Trace event also supports counters, which is a way to track a quantity michael@0: // as it varies over time. Counters are created with the following macro: michael@0: // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue); michael@0: // michael@0: // Counters are process-specific. The macro itself can be issued from any michael@0: // thread, however. michael@0: // michael@0: // Sometimes, you want to track two counters at once. You can do this with two michael@0: // counter macros: michael@0: // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]); michael@0: // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]); michael@0: // Or you can do it with a combined macro: michael@0: // TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter", michael@0: // "bytesPinned", g_myCounterValue[0], michael@0: // "bytesAllocated", g_myCounterValue[1]); michael@0: // This indicates to the tracing UI that these counters should be displayed michael@0: // in a single graph, as a summed area chart. michael@0: // michael@0: // Since counters are in a global namespace, you may want to disambiguate with a michael@0: // unique ID, by using the TRACE_COUNTER_ID* variations. michael@0: // michael@0: // By default, trace collection is compiled in, but turned off at runtime. michael@0: // Collecting trace data is the responsibility of the embedding michael@0: // application. In Chrome's case, navigating to about:tracing will turn on michael@0: // tracing and display data collected across all active processes. michael@0: // michael@0: // michael@0: // Memory scoping note: michael@0: // Tracing copies the pointers, not the string content, of the strings passed michael@0: // in for category_group, name, and arg_names. Thus, the following code will michael@0: // cause problems: michael@0: // char* str = strdup("importantName"); michael@0: // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! michael@0: // free(str); // Trace system now has dangling pointer michael@0: // michael@0: // To avoid this issue with the |name| and |arg_name| parameters, use the michael@0: // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. michael@0: // Notes: The category must always be in a long-lived char* (i.e. static const). michael@0: // The |arg_values|, when used, are always deep copied with the _COPY michael@0: // macros. michael@0: // michael@0: // When are string argument values copied: michael@0: // const char* arg_values are only referenced by default: michael@0: // TRACE_EVENT1("category", "name", michael@0: // "arg1", "literal string is only referenced"); michael@0: // Use TRACE_STR_COPY to force copying of a const char*: michael@0: // TRACE_EVENT1("category", "name", michael@0: // "arg1", TRACE_STR_COPY("string will be copied")); michael@0: // std::string arg_values are always copied: michael@0: // TRACE_EVENT1("category", "name", michael@0: // "arg1", std::string("string will be copied")); michael@0: // michael@0: // michael@0: // Thread Safety: michael@0: // A thread safe singleton and mutex are used for thread safety. Category michael@0: // enabled flags are used to limit the performance impact when the system michael@0: // is not enabled. michael@0: // michael@0: // TRACE_EVENT macros first cache a pointer to a category. The categories are michael@0: // statically allocated and safe at all times, even after exit. Fetching a michael@0: // category is protected by the TraceLog::lock_. Multiple threads initializing michael@0: // the static variable is safe, as they will be serialized by the lock and michael@0: // multiple calls will return the same pointer to the category. michael@0: // michael@0: // Then the category_group_enabled flag is checked. This is a unsigned char, and michael@0: // not intended to be multithread safe. It optimizes access to AddTraceEvent michael@0: // which is threadsafe internally via TraceLog::lock_. The enabled flag may michael@0: // cause some threads to incorrectly call or skip calling AddTraceEvent near michael@0: // the time of the system being enabled or disabled. This is acceptable as michael@0: // we tolerate some data loss while the system is being enabled/disabled and michael@0: // because AddTraceEvent is threadsafe internally and checks the enabled state michael@0: // again under lock. michael@0: // michael@0: // Without the use of these static category pointers and enabled flags all michael@0: // trace points would carry a significant performance cost of acquiring a lock michael@0: // and resolving the category. michael@0: michael@0: #ifndef SkTraceEvent_DEFINED michael@0: #define SkTraceEvent_DEFINED michael@0: michael@0: #include "SkEventTracer.h" michael@0: michael@0: // By default, const char* argument values are assumed to have long-lived scope michael@0: // and will not be copied. Use this macro to force a const char* to be copied. michael@0: #define TRACE_STR_COPY(str) \ michael@0: skia::tracing_internals::TraceStringWithCopy(str) michael@0: michael@0: // By default, uint64 ID argument values are not mangled with the Process ID in michael@0: // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. michael@0: #define TRACE_ID_MANGLE(id) \ michael@0: skia::tracing_internals::TraceID::ForceMangle(id) michael@0: michael@0: // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC michael@0: // macros. Use this macro to prevent Process ID mangling. michael@0: #define TRACE_ID_DONT_MANGLE(id) \ michael@0: skia::tracing_internals::TraceID::DontMangle(id) michael@0: michael@0: // Records a pair of begin and end events called "name" for the current michael@0: // scope, with 0, 1 or 2 associated arguments. If the category is not michael@0: // enabled, then this does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_EVENT0(category_group, name) \ michael@0: INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name) michael@0: #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val) michael@0: #define TRACE_EVENT2( \ michael@0: category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_SCOPED( \ michael@0: category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing. michael@0: // Use this where |name| is too generic to accurately aggregate allocations. michael@0: #define TRACE_EVENT_WITH_MEMORY_TAG2( \ michael@0: category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_SCOPED( \ michael@0: category, name, arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not michael@0: // included in official builds. michael@0: michael@0: #if OFFICIAL_BUILD michael@0: #undef TRACING_IS_OFFICIAL_BUILD michael@0: #define TRACING_IS_OFFICIAL_BUILD 1 michael@0: #elif !defined(TRACING_IS_OFFICIAL_BUILD) michael@0: #define TRACING_IS_OFFICIAL_BUILD 0 michael@0: #endif michael@0: michael@0: #if TRACING_IS_OFFICIAL_BUILD michael@0: #define UNSHIPPED_TRACE_EVENT0(category_group, name) (void)0 michael@0: #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ michael@0: (void)0 michael@0: #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) (void)0 michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) (void)0 michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ michael@0: arg1_name, arg1_val) (void)0 michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ michael@0: arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) (void)0 michael@0: #else michael@0: #define UNSHIPPED_TRACE_EVENT0(category_group, name) \ michael@0: TRACE_EVENT0(category_group, name) michael@0: #define UNSHIPPED_TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ michael@0: TRACE_EVENT1(category_group, name, arg1_name, arg1_val) michael@0: #define UNSHIPPED_TRACE_EVENT2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT0(category_group, name, scope) \ michael@0: TRACE_EVENT_INSTANT0(category_group, name, scope) michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT1(category_group, name, scope, \ michael@0: arg1_name, arg1_val) \ michael@0: TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) michael@0: #define UNSHIPPED_TRACE_EVENT_INSTANT2(category_group, name, scope, \ michael@0: arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) michael@0: #endif michael@0: michael@0: // Records a single event called "name" immediately, with 0, 1 or 2 michael@0: // associated arguments. If the category is not enabled, then this michael@0: // does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_EVENT_INSTANT0(category_group, name, scope) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE | scope) michael@0: #define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE | scope, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_INSTANT0(category_group, name, scope) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY | scope) michael@0: #define TRACE_EVENT_COPY_INSTANT1(category_group, name, scope, \ michael@0: arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY | scope, arg1_name, \ michael@0: arg1_val) michael@0: #define TRACE_EVENT_COPY_INSTANT2(category_group, name, scope, \ michael@0: arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY | scope, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // Sets the current sample state to the given category and name (both must be michael@0: // constant strings). These states are intended for a sampling profiler. michael@0: // Implementation note: we store category and name together because we don't michael@0: // want the inconsistency/expense of storing two pointers. michael@0: // |thread_bucket| is [0..2] and is used to statically isolate samples in one michael@0: // thread from others. michael@0: #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ michael@0: bucket_number, category, name) \ michael@0: skia::tracing_internals:: \ michael@0: TraceEventSamplingStateScope::Set(category "\0" name) michael@0: michael@0: // Returns a current sampling state of the given bucket. michael@0: #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ michael@0: skia::tracing_internals::TraceEventSamplingStateScope::Current() michael@0: michael@0: // Creates a scope of a sampling state of the given bucket. michael@0: // michael@0: // { // The sampling state is set within this scope. michael@0: // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); michael@0: // ...; michael@0: // } michael@0: #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ michael@0: bucket_number, category, name) \ michael@0: skia::tracing_internals::TraceEventSamplingStateScope \ michael@0: traceEventSamplingScope(category "\0" name); michael@0: michael@0: // Syntactic sugars for the sampling tracing in the main thread. michael@0: #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \ michael@0: TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name) michael@0: #define TRACE_EVENT_GET_SAMPLING_STATE() \ michael@0: TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0) michael@0: #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \ michael@0: TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name) michael@0: michael@0: michael@0: // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 michael@0: // associated arguments. If the category is not enabled, then this michael@0: // does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_EVENT_BEGIN0(category_group, name) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_BEGIN2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_BEGIN0(category_group, name) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_BEGIN1(category_group, name, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_BEGIN2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) michael@0: michael@0: // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. michael@0: // - |id| is used to match the _BEGIN event with the _END event. michael@0: // Events are considered to match if their category_group, name and id values michael@0: // all match. |id| must either be a pointer or an integer value up to 64 bits. michael@0: // If it's a pointer, the bits will be xored with a hash of the process ID so michael@0: // that the same pointer on two different processes will not collide. michael@0: #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ michael@0: name, id, thread_id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ michael@0: TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ michael@0: timestamp, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ michael@0: category_group, name, id, thread_id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ michael@0: TRACE_EVENT_PHASE_ASYNC_BEGIN, category_group, name, id, thread_id, \ michael@0: timestamp, TRACE_EVENT_FLAG_COPY) michael@0: michael@0: // Records a single END event for "name" immediately. If the category michael@0: // is not enabled, then this does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_EVENT_END0(category_group, name) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_END1(category_group, name, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_END2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_END0(category_group, name) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_END1(category_group, name, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_END2(category_group, name, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) michael@0: michael@0: // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. michael@0: // - |id| is used to match the _BEGIN event with the _END event. michael@0: // Events are considered to match if their category_group, name and id values michael@0: // all match. |id| must either be a pointer or an integer value up to 64 bits. michael@0: // If it's a pointer, the bits will be xored with a hash of the process ID so michael@0: // that the same pointer on two different processes will not collide. michael@0: #define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category_group, \ michael@0: name, id, thread_id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ michael@0: TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ michael@0: timestamp, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ michael@0: category_group, name, id, thread_id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ michael@0: TRACE_EVENT_PHASE_ASYNC_END, category_group, name, id, thread_id, \ michael@0: timestamp, TRACE_EVENT_FLAG_COPY) michael@0: michael@0: // Records the value of a counter called "name" immediately. Value michael@0: // must be representable as a 32 bit integer. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_COUNTER1(category_group, name, value) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, \ michael@0: "value", static_cast(value)) michael@0: #define TRACE_COPY_COUNTER1(category_group, name, value) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, \ michael@0: "value", static_cast(value)) michael@0: michael@0: // Records the values of a multi-parted counter called "name" immediately. michael@0: // The UI will treat value1 and value2 as parts of a whole, displaying their michael@0: // values as a stacked-bar chart. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: #define TRACE_COUNTER2(category_group, name, value1_name, value1_val, \ michael@0: value2_name, value2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, TRACE_EVENT_FLAG_NONE, \ michael@0: value1_name, static_cast(value1_val), \ michael@0: value2_name, static_cast(value2_val)) michael@0: #define TRACE_COPY_COUNTER2(category_group, name, value1_name, value1_val, \ michael@0: value2_name, value2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, TRACE_EVENT_FLAG_COPY, \ michael@0: value1_name, static_cast(value1_val), \ michael@0: value2_name, static_cast(value2_val)) michael@0: michael@0: // Records the value of a counter called "name" immediately. Value michael@0: // must be representable as a 32 bit integer. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: // - |id| is used to disambiguate counters with the same name. It must either michael@0: // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits michael@0: // will be xored with a hash of the process ID so that the same pointer on michael@0: // two different processes will not collide. michael@0: #define TRACE_COUNTER_ID1(category_group, name, id, value) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: "value", static_cast(value)) michael@0: #define TRACE_COPY_COUNTER_ID1(category_group, name, id, value) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: "value", static_cast(value)) michael@0: michael@0: // Records the values of a multi-parted counter called "name" immediately. michael@0: // The UI will treat value1 and value2 as parts of a whole, displaying their michael@0: // values as a stacked-bar chart. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: // - |id| is used to disambiguate counters with the same name. It must either michael@0: // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits michael@0: // will be xored with a hash of the process ID so that the same pointer on michael@0: // two different processes will not collide. michael@0: #define TRACE_COUNTER_ID2(category_group, name, id, value1_name, value1_val, \ michael@0: value2_name, value2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: value1_name, static_cast(value1_val), \ michael@0: value2_name, static_cast(value2_val)) michael@0: #define TRACE_COPY_COUNTER_ID2(category_group, name, id, value1_name, \ michael@0: value1_val, value2_name, value2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: value1_name, static_cast(value1_val), \ michael@0: value2_name, static_cast(value2_val)) michael@0: michael@0: michael@0: // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2 michael@0: // associated arguments. If the category is not enabled, then this michael@0: // does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: // - |id| is used to match the ASYNC_BEGIN event with the ASYNC_END event. ASYNC michael@0: // events are considered to match if their category_group, name and id values michael@0: // all match. |id| must either be a pointer or an integer value up to 64 bits. michael@0: // If it's a pointer, the bits will be xored with a hash of the process ID so michael@0: // that the same pointer on two different processes will not collide. michael@0: // michael@0: // An asynchronous operation can consist of multiple phases. The first phase is michael@0: // defined by the ASYNC_BEGIN calls. Additional phases can be defined using the michael@0: // ASYNC_STEP_INTO or ASYNC_STEP_PAST macros. The ASYNC_STEP_INTO macro will michael@0: // annotate the block following the call. The ASYNC_STEP_PAST macro will michael@0: // annotate the block prior to the call. Note that any particular event must use michael@0: // only STEP_INTO or STEP_PAST macros; they can not mix and match. When the michael@0: // operation completes, call ASYNC_END. michael@0: // michael@0: // An ASYNC trace typically occurs on a single thread (if not, they will only be michael@0: // drawn on the thread defined in the ASYNC_BEGIN event), but all events in that michael@0: // operation must use the same |name| and |id|. Each step can have its own michael@0: // args. michael@0: #define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ michael@0: arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ michael@0: arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_ASYNC_BEGIN0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_ASYNC_BEGIN1(category_group, name, id, arg1_name, \ michael@0: arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_ASYNC_BEGIN2(category_group, name, id, arg1_name, \ michael@0: arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // Records a single ASYNC_STEP_INTO event for |step| immediately. If the michael@0: // category is not enabled, then this does nothing. The |name| and |id| must michael@0: // match the ASYNC_BEGIN event above. The |step| param identifies this step michael@0: // within the async event. This should be called at the beginning of the next michael@0: // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any michael@0: // ASYNC_STEP_PAST events. michael@0: #define TRACE_EVENT_ASYNC_STEP_INTO0(category_group, name, id, step) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) michael@0: #define TRACE_EVENT_ASYNC_STEP_INTO1(category_group, name, id, step, \ michael@0: arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_INTO, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ michael@0: arg1_name, arg1_val) michael@0: michael@0: // Records a single ASYNC_STEP_PAST event for |step| immediately. If the michael@0: // category is not enabled, then this does nothing. The |name| and |id| must michael@0: // match the ASYNC_BEGIN event above. The |step| param identifies this step michael@0: // within the async event. This should be called at the beginning of the next michael@0: // phase of an asynchronous operation. The ASYNC_BEGIN event must not have any michael@0: // ASYNC_STEP_INTO events. michael@0: #define TRACE_EVENT_ASYNC_STEP_PAST0(category_group, name, id, step) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) michael@0: #define TRACE_EVENT_ASYNC_STEP_PAST1(category_group, name, id, step, \ michael@0: arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ michael@0: arg1_name, arg1_val) michael@0: michael@0: // Records a single ASYNC_END event for "name" immediately. If the category michael@0: // is not enabled, then this does nothing. michael@0: #define TRACE_EVENT_ASYNC_END0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_ASYNC_END1(category_group, name, id, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_ASYNC_END2(category_group, name, id, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_ASYNC_END0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_ASYNC_END1(category_group, name, id, arg1_name, \ michael@0: arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_ASYNC_END2(category_group, name, id, arg1_name, \ michael@0: arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: michael@0: // Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2 michael@0: // associated arguments. If the category is not enabled, then this michael@0: // does nothing. michael@0: // - category and name strings must have application lifetime (statics or michael@0: // literals). They may not include " chars. michael@0: // - |id| is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW michael@0: // events are considered to match if their category_group, name and id values michael@0: // all match. |id| must either be a pointer or an integer value up to 64 bits. michael@0: // If it's a pointer, the bits will be xored with a hash of the process ID so michael@0: // that the same pointer on two different processes will not collide. michael@0: // FLOW events are different from ASYNC events in how they are drawn by the michael@0: // tracing UI. A FLOW defines asynchronous data flow, such as posting a task michael@0: // (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be michael@0: // drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar michael@0: // to ASYNC, a FLOW can consist of multiple phases. The first phase is defined michael@0: // by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP michael@0: // macros. When the operation completes, call FLOW_END. An async operation can michael@0: // span threads and processes, but all events in that operation must use the michael@0: // same |name| and |id|. Each event can have its own args. michael@0: #define TRACE_EVENT_FLOW_BEGIN0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_FLOW_BEGIN1(category_group, name, id, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_FLOW_BEGIN2(category_group, name, id, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_FLOW_BEGIN0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_FLOW_BEGIN1(category_group, name, id, arg1_name, \ michael@0: arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_FLOW_BEGIN2(category_group, name, id, arg1_name, \ michael@0: arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // Records a single FLOW_STEP event for |step| immediately. If the category michael@0: // is not enabled, then this does nothing. The |name| and |id| must match the michael@0: // FLOW_BEGIN event above. The |step| param identifies this step within the michael@0: // async event. This should be called at the beginning of the next phase of an michael@0: // asynchronous operation. michael@0: #define TRACE_EVENT_FLOW_STEP0(category_group, name, id, step) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step) michael@0: #define TRACE_EVENT_FLOW_STEP1(category_group, name, id, step, \ michael@0: arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, "step", step, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_FLOW_STEP0(category_group, name, id, step) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step) michael@0: #define TRACE_EVENT_COPY_FLOW_STEP1(category_group, name, id, step, \ michael@0: arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ michael@0: arg1_name, arg1_val) michael@0: michael@0: // Records a single FLOW_END event for "name" immediately. If the category michael@0: // is not enabled, then this does nothing. michael@0: #define TRACE_EVENT_FLOW_END0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE) michael@0: #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) michael@0: #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \ michael@0: arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_NONE, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: #define TRACE_EVENT_COPY_FLOW_END0(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY) michael@0: #define TRACE_EVENT_COPY_FLOW_END1(category_group, name, id, arg1_name, \ michael@0: arg1_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val) michael@0: #define TRACE_EVENT_COPY_FLOW_END2(category_group, name, id, arg1_name, \ michael@0: arg1_val, arg2_name, arg2_val) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ michael@0: category_group, name, id, TRACE_EVENT_FLAG_COPY, \ michael@0: arg1_name, arg1_val, arg2_name, arg2_val) michael@0: michael@0: // Macros to track the life time and value of arbitrary client objects. michael@0: // See also TraceTrackableObject. michael@0: #define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_CREATE_OBJECT, \ michael@0: category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) michael@0: michael@0: #define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \ michael@0: category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\ michael@0: "snapshot", snapshot) michael@0: michael@0: #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \ michael@0: INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \ michael@0: category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) michael@0: michael@0: #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ michael@0: *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ michael@0: (SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags | \ michael@0: SkEventTracer::kEnabledForEventCallback_CategoryGroupEnabledFlags) michael@0: michael@0: // Macro to efficiently determine if a given category group is enabled. michael@0: #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \ michael@0: do { \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ michael@0: if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ michael@0: *ret = true; \ michael@0: } else { \ michael@0: *ret = false; \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: // Macro to efficiently determine, through polling, if a new trace has begun. michael@0: #define TRACE_EVENT_IS_NEW_TRACE(ret) \ michael@0: do { \ michael@0: static int INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = 0; \ michael@0: int num_traces_recorded = TRACE_EVENT_API_GET_NUM_TRACES_RECORDED(); \ michael@0: if (num_traces_recorded != -1 && \ michael@0: num_traces_recorded != \ michael@0: INTERNAL_TRACE_EVENT_UID(lastRecordingNumber)) { \ michael@0: INTERNAL_TRACE_EVENT_UID(lastRecordingNumber) = \ michael@0: num_traces_recorded; \ michael@0: *ret = true; \ michael@0: } else { \ michael@0: *ret = false; \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Implementation specific tracing API definitions. michael@0: michael@0: // Get a pointer to the enabled state of the given trace category. Only michael@0: // long-lived literal strings should be given as the category group. The michael@0: // returned pointer can be held permanently in a local static for example. If michael@0: // the unsigned char is non-zero, tracing is enabled. If tracing is enabled, michael@0: // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled michael@0: // between the load of the tracing state and the call to michael@0: // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out michael@0: // for best performance when tracing is disabled. michael@0: // const uint8_t* michael@0: // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group) michael@0: #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ michael@0: SkEventTracer::GetInstance()->getCategoryGroupEnabled michael@0: michael@0: // Get the number of times traces have been recorded. This is used to implement michael@0: // the TRACE_EVENT_IS_NEW_TRACE facility. michael@0: // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED() michael@0: #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \ michael@0: SkEventTracer::GetInstance()->getNumTracesRecorded michael@0: michael@0: // Add a trace event to the platform tracing system. michael@0: // SkEventTracer::Handle TRACE_EVENT_API_ADD_TRACE_EVENT( michael@0: // char phase, michael@0: // const uint8_t* category_group_enabled, michael@0: // const char* name, michael@0: // uint64_t id, michael@0: // int num_args, michael@0: // const char** arg_names, michael@0: // const uint8_t* arg_types, michael@0: // const uint64_t* arg_values, michael@0: // unsigned char flags) michael@0: #define TRACE_EVENT_API_ADD_TRACE_EVENT \ michael@0: SkEventTracer::GetInstance()->addTraceEvent michael@0: michael@0: // Set the duration field of a COMPLETE trace event. michael@0: // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( michael@0: // const uint8_t* category_group_enabled, michael@0: // const char* name, michael@0: // SkEventTracer::Handle id) michael@0: #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ michael@0: SkEventTracer::GetInstance()->updateTraceEventDuration michael@0: michael@0: // These operations are atomic in the Chrome tracing implementation michael@0: // to cater to ARM's weak memory consistency; we're just doing read/ michael@0: // write here because it's not strictly needed for correctness. michael@0: // So says Nat. michael@0: // FIXME michael@0: michael@0: #define TRACE_EVENT_API_ATOMIC_WORD intptr_t michael@0: #define TRACE_EVENT_API_ATOMIC_LOAD(var) (*(&var)) michael@0: #define TRACE_EVENT_API_ATOMIC_STORE(var, value) (var=value) michael@0: michael@0: // Defines visibility for classes in trace_event.h michael@0: #define TRACE_EVENT_API_CLASS_EXPORT SK_API michael@0: michael@0: // The thread buckets for the sampling profiler. michael@0: TRACE_EVENT_API_CLASS_EXPORT extern \ michael@0: TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; michael@0: michael@0: #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ michael@0: g_trace_state[thread_bucket] michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: // Implementation detail: trace event macros create temporary variables michael@0: // to keep instrumentation overhead low. These macros give each temporary michael@0: // variable a unique name based on the line number to prevent name collisions. michael@0: #define INTERNAL_TRACE_EVENT_UID3(a,b) \ michael@0: trace_event_unique_##a##b michael@0: #define INTERNAL_TRACE_EVENT_UID2(a,b) \ michael@0: INTERNAL_TRACE_EVENT_UID3(a,b) michael@0: #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ michael@0: INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) michael@0: michael@0: // Implementation detail: internal macro to create static category. michael@0: // No barriers are needed, because this code is designed to operate safely michael@0: // even when the unsigned char* points to garbage data (which may be the case michael@0: // on processors without cache coherency). michael@0: #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \ michael@0: category_group, atomic, category_group_enabled) \ michael@0: category_group_enabled = \ michael@0: reinterpret_cast(TRACE_EVENT_API_ATOMIC_LOAD( \ michael@0: atomic)); \ michael@0: if (!category_group_enabled) { \ michael@0: category_group_enabled = \ michael@0: TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \ michael@0: TRACE_EVENT_API_ATOMIC_STORE(atomic, \ michael@0: reinterpret_cast( \ michael@0: category_group_enabled)); \ michael@0: } michael@0: michael@0: #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ michael@0: static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ michael@0: const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \ michael@0: INTERNAL_TRACE_EVENT_UID(atomic), \ michael@0: INTERNAL_TRACE_EVENT_UID(category_group_enabled)); michael@0: michael@0: // Implementation detail: internal macro to create static category and add michael@0: // event if the category is enabled. michael@0: #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ michael@0: do { \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ michael@0: if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ michael@0: skia::tracing_internals::AddTraceEvent( \ michael@0: phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ michael@0: skia::tracing_internals::kNoEventId, flags, ##__VA_ARGS__); \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: // Implementation detail: internal macro to create static category and add begin michael@0: // event if the category is enabled. Also adds the end event when the scope michael@0: // ends. michael@0: #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ michael@0: skia::tracing_internals::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ michael@0: if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ michael@0: SkEventTracer::Handle h = skia::tracing_internals::AddTraceEvent( \ michael@0: TRACE_EVENT_PHASE_COMPLETE, \ michael@0: INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ michael@0: name, skia::tracing_internals::kNoEventId, \ michael@0: TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ michael@0: INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ michael@0: INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ michael@0: } michael@0: michael@0: // Implementation detail: internal macro to create static category and add michael@0: // event if the category is enabled. michael@0: #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ michael@0: flags, ...) \ michael@0: do { \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ michael@0: if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ michael@0: unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ michael@0: skia::tracing_internals::TraceID trace_event_trace_id( \ michael@0: id, &trace_event_flags); \ michael@0: skia::tracing_internals::AddTraceEvent( \ michael@0: phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ michael@0: name, trace_event_trace_id.data(), trace_event_flags, \ michael@0: ##__VA_ARGS__); \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: // Implementation detail: internal macro to create static category and add michael@0: // event if the category is enabled. michael@0: #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ michael@0: category_group, name, id, thread_id, flags, ...) \ michael@0: do { \ michael@0: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ michael@0: if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ michael@0: unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ michael@0: skia::tracing_internals::TraceID trace_event_trace_id( \ michael@0: id, &trace_event_flags); \ michael@0: skia::tracing_internals::AddTraceEventWithThreadIdAndTimestamp( \ michael@0: phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ michael@0: name, trace_event_trace_id.data(), \ michael@0: thread_id, base::TimeTicks::FromInternalValue(timestamp), \ michael@0: trace_event_flags, ##__VA_ARGS__); \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: // Notes regarding the following definitions: michael@0: // New values can be added and propagated to third party libraries, but existing michael@0: // definitions must never be changed, because third party libraries may use old michael@0: // definitions. michael@0: michael@0: // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. michael@0: #define TRACE_EVENT_PHASE_BEGIN ('B') michael@0: #define TRACE_EVENT_PHASE_END ('E') michael@0: #define TRACE_EVENT_PHASE_COMPLETE ('X') michael@0: #define TRACE_EVENT_PHASE_INSTANT ('i') michael@0: #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') michael@0: #define TRACE_EVENT_PHASE_ASYNC_STEP_INTO ('T') michael@0: #define TRACE_EVENT_PHASE_ASYNC_STEP_PAST ('p') michael@0: #define TRACE_EVENT_PHASE_ASYNC_END ('F') michael@0: #define TRACE_EVENT_PHASE_FLOW_BEGIN ('s') michael@0: #define TRACE_EVENT_PHASE_FLOW_STEP ('t') michael@0: #define TRACE_EVENT_PHASE_FLOW_END ('f') michael@0: #define TRACE_EVENT_PHASE_METADATA ('M') michael@0: #define TRACE_EVENT_PHASE_COUNTER ('C') michael@0: #define TRACE_EVENT_PHASE_SAMPLE ('P') michael@0: #define TRACE_EVENT_PHASE_CREATE_OBJECT ('N') michael@0: #define TRACE_EVENT_PHASE_SNAPSHOT_OBJECT ('O') michael@0: #define TRACE_EVENT_PHASE_DELETE_OBJECT ('D') michael@0: michael@0: // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. michael@0: #define TRACE_EVENT_FLAG_NONE (static_cast(0)) michael@0: #define TRACE_EVENT_FLAG_COPY (static_cast(1 << 0)) michael@0: #define TRACE_EVENT_FLAG_HAS_ID (static_cast(1 << 1)) michael@0: #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast(1 << 2)) michael@0: #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast(1 << 3)) michael@0: michael@0: #define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast( \ michael@0: TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1))) michael@0: michael@0: // Type values for identifying types in the TraceValue union. michael@0: #define TRACE_VALUE_TYPE_BOOL (static_cast(1)) michael@0: #define TRACE_VALUE_TYPE_UINT (static_cast(2)) michael@0: #define TRACE_VALUE_TYPE_INT (static_cast(3)) michael@0: #define TRACE_VALUE_TYPE_DOUBLE (static_cast(4)) michael@0: #define TRACE_VALUE_TYPE_POINTER (static_cast(5)) michael@0: #define TRACE_VALUE_TYPE_STRING (static_cast(6)) michael@0: #define TRACE_VALUE_TYPE_COPY_STRING (static_cast(7)) michael@0: #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast(8)) michael@0: michael@0: // Enum reflecting the scope of an INSTANT event. Must fit within michael@0: // TRACE_EVENT_FLAG_SCOPE_MASK. michael@0: #define TRACE_EVENT_SCOPE_GLOBAL (static_cast(0 << 3)) michael@0: #define TRACE_EVENT_SCOPE_PROCESS (static_cast(1 << 3)) michael@0: #define TRACE_EVENT_SCOPE_THREAD (static_cast(2 << 3)) michael@0: michael@0: #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') michael@0: #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') michael@0: #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') michael@0: michael@0: namespace skia { michael@0: namespace tracing_internals { michael@0: michael@0: // Specify these values when the corresponding argument of AddTraceEvent is not michael@0: // used. michael@0: const int kZeroNumArgs = 0; michael@0: const uint64_t kNoEventId = 0; michael@0: michael@0: // TraceID encapsulates an ID that can either be an integer or pointer. Pointers michael@0: // are by default mangled with the Process ID so that they are unlikely to michael@0: // collide when the same pointer is used on different processes. michael@0: class TraceID { michael@0: public: michael@0: class DontMangle { michael@0: public: michael@0: explicit DontMangle(const void* id) michael@0: : data_(static_cast( michael@0: reinterpret_cast(id))) {} michael@0: explicit DontMangle(uint64_t id) : data_(id) {} michael@0: explicit DontMangle(unsigned int id) : data_(id) {} michael@0: explicit DontMangle(unsigned short id) : data_(id) {} michael@0: explicit DontMangle(unsigned char id) : data_(id) {} michael@0: explicit DontMangle(long long id) michael@0: : data_(static_cast(id)) {} michael@0: explicit DontMangle(long id) michael@0: : data_(static_cast(id)) {} michael@0: explicit DontMangle(int id) michael@0: : data_(static_cast(id)) {} michael@0: explicit DontMangle(short id) michael@0: : data_(static_cast(id)) {} michael@0: explicit DontMangle(signed char id) michael@0: : data_(static_cast(id)) {} michael@0: uint64_t data() const { return data_; } michael@0: private: michael@0: uint64_t data_; michael@0: }; michael@0: michael@0: class ForceMangle { michael@0: public: michael@0: explicit ForceMangle(uint64_t id) : data_(id) {} michael@0: explicit ForceMangle(unsigned int id) : data_(id) {} michael@0: explicit ForceMangle(unsigned short id) : data_(id) {} michael@0: explicit ForceMangle(unsigned char id) : data_(id) {} michael@0: explicit ForceMangle(long long id) michael@0: : data_(static_cast(id)) {} michael@0: explicit ForceMangle(long id) michael@0: : data_(static_cast(id)) {} michael@0: explicit ForceMangle(int id) michael@0: : data_(static_cast(id)) {} michael@0: explicit ForceMangle(short id) michael@0: : data_(static_cast(id)) {} michael@0: explicit ForceMangle(signed char id) michael@0: : data_(static_cast(id)) {} michael@0: uint64_t data() const { return data_; } michael@0: private: michael@0: uint64_t data_; michael@0: }; michael@0: michael@0: TraceID(const void* id, unsigned char* flags) michael@0: : data_(static_cast( michael@0: reinterpret_cast(id))) { michael@0: *flags |= TRACE_EVENT_FLAG_MANGLE_ID; michael@0: } michael@0: TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) { michael@0: *flags |= TRACE_EVENT_FLAG_MANGLE_ID; michael@0: } michael@0: TraceID(DontMangle id, unsigned char* flags) : data_(id.data()) { michael@0: } michael@0: TraceID(uint64_t id, unsigned char* flags) michael@0: : data_(id) { (void)flags; } michael@0: TraceID(unsigned int id, unsigned char* flags) michael@0: : data_(id) { (void)flags; } michael@0: TraceID(unsigned short id, unsigned char* flags) michael@0: : data_(id) { (void)flags; } michael@0: TraceID(unsigned char id, unsigned char* flags) michael@0: : data_(id) { (void)flags; } michael@0: TraceID(long long id, unsigned char* flags) michael@0: : data_(static_cast(id)) { (void)flags; } michael@0: TraceID(long id, unsigned char* flags) michael@0: : data_(static_cast(id)) { (void)flags; } michael@0: TraceID(int id, unsigned char* flags) michael@0: : data_(static_cast(id)) { (void)flags; } michael@0: TraceID(short id, unsigned char* flags) michael@0: : data_(static_cast(id)) { (void)flags; } michael@0: TraceID(signed char id, unsigned char* flags) michael@0: : data_(static_cast(id)) { (void)flags; } michael@0: michael@0: uint64_t data() const { return data_; } michael@0: michael@0: private: michael@0: uint64_t data_; michael@0: }; michael@0: michael@0: // Simple union to store various types as uint64_t. michael@0: union TraceValueUnion { michael@0: bool as_bool; michael@0: uint64_t as_uint; michael@0: long long as_int; michael@0: double as_double; michael@0: const void* as_pointer; michael@0: const char* as_string; michael@0: }; michael@0: michael@0: // Simple container for const char* that should be copied instead of retained. michael@0: class TraceStringWithCopy { michael@0: public: michael@0: explicit TraceStringWithCopy(const char* str) : str_(str) {} michael@0: operator const char* () const { return str_; } michael@0: private: michael@0: const char* str_; michael@0: }; michael@0: michael@0: // Define SetTraceValue for each allowed type. It stores the type and michael@0: // value in the return arguments. This allows this API to avoid declaring any michael@0: // structures so that it is portable to third_party libraries. michael@0: #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ michael@0: union_member, \ michael@0: value_type_id) \ michael@0: static inline void SetTraceValue( \ michael@0: actual_type arg, \ michael@0: unsigned char* type, \ michael@0: uint64_t* value) { \ michael@0: TraceValueUnion type_value; \ michael@0: type_value.union_member = arg; \ michael@0: *type = value_type_id; \ michael@0: *value = type_value.as_uint; \ michael@0: } michael@0: // Simpler form for int types that can be safely casted. michael@0: #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ michael@0: value_type_id) \ michael@0: static inline void SetTraceValue( \ michael@0: actual_type arg, \ michael@0: unsigned char* type, \ michael@0: uint64_t* value) { \ michael@0: *type = value_type_id; \ michael@0: *value = static_cast(arg); \ michael@0: } michael@0: michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint64_t, TRACE_VALUE_TYPE_UINT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, michael@0: TRACE_VALUE_TYPE_POINTER) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, michael@0: TRACE_VALUE_TYPE_STRING) michael@0: INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, michael@0: TRACE_VALUE_TYPE_COPY_STRING) michael@0: michael@0: #undef INTERNAL_DECLARE_SET_TRACE_VALUE michael@0: #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT michael@0: michael@0: // These AddTraceEvent and AddTraceEvent template michael@0: // functions are defined here instead of in the macro, because the arg_values michael@0: // could be temporary objects, such as std::string. In order to store michael@0: // pointers to the internal c_str and pass through to the tracing API, michael@0: // the arg_values must live throughout these procedures. michael@0: michael@0: static inline SkEventTracer::Handle michael@0: AddTraceEvent( michael@0: char phase, michael@0: const uint8_t* category_group_enabled, michael@0: const char* name, michael@0: uint64_t id, michael@0: unsigned char flags) { michael@0: return TRACE_EVENT_API_ADD_TRACE_EVENT( michael@0: phase, category_group_enabled, name, id, michael@0: kZeroNumArgs, NULL, NULL, NULL, flags); michael@0: } michael@0: michael@0: template michael@0: static inline SkEventTracer::Handle michael@0: AddTraceEvent( michael@0: char phase, michael@0: const uint8_t* category_group_enabled, michael@0: const char* name, michael@0: uint64_t id, michael@0: unsigned char flags, michael@0: const char* arg1_name, michael@0: const ARG1_TYPE& arg1_val) { michael@0: const int num_args = 1; michael@0: uint8_t arg_types[1]; michael@0: uint64_t arg_values[1]; michael@0: SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); michael@0: return TRACE_EVENT_API_ADD_TRACE_EVENT( michael@0: phase, category_group_enabled, name, id, michael@0: num_args, &arg1_name, arg_types, arg_values, flags); michael@0: } michael@0: michael@0: template michael@0: static inline SkEventTracer::Handle michael@0: AddTraceEvent( michael@0: char phase, michael@0: const uint8_t* category_group_enabled, michael@0: const char* name, michael@0: uint64_t id, michael@0: unsigned char flags, michael@0: const char* arg1_name, michael@0: const ARG1_TYPE& arg1_val, michael@0: const char* arg2_name, michael@0: const ARG2_TYPE& arg2_val) { michael@0: const int num_args = 2; michael@0: const char* arg_names[2] = { arg1_name, arg2_name }; michael@0: unsigned char arg_types[2]; michael@0: uint64_t arg_values[2]; michael@0: SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); michael@0: SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); michael@0: return TRACE_EVENT_API_ADD_TRACE_EVENT( michael@0: phase, category_group_enabled, name, id, michael@0: num_args, arg_names, arg_types, arg_values, flags); michael@0: } michael@0: michael@0: // Used by TRACE_EVENTx macros. Do not use directly. michael@0: class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { michael@0: public: michael@0: // Note: members of data_ intentionally left uninitialized. See Initialize. michael@0: ScopedTracer() : p_data_(NULL) {} michael@0: michael@0: ~ScopedTracer() { michael@0: if (p_data_ && *data_.category_group_enabled) michael@0: TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( michael@0: data_.category_group_enabled, data_.name, data_.event_handle); michael@0: } michael@0: michael@0: void Initialize(const uint8_t* category_group_enabled, michael@0: const char* name, michael@0: SkEventTracer::Handle event_handle) { michael@0: data_.category_group_enabled = category_group_enabled; michael@0: data_.name = name; michael@0: data_.event_handle = event_handle; michael@0: p_data_ = &data_; michael@0: } michael@0: michael@0: private: michael@0: // This Data struct workaround is to avoid initializing all the members michael@0: // in Data during construction of this object, since this object is always michael@0: // constructed, even when tracing is disabled. If the members of Data were michael@0: // members of this class instead, compiler warnings occur about potential michael@0: // uninitialized accesses. michael@0: struct Data { michael@0: const uint8_t* category_group_enabled; michael@0: const char* name; michael@0: SkEventTracer::Handle event_handle; michael@0: }; michael@0: Data* p_data_; michael@0: Data data_; michael@0: }; michael@0: michael@0: // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. michael@0: class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient { michael@0: public: michael@0: ScopedTraceBinaryEfficient(const char* category_group, const char* name); michael@0: ~ScopedTraceBinaryEfficient(); michael@0: michael@0: private: michael@0: const uint8_t* category_group_enabled_; michael@0: const char* name_; michael@0: SkEventTracer::Handle event_handle_; michael@0: }; michael@0: michael@0: // This macro generates less code then TRACE_EVENT0 but is also michael@0: // slower to execute when tracing is off. It should generally only be michael@0: // used with code that is seldom executed or conditionally executed michael@0: // when debugging. michael@0: // For now the category_group must be "gpu". michael@0: #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ michael@0: skia::tracing_internals::ScopedTraceBinaryEfficient \ michael@0: INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name); michael@0: michael@0: // TraceEventSamplingStateScope records the current sampling state michael@0: // and sets a new sampling state. When the scope exists, it restores michael@0: // the sampling state having recorded. michael@0: template michael@0: class TraceEventSamplingStateScope { michael@0: public: michael@0: TraceEventSamplingStateScope(const char* category_and_name) { michael@0: previous_state_ = TraceEventSamplingStateScope::Current(); michael@0: TraceEventSamplingStateScope::Set(category_and_name); michael@0: } michael@0: michael@0: ~TraceEventSamplingStateScope() { michael@0: TraceEventSamplingStateScope::Set(previous_state_); michael@0: } michael@0: michael@0: static inline const char* Current() { michael@0: return reinterpret_cast(TRACE_EVENT_API_ATOMIC_LOAD( michael@0: g_trace_state[BucketNumber])); michael@0: } michael@0: michael@0: static inline void Set(const char* category_and_name) { michael@0: TRACE_EVENT_API_ATOMIC_STORE( michael@0: g_trace_state[BucketNumber], michael@0: reinterpret_cast( michael@0: const_cast(category_and_name))); michael@0: } michael@0: michael@0: private: michael@0: const char* previous_state_; michael@0: }; michael@0: michael@0: } // namespace tracing_internals michael@0: } // namespace skia michael@0: michael@0: #endif