| OLD | NEW | 
|     1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |     1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|     2 // Use of this source code is governed by a BSD-style license that can be |     2 // Use of this source code is governed by a BSD-style license that can be | 
|     3 // found in the LICENSE file. |     3 // found in the LICENSE file. | 
|     4  |     4  | 
|     5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ |     5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ | 
|     6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ |     6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ | 
|     7  |     7  | 
|     8 // This header file defines implementation details of how the trace macros in |     8 // This header file defines implementation details of how the trace macros in | 
|     9 // trace_event_common.h collect and store trace events. Anything not |     9 // trace_event_common.h collect and store trace events. Anything not | 
|    10 // implementation-specific should go in trace_event_common.h instead of here. |    10 // implementation-specific should go in trace_event_common.h instead of here. | 
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   188 // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method |   188 // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method | 
|   189 // on the convertable value will be called at flush time. |   189 // on the convertable value will be called at flush time. | 
|   190 // TRACE_EVENT_API_ADD_METADATA_EVENT( |   190 // TRACE_EVENT_API_ADD_METADATA_EVENT( | 
|   191 //     const unsigned char* category_group_enabled, |   191 //     const unsigned char* category_group_enabled, | 
|   192 //     const char* event_name, |   192 //     const char* event_name, | 
|   193 //     const char* arg_name, |   193 //     const char* arg_name, | 
|   194 //     std::unique_ptr<ConvertableToTraceFormat> arg_value) |   194 //     std::unique_ptr<ConvertableToTraceFormat> arg_value) | 
|   195 #define TRACE_EVENT_API_ADD_METADATA_EVENT \ |   195 #define TRACE_EVENT_API_ADD_METADATA_EVENT \ | 
|   196     trace_event_internal::AddMetadataEvent |   196     trace_event_internal::AddMetadataEvent | 
|   197  |   197  | 
 |   198 #define TRACE_EVENT_API_ADD_METADATA_EVENT_WITH_TIMESTAMP \ | 
 |   199   trace_event_internal::AddMetadataEventWithTimestamp | 
 |   200  | 
|   198 // Defines atomic operations used internally by the tracing system. |   201 // Defines atomic operations used internally by the tracing system. | 
|   199 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord |   202 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord | 
|   200 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) |   203 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) | 
|   201 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ |   204 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ | 
|   202     base::subtle::NoBarrier_Store(&(var), (value)) |   205     base::subtle::NoBarrier_Store(&(var), (value)) | 
|   203  |   206  | 
|   204 // Defines visibility for classes in trace_event.h |   207 // Defines visibility for classes in trace_event.h | 
|   205 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT |   208 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT | 
|   206  |   209  | 
|   207 // The thread buckets for the sampling profiler. |   210 // The thread buckets for the sampling profiler. | 
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   344           phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,      \ |   347           phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,      \ | 
|   345           trace_event_trace_id.scope(), trace_event_trace_id.raw_id(),        \ |   348           trace_event_trace_id.scope(), trace_event_trace_id.raw_id(),        \ | 
|   346           thread_id, base::TimeTicks::FromInternalValue(timestamp),           \ |   349           thread_id, base::TimeTicks::FromInternalValue(timestamp),           \ | 
|   347           trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP,            \ |   350           trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP,            \ | 
|   348           trace_event_internal::kNoId, ##__VA_ARGS__);                        \ |   351           trace_event_internal::kNoId, ##__VA_ARGS__);                        \ | 
|   349     }                                                                         \ |   352     }                                                                         \ | 
|   350   } while (0) |   353   } while (0) | 
|   351  |   354  | 
|   352 // Implementation detail: internal macro to create static category and add |   355 // Implementation detail: internal macro to create static category and add | 
|   353 // metadata event if the category is enabled. |   356 // metadata event if the category is enabled. | 
|   354 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...)        \ |   357 #define INTERNAL_TRACE_EVENT_METADATA_ADD_IF_ENABLED(category_group, name,  \ | 
 |   358                                                      ...)                   \ | 
