Chromium Code Reviews| Index: base/debug/trace_event.h |
| diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
| index 444c97514dc925ed31f46bbd3f7fdfb04399333b..b1a9b7177cbda37b601a4c8669a1d5603ba798a3 100644 |
| --- a/base/debug/trace_event.h |
| +++ b/base/debug/trace_event.h |
| @@ -126,7 +126,7 @@ |
| // the static variable is safe, as they will be serialized by the lock and |
| // multiple calls will return the same pointer to the category. |
| // |
| -// Then the category.enabled flag is checked. This is a volatile bool, and |
| +// Then the category_enabled flag is checked. This is a unsigned char, and |
| // not intended to be multithread safe. It optimizes access to AddTraceEvent |
| // which is threadsafe internally via TraceLog::lock_. The enabled flag may |
| // cause some threads to incorrectly call or skip calling AddTraceEvent near |
| @@ -160,9 +160,56 @@ |
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| #include "base/timer.h" |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// TODO(jbates): split this into a separate header. |
| +// This header is designed to be give you trace_event macros without specifying |
| +// how the events actually get collected and stored. If you need to expose trace |
| +// event to some other universe, you can copy-and-paste this file and just |
| +// implement these API macros. |
| + |
| +// unsigned char* |
| +// TRACE_EVENT_API_GET_CATEGORY_ENABLED(const char* category_name) |
| +#define TRACE_EVENT_API_GET_CATEGORY_ENABLED \ |
| + base::debug::TraceLog::GetCategoryEnabled |
| + |
| +// Returns the threshold_begin_id used by TRACE_IF_LONGER_THAN macros. |
| +// int TRACE_EVENT_API_ADD_TRACE_EVENT( |
| +// char phase, |
| +// const unsigned char* category_enabled, |
|
jar (doing other things)
2012/01/12 21:48:43
nit: IMO, bool is a better type. It adds to readab
jbates
2012/01/12 22:22:11
The main reasoning for not using bool in this API
|
| +// const char* name, |
| +// unsigned long long id, |
| +// int num_args, |
| +// const char** arg_names, |
| +// const unsigned char* arg_types, |
| +// const unsigned long long* arg_values, |
| +// int threshold_begin_id, |
| +// long long threshold, |
| +// unsigned char flags) |
| +#define TRACE_EVENT_API_ADD_TRACE_EVENT \ |
| + base::debug::TraceLog::GetInstance()->AddTraceEvent |
| + |
| +// void TRACE_EVENT_API_ADD_COUNTER_EVENT( |
| +// const unsigned char* category_enabled, |
| +// const char* name, |
| +// unsigned long long id, |
| +// const char* arg1_name, int arg1_val, |
| +// const char* arg2_name, int arg2_val, |
| +// unsigned char flags) |
| +#define TRACE_EVENT_API_ADD_COUNTER_EVENT \ |
| + base::debug::TraceLog::GetInstance()->AddCounterEvent |
| + |
| +// Mangle |pointer| with a process ID hash so that if |pointer| occurs on more |
| +// than one process, it will not collide in the trace data. |
| +// unsigned long long TRACE_EVENT_API_GET_ID_FROM_POINTER(void* pointer) |
| +#define TRACE_EVENT_API_GET_ID_FROM_POINTER \ |
| + base::debug::TraceLog::GetInstance()->GetInterProcessID |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| // By default, const char* argument values are assumed to have long-lived scope |
| // and will not be copied. Use this macro to force a const char* to be copied. |
| -#define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) |
| +#define TRACE_STR_COPY(str) \ |
| + trace_event_internal::TraceStringWithCopy(str) |
| // Older style trace macros with explicit id and extra data |
| // Only these macros result in publishing data to ETW as currently implemented. |
| @@ -187,12 +234,12 @@ |
| // - category and name strings must have application lifetime (statics or |
| // literals). They may not include " chars. |
| #define TRACE_EVENT0(category, name) \ |
| - TRACE_EVENT1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name) |
| #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val) |
| #define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| - INTERNAL_TRACE_EVENT_ADD_SCOPED( \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val) |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| // Same as TRACE_EVENT except that they are not included in official builds. |
| #ifdef OFFICIAL_BUILD |
| @@ -229,25 +276,27 @@ |
| // - category and name strings must have application lifetime (statics or |
| // literals). They may not include " chars. |
| #define TRACE_EVENT_INSTANT0(category, name) \ |
| - TRACE_EVENT_INSTANT1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| + category, name, TRACE_EVENT_FLAG_NONE) |
| #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
| #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
| - TRACE_EVENT_FLAG_NONE) |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| #define TRACE_EVENT_COPY_INSTANT0(category, name) \ |
| - TRACE_EVENT_COPY_INSTANT1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| + category, name, TRACE_EVENT_FLAG_COPY) |
| #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| - category, name, \ |
| - arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
| - arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
| - TRACE_EVENT_FLAG_COPY) |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
| // associated arguments. If the category is not enabled, then this |
| @@ -255,50 +304,54 @@ |
| // - category and name strings must have application lifetime (statics or |
| // literals). They may not include " chars. |
| #define TRACE_EVENT_BEGIN0(category, name) \ |
| - TRACE_EVENT_BEGIN1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| + category, name, TRACE_EVENT_FLAG_NONE) |
| #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
| #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
| - TRACE_EVENT_FLAG_NONE) |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| #define TRACE_EVENT_COPY_BEGIN0(category, name) \ |
| - TRACE_EVENT_COPY_BEGIN1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| + category, name, TRACE_EVENT_FLAG_COPY) |
| #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| - category, name, \ |
| - arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
| - arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
| - TRACE_EVENT_FLAG_COPY) |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| // Records a single END event for "name" immediately. If the category |
| // is not enabled, then this does nothing. |
| // - category and name strings must have application lifetime (statics or |
| // literals). They may not include " chars. |
| #define TRACE_EVENT_END0(category, name) \ |
| - TRACE_EVENT_END1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| + category, name, TRACE_EVENT_FLAG_NONE) |
| #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_END2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
| #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
| - TRACE_EVENT_FLAG_NONE) |
| + category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| #define TRACE_EVENT_COPY_END0(category, name) \ |
| - TRACE_EVENT_COPY_END1(category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| + category, name, TRACE_EVENT_FLAG_COPY) |
| #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| - category, name, \ |
| - arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
| - arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
| - TRACE_EVENT_FLAG_COPY) |
| + category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| + arg2_name, arg2_val) |
| // Time threshold event: |
| // Only record the event if the duration is greater than the specified |
| @@ -309,15 +362,15 @@ |
| // - category and name strings must have application lifetime (statics or |
| // literals). They may not include " chars. |
| #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
| - TRACE_EVENT_IF_LONGER_THAN1(threshold_us, category, name, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) |
| #define TRACE_EVENT_IF_LONGER_THAN1( \ |
| - threshold_us, category, name, arg1_name, arg1_val) \ |
| - TRACE_EVENT_IF_LONGER_THAN2(threshold_us, category, name, \ |
| - arg1_name, arg1_val, NULL, 0) |
| + threshold_us, category, name, arg1_name, arg1_val) \ |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN( \ |
| + threshold_us, category, name, arg1_name, arg1_val) |
| #define TRACE_EVENT_IF_LONGER_THAN2( \ |
| threshold_us, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| - INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val) |
| + INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN( \ |
| + threshold_us, category, name, arg1_name, arg1_val, arg2_name, arg2_val) |
| // Records the value of a counter called "name" immediately. Value |
| // must be representable as a 32 bit integer. |
| @@ -336,14 +389,14 @@ |
| #define TRACE_COUNTER2(category, name, value1_name, value1_val, \ |
| value2_name, value2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
| - category, name, 0, value1_name, value1_val, value2_name, value2_val, \ |
| + category, name, trace_event_internal::kNoEventId, \ |
| + value1_name, value1_val, value2_name, value2_val, \ |
| TRACE_EVENT_FLAG_NONE) |
| #define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ |
| value2_name, value2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
| - category, name, 0, \ |
| - value1_name, value1_val, \ |
| - value2_name, value2_val, \ |
| + category, name, trace_event_internal::kNoEventId, \ |
| + value1_name, value1_val, value2_name, value2_val, \ |
| TRACE_EVENT_FLAG_COPY) |
| // Records the value of a counter called "name" immediately. Value |
| @@ -392,48 +445,54 @@ |
| // will be xored with a hash of the process ID so that the same pointer on |
| // two different processes will not collide. |
| #define TRACE_EVENT_START0(category, name, id) \ |
| - TRACE_EVENT_START1(category, name, id, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID) |
| #define TRACE_EVENT_START1(category, name, id, arg1_name, arg1_val) \ |
| - TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID, arg1_name, arg1_val) |
| #define TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| - category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ |
| - TRACE_EVENT_FLAG_HAS_ID) |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID, \ |
| + arg1_name, arg1_val, arg2_name, arg2_val) |
| #define TRACE_EVENT_COPY_START0(category, name, id) \ |
| - TRACE_EVENT_COPY_START1(category, name, id, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) |
| #define TRACE_EVENT_COPY_START1(category, name, id, arg1_name, arg1_val) \ |
| - TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| + arg1_name, arg1_val) |
| #define TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| - category, name, id, \ |
| - arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
| - arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
| - TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| + arg1_name, arg1_val, arg2_name, arg2_val) |
| // Records a single FINISH event for "name" immediately. If the category |
| // is not enabled, then this does nothing. |
| #define TRACE_EVENT_FINISH0(category, name, id) \ |
| - TRACE_EVENT_FINISH1(category, name, id, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID) |
| #define TRACE_EVENT_FINISH1(category, name, id, arg1_name, arg1_val) \ |
| - TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID, arg1_name, arg1_val) |
| #define TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| - category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ |
| - TRACE_EVENT_FLAG_HAS_ID) |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID, \ |
| + arg1_name, arg1_val, arg2_name, arg2_val) |
| #define TRACE_EVENT_COPY_FINISH0(category, name, id) \ |
| - TRACE_EVENT_COPY_FINISH1(category, name, id, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) |
| #define TRACE_EVENT_COPY_FINISH1(category, name, id, arg1_name, arg1_val) \ |
| - TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| + arg1_name, arg1_val) |
| #define TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) \ |
| INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| - category, name, id, \ |
| - arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
| - arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
| - TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) |
| + category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| + arg1_name, arg1_val, arg2_name, arg2_val) |
| // Implementation detail: trace event macros create temporary variables |
| @@ -449,23 +508,21 @@ |
| // Implementation detail: internal macro to create static category. |
| // - ANNOTATE_BENIGN_RACE, see Thread Safety above. |
| #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ |
| - static const base::debug::TraceCategory* \ |
| - INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ |
| + static const unsigned char* INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ |
| ANNOTATE_BENIGN_RACE(&INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| "trace_event category"); \ |
| if (!INTERNAL_TRACE_EVENT_UID(catstatic)) \ |
| INTERNAL_TRACE_EVENT_UID(catstatic) = \ |
| - base::debug::TraceLog::GetCategory(category); |
| + TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); |
| // Implementation detail: internal macro to create static category and add |
| // event if the category is enabled. |
| -#define INTERNAL_TRACE_EVENT_ADD( \ |
| - phase, category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
| +#define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| - if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
| - base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
| - phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| - name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| + trace_event_internal::AddTraceEvent( \ |
| + phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| + trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ |
| } |
| // Implementation detail: internal macro to create static category and |
| @@ -473,26 +530,26 @@ |
| #define INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
| category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| - if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
| - base::debug::TraceLog::GetInstance()->AddCounterEvent( \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| + TRACE_EVENT_API_ADD_COUNTER_EVENT( \ |
| INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| - name, id, arg1_name, arg1_val, arg2_name, arg2_val, flags); \ |
| + name, trace_event_internal::TraceID(id).data(), \ |
| + arg1_name, arg1_val, arg2_name, arg2_val, flags); \ |
| } |
| // Implementation detail: internal macro to create static category and add begin |
| // event if the category is enabled. Also adds the end event when the scope |
| // ends. |
| -#define INTERNAL_TRACE_EVENT_ADD_SCOPED( \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| +#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| - base::debug::internal::TraceEndOnScopeClose \ |
| + trace_event_internal::TraceEndOnScopeClose \ |
| INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| - if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
| - base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| + trace_event_internal::AddTraceEvent( \ |
| TRACE_EVENT_PHASE_BEGIN, \ |
| INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| - name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ |
| - TRACE_EVENT_FLAG_NONE); \ |
| + name, trace_event_internal::kNoEventId, \ |
| + TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
| INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
| INTERNAL_TRACE_EVENT_UID(catstatic), name); \ |
| } |
| @@ -501,17 +558,17 @@ |
| // event if the category is enabled. Also adds the end event when the scope |
| // ends. If the elapsed time is < threshold time, the begin/end pair is erased. |
| #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ |
| - category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| + category, name, ...) \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| - base::debug::internal::TraceEndOnScopeCloseThreshold \ |
| + trace_event_internal::TraceEndOnScopeCloseThreshold \ |
| INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| - if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ |
| - base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
| + trace_event_internal::AddTraceEvent( \ |
| TRACE_EVENT_PHASE_BEGIN, \ |
| INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| - name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ |
| - TRACE_EVENT_FLAG_NONE); \ |
| + name, trace_event_internal::kNoEventId, \ |
| + TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
| INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
| INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ |
| @@ -519,13 +576,14 @@ |
| // Implementation detail: internal macro to create static category and add |
| // event if the category is enabled. |
| -#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, \ |
| - arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
| +#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ |
| + ...) \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| - if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
| - base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| + trace_event_internal::AddTraceEvent( \ |
| phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| - name, id, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ |
| + name, trace_event_internal::TraceID(id).data(), flags, \ |
| + ##__VA_ARGS__); \ |
| } |
| template <typename Type> |
| @@ -537,173 +595,35 @@ class RefCountedString; |
| namespace debug { |
| -// Categories allow enabling/disabling of streams of trace events |
| -struct TraceCategory { |
| - const char* name; |
| - volatile bool enabled; |
| -}; |
| +const int kTraceMaxNumArgs = 2; |
| -const size_t kTraceMaxNumArgs = 2; |
| +// Notes regarding the following definitions: |
| +// New values can be added and propagated to third party libraries, but existing |
| +// definitions must never be changed, because third party libraries may use old |
| +// definitions. |
| // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. |
| -typedef char TraceEventPhase; |
| -#define TRACE_EVENT_PHASE_BEGIN (base::debug::TraceEventPhase('B')) |
| -#define TRACE_EVENT_PHASE_END (base::debug::TraceEventPhase('E')) |
| -#define TRACE_EVENT_PHASE_INSTANT (base::debug::TraceEventPhase('I')) |
| -#define TRACE_EVENT_PHASE_START (base::debug::TraceEventPhase('S')) |
| -#define TRACE_EVENT_PHASE_FINISH (base::debug::TraceEventPhase('F')) |
| -#define TRACE_EVENT_PHASE_METADATA (base::debug::TraceEventPhase('M')) |
| -#define TRACE_EVENT_PHASE_COUNTER (base::debug::TraceEventPhase('C')) |
| - |
| -typedef uint8 TraceEventFlags; |
| -#define TRACE_EVENT_FLAG_NONE (base::debug::TraceEventFlags(0)) |
| -#define TRACE_EVENT_FLAG_COPY (base::debug::TraceEventFlags(1<<0)) |
| -#define TRACE_EVENT_FLAG_HAS_ID (base::debug::TraceEventFlags(1<<1)) |
| - |
| -// Simple union of values. This is much lighter weight than base::Value, which |
| -// requires dynamic allocation and a vtable. To keep the trace runtime overhead |
| -// low, we want constant size storage here. |
| -class BASE_EXPORT TraceValue { |
| - public: |
| - enum Type { |
| - TRACE_TYPE_UNDEFINED, |
| - TRACE_TYPE_BOOL, |
| - TRACE_TYPE_UINT, |
| - TRACE_TYPE_INT, |
| - TRACE_TYPE_DOUBLE, |
| - TRACE_TYPE_POINTER, |
| - TRACE_TYPE_STRING, |
| - TRACE_TYPE_STATIC_STRING |
| - }; |
| - |
| - TraceValue() : type_(TRACE_TYPE_UNDEFINED) { |
| - value_.as_uint = 0ull; |
| - } |
| - TraceValue(bool rhs) : type_(TRACE_TYPE_BOOL) { |
| - value_.as_bool = rhs; |
| - } |
| - TraceValue(uint64 rhs) : type_(TRACE_TYPE_UINT) { |
| - value_.as_uint = rhs; |
| - } |
| - TraceValue(uint32 rhs) : type_(TRACE_TYPE_UINT) { |
| - value_.as_uint = rhs; |
| - } |
| - TraceValue(uint16 rhs) : type_(TRACE_TYPE_UINT) { |
| - value_.as_uint = rhs; |
| - } |
| - TraceValue(uint8 rhs) : type_(TRACE_TYPE_UINT) { |
| - value_.as_uint = rhs; |
| - } |
| - TraceValue(int64 rhs) : type_(TRACE_TYPE_INT) { |
| - value_.as_int = rhs; |
| - } |
| - TraceValue(int32 rhs) : type_(TRACE_TYPE_INT) { |
| - value_.as_int = rhs; |
| - } |
| - TraceValue(int16 rhs) : type_(TRACE_TYPE_INT) { |
| - value_.as_int = rhs; |
| - } |
| - TraceValue(int8 rhs) : type_(TRACE_TYPE_INT) { |
| - value_.as_int = rhs; |
| - } |
| - TraceValue(double rhs) : type_(TRACE_TYPE_DOUBLE) { |
| - value_.as_double = rhs; |
| - } |
| - TraceValue(const void* rhs) : type_(TRACE_TYPE_POINTER) { |
| - value_.as_pointer = rhs; |
| - } |
| - TraceValue(const std::string& rhs) : type_(TRACE_TYPE_STRING) { |
| - value_.as_string = rhs.c_str(); |
| - } |
| - TraceValue(const char* rhs) : type_(TRACE_TYPE_STATIC_STRING) { |
| - value_.as_string = rhs; |
| - } |
| - |
| - static TraceValue StringWithCopy(const char* rhs) { |
| - TraceValue value(rhs); |
| - if (rhs) |
| - value.type_ = TRACE_TYPE_STRING; |
| - return value; |
| - } |
| - |
| - static TraceValue ForceCopy(const TraceValue& rhs) { |
| - TraceValue value(rhs); |
| - if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) |
| - value.type_ = TRACE_TYPE_STRING; |
| - return value; |
| - } |
| - |
| - bool is_string() const { |
| - return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING; |
| - } |
| - |
| - void AppendAsJSON(std::string* out) const; |
| - |
| - Type type() const { |
| - return type_; |
| - } |
| - uint64 as_uint() const { |
| - DCHECK_EQ(TRACE_TYPE_UINT, type_); |
| - return value_.as_uint; |
| - } |
| - bool as_bool() const { |
| - DCHECK_EQ(TRACE_TYPE_BOOL, type_); |
| - return value_.as_bool; |
| - } |
| - int64 as_int() const { |
| - DCHECK_EQ(TRACE_TYPE_INT, type_); |
| - return value_.as_int; |
| - } |
| - double as_double() const { |
| - DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); |
| - return value_.as_double; |
| - } |
| - const void* as_pointer() const { |
| - DCHECK_EQ(TRACE_TYPE_POINTER, type_); |
| - return value_.as_pointer; |
| - } |
| - const char* as_string() const { |
| - DCHECK(is_string()); |
| - return value_.as_string; |
| - } |
| - const char** as_assignable_string() { |
| - DCHECK_EQ(TRACE_TYPE_STRING, type_); |
| - return &value_.as_string; |
| - } |
| - |
| - private: |
| - union Value { |
| - bool as_bool; |
| - uint64 as_uint; |
| - int64 as_int; |
| - double as_double; |
| - const void* as_pointer; |
| - const char* as_string; |
| - }; |
| - |
| - Type type_; |
| - Value value_; |
| -}; |
| - |
| -// TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| -// are mangled with the Process ID so that they are unlikely to collide when the |
| -// same pointer is used on different processes. |
| -class BASE_EXPORT TraceID { |
| - public: |
| - TraceID() : data_(0u) {} |
| - TraceID(void* rhs); |
| - TraceID(unsigned long long rhs) : data_(static_cast<uint64>(rhs)) {} |
| - TraceID(unsigned long rhs) : data_(static_cast<uint64>(rhs)) {} |
| - TraceID(unsigned int rhs) : data_(static_cast<uint64>(rhs)) {} |
| - TraceID(long long rhs) : data_(static_cast<uint64>(rhs)) {} |
| - TraceID(long rhs) : data_(static_cast<uint64>(rhs)) {} |
| - TraceID(int rhs) : data_(static_cast<uint64>(rhs)) {} |
| - |
| - uint64 data() const { return data_; } |
| - |
| - private: |
| - uint64 data_; |
| -}; |
| +#define TRACE_EVENT_PHASE_BEGIN ('B') |
| +#define TRACE_EVENT_PHASE_END ('E') |
| +#define TRACE_EVENT_PHASE_INSTANT ('I') |
| +#define TRACE_EVENT_PHASE_START ('S') |
| +#define TRACE_EVENT_PHASE_FINISH ('F') |
| +#define TRACE_EVENT_PHASE_METADATA ('M') |
| +#define TRACE_EVENT_PHASE_COUNTER ('C') |
| + |
| +// Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. |
| +#define TRACE_EVENT_FLAG_NONE (static_cast<unsigned char>(0)) |
| +#define TRACE_EVENT_FLAG_COPY (static_cast<unsigned char>(1<<0)) |
| +#define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned char>(1<<1)) |
| + |
| +// Type values for identifying types in the TraceValue union. |
| +#define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) |
| +#define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) |
| +#define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) |
| +#define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) |
| +#define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) |
| +#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) |
| +#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) |
| // Output records are "Events" and can be obtained via the |
| // OutputCallback whenever the tracing system decides to flush. This |
| @@ -711,26 +631,29 @@ class BASE_EXPORT TraceID { |
| // force it to happen. |
| class BASE_EXPORT TraceEvent { |
| public: |
| + union TraceValue { |
| + bool as_bool; |
| + unsigned long long as_uint; |
| + long long as_int; |
| + double as_double; |
| + const void* as_pointer; |
| + const char* as_string; |
| + }; |
| + |
| TraceEvent(); |
| TraceEvent(int thread_id, |
| TimeTicks timestamp, |
| - TraceEventPhase phase, |
| - const TraceCategory* category, |
| + char phase, |
| + const unsigned char* category_enabled, |
| const char* name, |
| - TraceID id, |
| - const char* arg1_name, const TraceValue& arg1_val, |
| - const char* arg2_name, const TraceValue& arg2_val, |
| - TraceEventFlags flags); |
| + unsigned long long id, |
| + int num_args, |
| + const char** arg_names, |
| + const unsigned char* arg_types, |
| + const unsigned long long* arg_values, |
| + unsigned char flags); |
| ~TraceEvent(); |
| - static char GetPhaseChar(TraceEventPhase phase) { |
| - return static_cast<char>(phase); |
| - } |
| - |
| - static TraceEventPhase GetPhase(const char* phase) { |
| - return static_cast<TraceEventPhase>(*phase); |
| - } |
| - |
| // Serialize event data to JSON |
| static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
| size_t start, |
| @@ -752,15 +675,16 @@ class BASE_EXPORT TraceEvent { |
| // Note: these are ordered by size (largest first) for optimal packing. |
| TimeTicks timestamp_; |
| // id_ can be used to store phase-specific data. |
| - TraceID id_; |
| + unsigned long long id_; |
| TraceValue arg_values_[kTraceMaxNumArgs]; |
| const char* arg_names_[kTraceMaxNumArgs]; |
| - const TraceCategory* category_; |
| + const unsigned char* category_enabled_; |
| const char* name_; |
| scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
| int thread_id_; |
| - TraceEventPhase phase_; |
| - TraceEventFlags flags_; |
| + char phase_; |
| + unsigned char flags_; |
| + unsigned char arg_types_[kTraceMaxNumArgs]; |
| }; |
| @@ -870,7 +794,8 @@ class BASE_EXPORT TraceLog { |
| void Flush(); |
| // Called by TRACE_EVENT* macros, don't call this directly. |
| - static const TraceCategory* GetCategory(const char* name); |
| + static const unsigned char* GetCategoryEnabled(const char* name); |
| + static const char* GetCategoryName(const unsigned char* category_enabled); |
| // Called by TRACE_EVENT* macros, don't call this directly. |
| // Returns the index in the internal vector of the event if it was added, or |
| @@ -880,36 +805,41 @@ class BASE_EXPORT TraceLog { |
| // is less than the threshold, the begin/end event pair is dropped. |
| // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
| // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. |
| - int AddTraceEvent(TraceEventPhase phase, |
| - const TraceCategory* category, |
| + int AddTraceEvent(char phase, |
| + const unsigned char* category_enabled, |
| const char* name, |
| - TraceID id, |
| - const char* arg1_name, TraceValue arg1_val, |
| - const char* arg2_name, TraceValue arg2_val, |
| + unsigned long long id, |
| + int num_args, |
| + const char** arg_names, |
| + const unsigned char* arg_types, |
| + const unsigned long long* arg_values, |
| int threshold_begin_id, |
| - int64 threshold, |
| - TraceEventFlags flags); |
| - static void AddTraceEventEtw(TraceEventPhase phase, |
| + long long threshold, |
|
jar (doing other things)
2012/01/12 21:48:43
nit: Style guide argues for types like int64. I'm
jbates
2012/01/12 22:22:11
In order to make this API available to third party
|
| + unsigned char flags); |
| + static void AddTraceEventEtw(char phase, |
| const char* name, |
| const void* id, |
| const char* extra); |
| - static void AddTraceEventEtw(TraceEventPhase phase, |
| + static void AddTraceEventEtw(char phase, |
| const char* name, |
| const void* id, |
| const std::string& extra); |
| // A wrapper around AddTraceEvent used by TRACE_COUNTERx macros |
| // that allows only integer values for the counters. |
| - int AddCounterEvent(const TraceCategory* category, |
| - const char* name, |
| - TraceID id, |
| - const char* arg1_name, int32 arg1_val, |
| - const char* arg2_name, int32 arg2_val, |
| - TraceEventFlags flags); |
| - |
| - // Mangle |id| with a hash based on the process ID so that if |id| occurs on |
| + void AddCounterEvent(const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + const char* arg1_name, int arg1_val, |
| + const char* arg2_name, int arg2_val, |
| + unsigned char flags); |
| + |
| + // Mangle |ptr| with a hash based on the process ID so that if |ptr| occurs on |
| // more than one process, it will not collide. |
| - uint64 GetIntraProcessID(uint64 id) const { return id ^ process_id_hash_; } |
| + unsigned long long GetInterProcessID(void* ptr) const { |
| + return static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(ptr)) ^ |
| + process_id_hash_; |
| + } |
| int process_id() const { return process_id_; } |
| @@ -937,7 +867,7 @@ class BASE_EXPORT TraceLog { |
| TraceLog(); |
| ~TraceLog(); |
| - const TraceCategory* GetCategoryInternal(const char* name); |
| + const unsigned char* GetCategoryEnabledInternal(const char* name); |
| void AddThreadNameMetadataEvents(); |
| void AddClockSyncMetadataEvents(); |
| @@ -954,14 +884,180 @@ class BASE_EXPORT TraceLog { |
| base::hash_map<int, std::string> thread_names_; |
| // XORed with TraceID to make it unlikely to collide with other processes. |
| - uint64 process_id_hash_; |
| + unsigned long long process_id_hash_; |
| int process_id_; |
| DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| }; |
| -namespace internal { |
| +} // namespace debug |
| +} // namespace base |
| + |
| +namespace trace_event_internal { |
| + |
| +// Specify these values when the corresponding argument of AddTraceEvent is not |
| +// used. |
| +const int kZeroNumArgs = 0; |
| +const int kNoThreshholdBeginId = -1; |
| +const long long kNoThresholdValue = 0; |
| +const unsigned long long kNoEventId = 0; |
| + |
| +// TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| +// are mangled with the Process ID so that they are unlikely to collide when the |
| +// same pointer is used on different processes. |
| +class BASE_EXPORT TraceID { |
| + public: |
| + explicit TraceID(void* rhs) : |
| + data_(TRACE_EVENT_API_GET_ID_FROM_POINTER(rhs)) {} |
| + explicit TraceID(unsigned long long rhs) : data_(rhs) {} |
| + explicit TraceID(unsigned long rhs) : data_(rhs) {} |
| + explicit TraceID(unsigned int rhs) : data_(rhs) {} |
| + explicit TraceID(unsigned short rhs) : data_(rhs) {} |
| + explicit TraceID(unsigned char rhs) : data_(rhs) {} |
| + explicit TraceID(long long rhs) : |
| + data_(static_cast<unsigned long long>(rhs)) {} |
| + explicit TraceID(long rhs) : data_(static_cast<unsigned long long>(rhs)) {} |
| + explicit TraceID(int rhs) : data_(static_cast<unsigned long long>(rhs)) {} |
| + explicit TraceID(short rhs) : data_(static_cast<unsigned long long>(rhs)) {} |
| + explicit TraceID(signed char rhs) : |
| + data_(static_cast<unsigned long long>(rhs)) {} |
| + |
| + unsigned long long data() const { return data_; } |
| + |
| + private: |
| + unsigned long long data_; |
| +}; |
| + |
| +// Simple union to store various types as unsigned long long. |
| +union TraceValueUnion { |
| + bool as_bool; |
| + unsigned long long as_uint; |
| + long long as_int; |
| + double as_double; |
| + const void* as_pointer; |
| + const char* as_string; |
| +}; |
| + |
| +// Simple container for const char* that should be copied instead of retained. |
| +class TraceStringWithCopy { |
| + public: |
| + explicit TraceStringWithCopy(const char* str) : str_(str) {} |
| + operator const char* () const { return str_; } |
| + private: |
| + const char* str_; |
| +}; |
| + |
| +// Define SetTraceValue for each allowed type. It stores the type and |
| +// value in the return arguments. This allows this API to avoid declaring any |
| +// structures so that it is portable to third_party libraries. |
| +#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ |
| + union_member, \ |
| + value_type_id) \ |
| + static inline void SetTraceValue(actual_type arg, \ |
| + unsigned char* type, \ |
| + unsigned long long* value) { \ |
| + TraceValueUnion type_value; \ |
| + type_value.union_member = arg; \ |
| + *type = value_type_id; \ |
| + *value = type_value.as_uint; \ |
| + } |
| +// Simpler form for int types that can be safely casted. |
| +#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ |
| + value_type_id) \ |
| + static inline void SetTraceValue(actual_type arg, \ |
| + unsigned char* type, \ |
| + unsigned long long* value) { \ |
| + *type = value_type_id; \ |
| + *value = static_cast<unsigned long long>(arg); \ |
| + } |
| + |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, |
| + TRACE_VALUE_TYPE_POINTER) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, |
| + TRACE_VALUE_TYPE_STRING) |
| +INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, |
| + TRACE_VALUE_TYPE_COPY_STRING) |
| + |
| +#undef INTERNAL_DECLARE_SET_TRACE_VALUE |
| +#undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT |
| + |
| +// std::string version of SetTraceValue so that trace arguments can be strings. |
| +static inline void SetTraceValue(const std::string& arg, |
| + unsigned char* type, |
| + unsigned long long* value) { |
| + TraceValueUnion type_value; |
| + type_value.as_string = arg.c_str(); |
| + *type = TRACE_VALUE_TYPE_COPY_STRING; |
| + *value = type_value.as_uint; |
| +} |
| + |
| +// These AddTraceEvent template functions are defined here instead of in the |
| +// macro, because the arg_values could be temporary objects, such as |
| +// std::string. In order to store pointers to the internal c_str and pass |
| +// through to the tracing API, the arg_values must live throughout |
| +// these procedures. |
| + |
| +static inline int AddTraceEvent(char phase, |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + unsigned char flags) { |
| + return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| + phase, category_enabled, name, id, |
| + kZeroNumArgs, NULL, NULL, NULL, |
| + kNoThreshholdBeginId, kNoThresholdValue, flags); |
| +} |
| + |
| +template<class ARG1_TYPE> |
| +static inline int AddTraceEvent(char phase, |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + unsigned char flags, |
| + const char* arg1_name, |
| + const ARG1_TYPE& arg1_val) { |
| + const int num_args = 1; |
| + unsigned char arg_types[1]; |
| + unsigned long long arg_values[1]; |
| + SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| + return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| + phase, category_enabled, name, id, |
| + num_args, &arg1_name, arg_types, arg_values, |
| + kNoThreshholdBeginId, kNoThresholdValue, flags); |
| +} |
| + |
| +template<class ARG1_TYPE, class ARG2_TYPE> |
| +static inline int AddTraceEvent(char phase, |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + unsigned char flags, |
| + const char* arg1_name, |
| + const ARG1_TYPE& arg1_val, |
| + const char* arg2_name, |
| + const ARG2_TYPE& arg2_val) { |
| + const int num_args = 2; |
| + const char* arg_names[2] = { arg1_name, arg2_name }; |
| + unsigned char arg_types[2]; |
| + unsigned long long arg_values[2]; |
| + SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| + SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
| + return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| + phase, category_enabled, name, id, |
| + num_args, arg_names, arg_types, arg_values, |
| + kNoThreshholdBeginId, kNoThresholdValue, flags); |
| +} |
| // Used by TRACE_EVENTx macro. Do not use directly. |
| class BASE_EXPORT TraceEndOnScopeClose { |
| @@ -973,7 +1069,7 @@ class BASE_EXPORT TraceEndOnScopeClose { |
| AddEventIfEnabled(); |
| } |
| - void Initialize(const TraceCategory* category, |
| + void Initialize(const unsigned char* category_enabled, |
| const char* name); |
| private: |
| @@ -986,7 +1082,7 @@ class BASE_EXPORT TraceEndOnScopeClose { |
| // members of this class instead, compiler warnings occur about potential |
| // uninitialized accesses. |
| struct Data { |
| - const TraceCategory* category; |
| + const unsigned char* category_enabled; |
| const char* name; |
| }; |
| Data* p_data_; |
| @@ -1005,10 +1101,10 @@ class BASE_EXPORT TraceEndOnScopeCloseThreshold { |
| // Called by macros only when tracing is enabled at the point when the begin |
| // event is added. |
| - void Initialize(const TraceCategory* category, |
| + void Initialize(const unsigned char* category_enabled, |
| const char* name, |
| int threshold_begin_id, |
| - int64 threshold); |
| + long long threshold); |
| private: |
| // Add the end event if the category is still enabled. |
| @@ -1020,8 +1116,8 @@ class BASE_EXPORT TraceEndOnScopeCloseThreshold { |
| // members of this class instead, compiler warnings occur about potential |
| // uninitialized accesses. |
| struct Data { |
| - int64 threshold; |
| - const TraceCategory* category; |
| + long long threshold; |
| + const unsigned char* category_enabled; |
| const char* name; |
| int threshold_begin_id; |
| }; |
| @@ -1029,9 +1125,6 @@ class BASE_EXPORT TraceEndOnScopeCloseThreshold { |
| Data data_; |
| }; |
| -} // namespace internal |
| - |
| -} // namespace debug |
| -} // namespace base |
| +} // namespace trace_event_internal |
| #endif // BASE_DEBUG_TRACE_EVENT_H_ |