Chromium Code Reviews| Index: base/debug/trace_event_internal.h |
| diff --git a/base/debug/trace_event_internal.h b/base/debug/trace_event_internal.h |
| index 96224114894a1d02e95abab6ba8c700c35fe9720..c4eddd951ef546b6a8518852cbb7d6b8e27e8059 100644 |
| --- a/base/debug/trace_event_internal.h |
| +++ b/base/debug/trace_event_internal.h |
| @@ -261,6 +261,23 @@ |
| category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) |
| +// Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. |
| +// - |id| is used to match the _BEGIN event with the _END event. |
| +// Events are considered to match if their category, name and id values all |
| +// match. |id| must either be a pointer or an integer value up to 64 bits. If |
| +// it's a pointer, the bits 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_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category, \ |
| + name, id, tid, ts) \ |
|
jar (doing other things)
2013/02/14 02:17:54
nit: please use larger names, like thread_id, and
dsinclair
2013/02/14 15:38:47
Done.
|
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
| + TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \ |
| + TRACE_EVENT_FLAG_NONE) |
| +#define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ |
| + category, name, id, tid, ts) \ |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
| + TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \ |
| + TRACE_EVENT_FLAG_COPY) |
| + |
| // 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 |
| @@ -288,6 +305,23 @@ |
| category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| arg2_name, arg2_val) |
| +// Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. |
| +// - |id| is used to match the _BEGIN event with the _END event. |
| +// Events are considered to match if their category, name and id values all |
| +// match. |id| must either be a pointer or an integer value up to 64 bits. If |
| +// it's a pointer, the bits 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_END_WITH_ID_TID_AND_TIMESTAMP0(category, \ |
| + name, id, tid, ts) \ |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
| + TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \ |
| + TRACE_EVENT_FLAG_NONE) |
| +#define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ |
| + category, name, id, tid, ts) \ |
| + INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
| + TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \ |
| + TRACE_EVENT_FLAG_COPY) |
| + |
| // Records the value of a counter called "name" immediately. Value |
| // must be representable as a 32 bit integer. |
| // - category and name strings must have application lifetime (statics or |
| @@ -540,7 +574,6 @@ |
| category, name, id, TRACE_EVENT_FLAG_COPY, \ |
| arg1_name, arg1_val, arg2_name, arg2_val) |
| - |
| // Implementation detail: trace event macros create temporary variables |
| // to keep instrumentation overhead low. These macros give each temporary |
| // variable a unique name based on the line number to prevent name collissions. |
| @@ -614,6 +647,23 @@ |
| } \ |
| } while (0) |
| +// Implementation detail: internal macro to create static category and add |
| +// event if the category is enabled. |
| +#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, category, \ |
| + name, id, tid, ts, flags, ...) \ |
| + do { \ |
| + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| + if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| + unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| + trace_event_internal::TraceID trace_event_trace_id( \ |
| + id, &trace_event_flags); \ |
| + trace_event_internal::AddTraceEvent( \ |
| + phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| + name, trace_event_trace_id.data(), tid, ts, \ |
| + trace_event_flags, ##__VA_ARGS__); \ |
| + } \ |
| + } while (0) |
| + |
| // 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 |
| @@ -800,42 +850,73 @@ static inline void SetTraceValue(const std::string& arg, |
| // these procedures. |
| static inline void AddTraceEvent(char phase, |
| - const unsigned char* category_enabled, |
| - const char* name, |
| - unsigned long long id, |
| - unsigned char flags) { |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + int thread_id, |
| + int64 timestamp, |
| + unsigned char flags) { |
| TRACE_EVENT_API_ADD_TRACE_EVENT( |
| - phase, category_enabled, name, id, |
| + phase, category_enabled, name, id, thread_id, timestamp, |
| kZeroNumArgs, NULL, NULL, NULL, flags); |
| } |
| +static inline void AddTraceEvent(char phase, |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + unsigned char flags) { |
| + int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
| + base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
| + AddTraceEvent(phase, category_enabled, name, id, thread_id, |
| + now.ToInternalValue(), flags); |
| +} |
| + |
| template<class ARG1_TYPE> |
| static inline void 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 unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + int thread_id, |
| + int64 timestamp, |
| + 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]); |
| TRACE_EVENT_API_ADD_TRACE_EVENT( |
| - phase, category_enabled, name, id, |
| + phase, category_enabled, name, id, thread_id, timestamp, |
| num_args, &arg1_name, arg_types, arg_values, flags); |
| } |
| +template<class ARG1_TYPE> |
| +static inline void 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) { |
| + int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
| + base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
| + AddTraceEvent(phase, category_enabled, name, id, thread_id, |
| + now.ToInternalValue(), flags, arg1_name, arg1_val); |
| +} |
| + |
| template<class ARG1_TYPE, class ARG2_TYPE> |
| static inline void 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 unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + int thread_id, |
| + int64 timestamp, |
| + 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]; |
| @@ -843,10 +924,27 @@ static inline void AddTraceEvent(char phase, |
| SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
| TRACE_EVENT_API_ADD_TRACE_EVENT( |
| - phase, category_enabled, name, id, |
| + phase, category_enabled, name, id, thread_id, timestamp, |
| num_args, arg_names, arg_types, arg_values, flags); |
| } |
| +template<class ARG1_TYPE, class ARG2_TYPE> |
| +static inline void 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) { |
| + int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
| + base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
| + AddTraceEvent(phase, category_enabled, name, id, thread_id, |
| + now.ToInternalValue(), flags, arg1_name, arg1_val, |
| + arg2_name, arg2_val); |
| +} |
| + |
| // Used by TRACE_EVENTx macro. Do not use directly. |
| class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { |
| public: |
| @@ -864,7 +962,6 @@ class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { |
| p_data_ = &data_; |
| } |
| - |
| private: |
| // Add the end event if the category is still enabled. |
| void AddEventIfEnabled() { |