|   355   do {                                                                      \ |   359   do {                                                                      \ | 
|   356     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                 \ |   360     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                 \ | 
|   357     if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |   361     if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 
|   358       TRACE_EVENT_API_ADD_METADATA_EVENT(                                   \ |   362       TRACE_EVENT_API_ADD_METADATA_EVENT(                                   \ | 
 |   363           TRACE_EVENT_PHASE_METADATA,                                       \ | 
|   359           INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,           \ |   364           INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,           \ | 
|   360           ##__VA_ARGS__);                                                   \ |   365           ##__VA_ARGS__);                                                   \ | 
|   361     }                                                                       \ |   366     }                                                                       \ | 
|   362   } while (0) |   367   } while (0) | 
|   363  |   368  | 
 |   369 #define INTERNAL_TRACE_EVENT_METADATA_ADD_FORCED(phase, name, ...)             \ | 
 |   370   do {                                                                         \ | 
 |   371     TRACE_EVENT_API_ADD_METADATA_EVENT(                                        \ | 
 |   372         phase, TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("__metadata"), name, \ | 
 |   373         ##__VA_ARGS__);                                                        \ | 
 |   374   } while (0) | 
 |   375  | 
 |   376 #define INTERNAL_TRACE_EVENT_METADATA_ADD_FORCED_WITH_TIMESTAMP(               \ | 
 |   377     phase, name, timestamp, ...)                                               \ | 
 |   378   do {                                                                         \ | 
 |   379     TRACE_EVENT_API_ADD_METADATA_EVENT_WITH_TIMESTAMP(                         \ | 
 |   380         phase, TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("__metadata"), name, \ | 
 |   381         base::TimeTicks::FromInternalValue(timestamp), ##__VA_ARGS__);         \ | 
 |   382   } while (0) | 
 |   383  | 
|   364 // Implementation detail: internal macro to enter and leave a |   384 // Implementation detail: internal macro to enter and leave a | 
|   365 // context based on the current scope. |   385 // context based on the current scope. | 
|   366 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ |   386 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ | 
|   367   struct INTERNAL_TRACE_EVENT_UID(ScopedContext) {                         \ |   387   struct INTERNAL_TRACE_EVENT_UID(ScopedContext) {                         \ | 
|   368    public:                                                                 \ |   388    public:                                                                 \ | 
|   369     INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) {    \ |   389     INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) {    \ | 
|   370       TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_);               \ |   390       TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_);               \ | 
|   371     }                                                                      \ |   391     }                                                                      \ | 
|   372     ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() {                           \ |   392     ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() {                           \ | 
|   373       TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_);               \ |   393       TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_);               \ | 
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   927     const char* arg2_name, |   947     const char* arg2_name, | 
|   928     const ARG2_TYPE& arg2_val) { |   948     const ARG2_TYPE& arg2_val) { | 
|   929   int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |   949   int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 
|   930   base::TimeTicks now = base::TimeTicks::Now(); |   950   base::TimeTicks now = base::TimeTicks::Now(); | 
|   931   return AddTraceEventWithThreadIdAndTimestamp( |   951   return AddTraceEventWithThreadIdAndTimestamp( | 
|   932       phase, category_group_enabled, name, scope, id, thread_id, now, flags, |   952       phase, category_group_enabled, name, scope, id, thread_id, now, flags, | 
|   933       bind_id, arg1_name, arg1_val, arg2_name, arg2_val); |   953       bind_id, arg1_name, arg1_val, arg2_name, arg2_val); | 
|   934 } |   954 } | 
|   935  |   955  | 
|   936 template <class ARG1_CONVERTABLE_TYPE> |   956 template <class ARG1_CONVERTABLE_TYPE> | 
|   937 static inline void AddMetadataEvent( |   957 static inline void AddMetadataEventWithTimestamp( | 
 |   958     char phase, | 
|   938     const unsigned char* category_group_enabled, |   959     const unsigned char* category_group_enabled, | 
|   939     const char* event_name, |   960     const char* event_name, | 
 |   961     const base::TimeTicks& timestamp, | 
|   940     const char* arg_name, |   962     const char* arg_name, | 
|   941     std::unique_ptr<ARG1_CONVERTABLE_TYPE> arg_value) { |   963     std::unique_ptr<ARG1_CONVERTABLE_TYPE> arg_value) { | 
|   942   const char* arg_names[1] = {arg_name}; |   964   const char* arg_names[1] = {arg_name}; | 
|   943   unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; |   965   unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; | 
|   944   std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |   966   std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 
|   945       convertable_values[1] = {std::move(arg_value)}; |   967       convertable_values[1] = {std::move(arg_value)}; | 
 |   968  | 
|   946   base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( |   969   base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( | 
|   947       category_group_enabled, event_name, |   970       phase, category_group_enabled, event_name, timestamp, | 
|   948       1,  // num_args |   971       1,  // num_args | 
|   949       arg_names, arg_types, |   972       arg_names, arg_types, | 
|   950       nullptr,  // arg_values |   973       nullptr,  // arg_values | 
|   951       convertable_values, TRACE_EVENT_FLAG_NONE); |   974       convertable_values, TRACE_EVENT_FLAG_NONE); | 
|   952 } |   975 } | 
|   953  |   976  | 
 |   977 template <class ARG1_TYPE, class ARG2_TYPE> | 
 |   978 static inline void AddMetadataEventWithTimestamp( | 
 |   979     char phase, | 
 |   980     const unsigned char* category_group_enabled, | 
 |   981     const char* event_name, | 
 |   982     const base::TimeTicks& timestamp, | 
 |   983     const char* arg1_name, | 
 |   984     const ARG1_TYPE& arg1_val, | 
 |   985     const char* arg2_name, | 
 |   986     const ARG2_TYPE& arg2_val) { | 
 |   987   const int num_args = 2; | 
 |   988   const char* arg_names[2] = {arg1_name, arg2_name}; | 
 |   989   unsigned char arg_types[2]; | 
 |   990   unsigned long long arg_values[2]; | 
 |   991   SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 
 |   992   SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 
 |   993   base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( | 
 |   994       phase, category_group_enabled, event_name, timestamp, num_args, arg_names, | 
 |   995       arg_types, arg_values, nullptr, TRACE_EVENT_FLAG_NONE); | 
 |   996 } | 
 |   997  | 
 |   998 template <class ARG1_TYPE, class ARG2_CONVERTABLE_TYPE> | 
 |   999 static inline void AddMetadataEventWithTimestamp( | 
 |  1000     char phase, | 
 |  1001     const unsigned char* category_group_enabled, | 
 |  1002     const char* event_name, | 
 |  1003     const base::TimeTicks& timestamp, | 
 |  1004     const char* arg1_name, | 
 |  1005     const ARG1_TYPE& arg1_val, | 
 |  1006     const char* arg2_name, | 
 |  1007     std::unique_ptr<ARG2_CONVERTABLE_TYPE> arg2_val) { | 
 |  1008   AddMetadataEventWithTimestamp(phase, category_group_enabled, event_name, | 
 |  1009                                 timestamp, arg1_name, arg1_val, arg2_name, | 
 |  1010                                 std::move(arg2_val)); | 
 |  1011 } | 
 |  1012  | 
