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_macros_common.h instead of here. | 10 // implementation-specific should go in trace_event_common.h instead of here. |
11 | 11 |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/atomicops.h" | 17 #include "base/atomicops.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/trace_event/common/trace_event_common.h" | 20 #include "base/trace_event/common/trace_event_common.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 180 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
181 // const unsigned char* category_group_enabled, | 181 // const unsigned char* category_group_enabled, |
182 // const char* name, | 182 // const char* name, |
183 // base::trace_event::TraceEventHandle id) | 183 // base::trace_event::TraceEventHandle id) |
184 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | 184 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ |
185 base::trace_event::TraceLog::GetInstance()->UpdateTraceEventDuration | 185 base::trace_event::TraceLog::GetInstance()->UpdateTraceEventDuration |
186 | 186 |
187 // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method | 187 // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method |
188 // on the convertable value will be called at flush time. | 188 // on the convertable value will be called at flush time. |
189 // TRACE_EVENT_API_ADD_METADATA_EVENT( | 189 // TRACE_EVENT_API_ADD_METADATA_EVENT( |
190 // const char* event_name, | 190 // const unsigned char* category_group_enabled, |
191 // const char* arg_name, | 191 // const char* event_name, |
192 // scoped_refptr<ConvertableToTraceFormat> arg_value) | 192 // const char* arg_name, |
| 193 // scoped_refptr<ConvertableToTraceFormat> arg_value) |
193 #define TRACE_EVENT_API_ADD_METADATA_EVENT \ | 194 #define TRACE_EVENT_API_ADD_METADATA_EVENT \ |
194 trace_event_internal::AddMetadataEvent | 195 trace_event_internal::AddMetadataEvent |
195 | 196 |
196 // Defines atomic operations used internally by the tracing system. | 197 // Defines atomic operations used internally by the tracing system. |
197 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord | 198 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord |
198 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) | 199 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) |
199 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ | 200 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ |
200 base::subtle::NoBarrier_Store(&(var), (value)) | 201 base::subtle::NoBarrier_Store(&(var), (value)) |
201 | 202 |
202 // Defines visibility for classes in trace_event.h | 203 // Defines visibility for classes in trace_event.h |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 &trace_event_flags); \ | 341 &trace_event_flags); \ |
341 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 342 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
342 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 343 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
343 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 344 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
344 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ | 345 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ |
345 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 346 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
346 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 347 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
347 } \ | 348 } \ |
348 } while (0) | 349 } while (0) |
349 | 350 |
350 // Implementation detail: internal macro to enter and leave a context based on | 351 // Implementation detail: internal macro to create static category and add |
351 // the current scope. | 352 // metadata event if the category is enabled. |
| 353 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ |
| 354 do { \ |
| 355 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 356 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 357 TRACE_EVENT_API_ADD_METADATA_EVENT( \ |
| 358 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 359 ##__VA_ARGS__); \ |
| 360 } \ |
| 361 } while (0) |
| 362 |
| 363 // Implementation detail: internal macro to enter and leave a |
| 364 // context based on the current scope. |
352 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ | 365 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ |
353 struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \ | 366 struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \ |
354 public: \ | 367 public: \ |
355 INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \ | 368 INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \ |
356 TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \ | 369 TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \ |
357 } \ | 370 } \ |
358 ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \ | 371 ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \ |
359 TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \ | 372 TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \ |
360 } \ | 373 } \ |
361 \ | 374 \ |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 const char* arg2_name, | 844 const char* arg2_name, |
832 const ARG2_TYPE& arg2_val) { | 845 const ARG2_TYPE& arg2_val) { |
833 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 846 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
834 base::TimeTicks now = base::TimeTicks::Now(); | 847 base::TimeTicks now = base::TimeTicks::Now(); |
835 return AddTraceEventWithThreadIdAndTimestamp( | 848 return AddTraceEventWithThreadIdAndTimestamp( |
836 phase, category_group_enabled, name, scope, id, thread_id, now, flags, | 849 phase, category_group_enabled, name, scope, id, thread_id, now, flags, |
837 bind_id, arg1_name, arg1_val, arg2_name, arg2_val); | 850 bind_id, arg1_name, arg1_val, arg2_name, arg2_val); |
838 } | 851 } |
839 | 852 |
840 static inline void AddMetadataEvent( | 853 static inline void AddMetadataEvent( |
| 854 const unsigned char* category_group_enabled, |
841 const char* event_name, | 855 const char* event_name, |
842 const char* arg_name, | 856 const char* arg_name, |
843 scoped_refptr<base::trace_event::ConvertableToTraceFormat> arg_value) { | 857 scoped_refptr<base::trace_event::ConvertableToTraceFormat> arg_value) { |
844 const char* arg_names[1] = {arg_name}; | 858 const char* arg_names[1] = {arg_name}; |
845 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 859 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
846 convertable_values[1] = {arg_value}; | 860 convertable_values[1] = {arg_value}; |
847 unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; | 861 unsigned char arg_types[1] = {TRACE_VALUE_TYPE_CONVERTABLE}; |
848 base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( | 862 base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( |
849 event_name, | 863 category_group_enabled, event_name, |
850 1, // num_args | 864 1, // num_args |
851 arg_names, arg_types, | 865 arg_names, arg_types, |
852 nullptr, // arg_values | 866 nullptr, // arg_values |
853 convertable_values, TRACE_EVENT_FLAG_NONE); | 867 convertable_values, TRACE_EVENT_FLAG_NONE); |
854 } | 868 } |
855 | 869 |
856 template <class ARG1_TYPE> | 870 template <class ARG1_TYPE> |
857 static void AddMetadataEvent(const char* event_name, | 871 static void AddMetadataEvent(const unsigned char* category_group_enabled, |
| 872 const char* event_name, |
858 const char* arg_name, | 873 const char* arg_name, |
859 const ARG1_TYPE& arg_val) { | 874 const ARG1_TYPE& arg_val) { |
860 const int num_args = 1; | 875 const int num_args = 1; |
861 const char* arg_names[1] = {arg_name}; | 876 const char* arg_names[1] = {arg_name}; |
862 unsigned char arg_types[1]; | 877 unsigned char arg_types[1]; |
863 unsigned long long arg_values[1]; | 878 unsigned long long arg_values[1]; |
864 SetTraceValue(arg_val, &arg_types[0], &arg_values[0]); | 879 SetTraceValue(arg_val, &arg_types[0], &arg_values[0]); |
865 | 880 |
866 base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( | 881 base::trace_event::TraceLog::GetInstance()->AddMetadataEvent( |
867 event_name, num_args, arg_names, arg_types, arg_values, nullptr, | 882 category_group_enabled, event_name, num_args, arg_names, arg_types, |
868 TRACE_EVENT_FLAG_NONE); | 883 arg_values, nullptr, TRACE_EVENT_FLAG_NONE); |
869 } | 884 } |
870 | 885 |
871 // Used by TRACE_EVENTx macros. Do not use directly. | 886 // Used by TRACE_EVENTx macros. Do not use directly. |
872 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | 887 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
873 public: | 888 public: |
874 // Note: members of data_ intentionally left uninitialized. See Initialize. | 889 // Note: members of data_ intentionally left uninitialized. See Initialize. |
875 ScopedTracer() : p_data_(NULL) {} | 890 ScopedTracer() : p_data_(NULL) {} |
876 | 891 |
877 ~ScopedTracer() { | 892 ~ScopedTracer() { |
878 if (p_data_ && *data_.category_group_enabled) | 893 if (p_data_ && *data_.category_group_enabled) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 const char* name_; | 999 const char* name_; |
985 IDType id_; | 1000 IDType id_; |
986 | 1001 |
987 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1002 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
988 }; | 1003 }; |
989 | 1004 |
990 } // namespace trace_event | 1005 } // namespace trace_event |
991 } // namespace base | 1006 } // namespace base |
992 | 1007 |
993 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1008 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
OLD | NEW |