|   954 template <class ARG1_TYPE> |  1013 template <class ARG1_TYPE> | 
|   955 static void AddMetadataEvent(const unsigned char* category_group_enabled, |  1014 static inline void AddMetadataEventWithTimestamp( | 
|   956                              const char* event_name, |  1015     char phase, | 
|   957                              const char* arg_name, |  1016     const unsigned char* category_group_enabled, | 
|   958                              const ARG1_TYPE& arg_val) { |  1017     const char* event_name, | 
 |  1018     const base::TimeTicks& timestamp, | 
 |  1019     const char* arg_name, | 
 |  1020     const ARG1_TYPE& arg_val) { | 
|   959   const int num_args = 1; |  1021   const int num_args = 1; | 
|   960   const char* arg_names[1] = {arg_name}; |  1022   const char* arg_names[1] = {arg_name}; | 
|   961   unsigned char arg_types[1]; |  1023   unsigned char arg_types[1]; | 
|   962   unsigned long long arg_values[1]; |  1024   unsigned long long arg_values[1]; | 
|   963   SetTraceValue(arg_val, &arg_types[0], &arg_values[0]); |  1025   SetTraceValue(arg_val, &arg_types[0], &arg_values[0]); | 
|   964  |  1026  | 
|   965   base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( |  1027   base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( | 
|   966       category_group_enabled, event_name, num_args, arg_names, arg_types, |  1028       phase, category_group_enabled, event_name, timestamp, num_args, arg_names, | 
|   967       arg_values, nullptr, TRACE_EVENT_FLAG_NONE); |  1029       arg_types, arg_values, nullptr, TRACE_EVENT_FLAG_NONE); | 
 |  1030 } | 
 |  1031  | 
 |  1032 template <class ARG1_CONVERTABLE_TYPE> | 
 |  1033 static inline void AddMetadataEvent( | 
 |  1034     char phase, | 
 |  1035     const unsigned char* category_group_enabled, | 
 |  1036     const char* event_name, | 
 |  1037     const char* arg_name, | 
 |  1038     std::unique_ptr<ARG1_CONVERTABLE_TYPE> arg_value) { | 
 |  1039   base::TimeTicks now = base::TimeTicks::Now(); | 
 |  1040   AddMetadataEventWithTimestamp(phase, category_group_enabled, event_name, now, | 
 |  1041                                 arg_name, std::move(arg_value)); | 
 |  1042 } | 
 |  1043  | 
 |  1044 template <class ARG1_TYPE> | 
 |  1045 static void AddMetadataEvent(char phase, | 
 |  1046                              const unsigned char* category_group_enabled, | 
 |  1047                              const char* event_name, | 
 |  1048                              const char* arg_name, | 
 |  1049                              const ARG1_TYPE& arg_val) { | 
 |  1050   base::TimeTicks now = base::TimeTicks::Now(); | 
 |  1051   AddMetadataEventWithTimestamp(phase, category_group_enabled, event_name, now, | 
 |  1052                                 arg_name, arg_val); | 
|   968 } |  1053 } | 
|   969  |  1054  | 
|   970 // Used by TRACE_EVENTx macros. Do not use directly. |  1055 // Used by TRACE_EVENTx macros. Do not use directly. | 
|   971 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |  1056 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | 
|   972  public: |  1057  public: | 
|   973   // Note: members of data_ intentionally left uninitialized. See Initialize. |  1058   // Note: members of data_ intentionally left uninitialized. See Initialize. | 
|   974   ScopedTracer() : p_data_(NULL) {} |  1059   ScopedTracer() : p_data_(NULL) {} | 
|   975  |  1060  | 
|   976   ~ScopedTracer() { |  1061   ~ScopedTracer() { | 
|   977     if (p_data_ && *data_.category_group_enabled) |  1062     if (p_data_ && *data_.category_group_enabled) | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1083   const char* name_; |  1168   const char* name_; | 
|  1084   IDType id_; |  1169   IDType id_; | 
|  1085  |  1170  | 
|  1086   DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |  1171   DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 
|  1087 }; |  1172 }; | 
|  1088  |  1173  | 
|  1089 }  // namespace trace_event |  1174 }  // namespace trace_event | 
|  1090 }  // namespace base |  1175 }  // namespace base | 
|  1091  |  1176  | 
|  1092 #endif  // BASE_TRACE_EVENT_TRACE_EVENT_H_ |  1177 #endif  // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 
| OLD | NEW |