Chromium Code Reviews| 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_macros_common.h instead of here. |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/atomicops.h" | 14 #include "base/atomicops.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/trace_event/memory_profiler_allocation_context.h" | |
| 16 #include "base/trace_event/trace_event_common.h" | 17 #include "base/trace_event/trace_event_common.h" |
| 17 #include "base/trace_event/trace_event_memory.h" | 18 #include "base/trace_event/trace_event_memory.h" |
| 18 #include "base/trace_event/trace_event_system_stats_monitor.h" | 19 #include "base/trace_event/trace_event_system_stats_monitor.h" |
| 19 #include "base/trace_event/trace_log.h" | 20 #include "base/trace_event/trace_log.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 | 22 |
| 22 // By default, const char* argument values are assumed to have long-lived scope | 23 // By default, const char* argument values are assumed to have long-lived scope |
| 23 // and will not be copied. Use this macro to force a const char* to be copied. | 24 // and will not be copied. Use this macro to force a const char* to be copied. |
| 24 #define TRACE_STR_COPY(str) \ | 25 #define TRACE_STR_COPY(str) \ |
| 25 trace_event_internal::TraceStringWithCopy(str) | 26 trace_event_internal::TraceStringWithCopy(str) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // Implementation detail: internal macro to create static category and add | 210 // Implementation detail: internal macro to create static category and add |
| 210 // event if the category is enabled. | 211 // event if the category is enabled. |
| 211 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ | 212 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ |
| 212 do { \ | 213 do { \ |
| 213 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 214 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 214 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 215 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 215 trace_event_internal::AddTraceEvent( \ | 216 trace_event_internal::AddTraceEvent( \ |
| 216 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 217 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 217 trace_event_internal::kNoId, flags, \ | 218 trace_event_internal::kNoId, flags, \ |
| 218 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 219 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 220 trace_event_internal::MaybeUpdatePseudoStack(phase, name); \ | |
|
Primiano Tucci (use gerrit)
2015/09/24 14:45:20
My main concerns here are:
1) this is a bit fragil
Ruud van Asseldonk
2015/09/24 15:16:21
Done.
| |
| 219 } \ | 221 } \ |
| 220 } while (0) | 222 } while (0) |
| 221 | 223 |
| 222 // Implementation detail: internal macro to create static category and add begin | 224 // Implementation detail: internal macro to create static category and add begin |
| 223 // event if the category is enabled. Also adds the end event when the scope | 225 // event if the category is enabled. Also adds the end event when the scope |
| 224 // ends. | 226 // ends. |
| 225 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ | 227 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ |
| 226 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 228 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 227 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ | 229 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ |
| 228 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 230 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 do { \ | 263 do { \ |
| 262 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 264 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 263 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 265 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 264 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 266 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| 265 trace_event_internal::TraceID trace_event_trace_id( \ | 267 trace_event_internal::TraceID trace_event_trace_id( \ |
| 266 id, &trace_event_flags); \ | 268 id, &trace_event_flags); \ |
| 267 trace_event_internal::AddTraceEvent( \ | 269 trace_event_internal::AddTraceEvent( \ |
| 268 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 270 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 269 name, trace_event_trace_id.data(), trace_event_flags, \ | 271 name, trace_event_trace_id.data(), trace_event_flags, \ |
| 270 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 272 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 273 trace_event_internal::MaybeUpdatePseudoStack(phase, name); \ | |
| 271 } \ | 274 } \ |
| 272 } while (0) | 275 } while (0) |
| 273 | 276 |
| 274 // Implementation detail: internal macro to create static category and add | 277 // Implementation detail: internal macro to create static category and add |
| 275 // event if the category is enabled. | 278 // event if the category is enabled. |
| 276 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ | 279 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ |
| 277 category_group, name, id, thread_id, timestamp, flags, ...) \ | 280 category_group, name, id, thread_id, timestamp, flags, ...) \ |
| 278 do { \ | 281 do { \ |
| 279 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 282 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 280 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 283 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 281 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 284 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| 282 trace_event_internal::TraceID trace_event_trace_id( \ | 285 trace_event_internal::TraceID trace_event_trace_id( \ |
| 283 id, &trace_event_flags); \ | 286 id, &trace_event_flags); \ |
| 284 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 287 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
| 285 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 288 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 286 name, trace_event_trace_id.data(), trace_event_internal::kNoId, \ | 289 name, trace_event_trace_id.data(), trace_event_internal::kNoId, \ |
| 287 thread_id, base::TraceTicks::FromInternalValue(timestamp), \ | 290 thread_id, base::TraceTicks::FromInternalValue(timestamp), \ |
| 288 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 291 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
| 289 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 292 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 293 trace_event_internal::MaybeUpdatePseudoStack(phase, name); \ | |
| 290 } \ | 294 } \ |
| 291 } while (0) | 295 } while (0) |
| 292 | 296 |
| 293 | 297 |
| 294 namespace trace_event_internal { | 298 namespace trace_event_internal { |
| 295 | 299 |
| 296 // Specify these values when the corresponding argument of AddTraceEvent is not | 300 // Specify these values when the corresponding argument of AddTraceEvent is not |
| 297 // used. | 301 // used. |
| 298 const int kZeroNumArgs = 0; | 302 const int kZeroNumArgs = 0; |
| 299 const unsigned long long kNoId = 0; | 303 const unsigned long long kNoId = 0; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 // Used by TRACE_EVENTx macros. Do not use directly. | 747 // Used by TRACE_EVENTx macros. Do not use directly. |
| 744 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | 748 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
| 745 public: | 749 public: |
| 746 // Note: members of data_ intentionally left uninitialized. See Initialize. | 750 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 747 ScopedTracer() : p_data_(NULL) {} | 751 ScopedTracer() : p_data_(NULL) {} |
| 748 | 752 |
| 749 ~ScopedTracer() { | 753 ~ScopedTracer() { |
| 750 if (p_data_ && *data_.category_group_enabled) | 754 if (p_data_ && *data_.category_group_enabled) |
| 751 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 755 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
| 752 data_.category_group_enabled, data_.name, data_.event_handle); | 756 data_.category_group_enabled, data_.name, data_.event_handle); |
| 757 | |
| 758 if (base::trace_event::AllocationContextTracker::capture_enabled()) | |
| 759 base::trace_event::AllocationContextTracker::PopPseudoStackFrame(); | |
| 753 } | 760 } |
| 754 | 761 |
| 755 void Initialize(const unsigned char* category_group_enabled, | 762 void Initialize(const unsigned char* category_group_enabled, |
| 756 const char* name, | 763 const char* name, |
| 757 base::trace_event::TraceEventHandle event_handle) { | 764 base::trace_event::TraceEventHandle event_handle) { |
| 758 data_.category_group_enabled = category_group_enabled; | 765 data_.category_group_enabled = category_group_enabled; |
| 759 data_.name = name; | 766 data_.name = name; |
| 760 data_.event_handle = event_handle; | 767 data_.event_handle = event_handle; |
| 761 p_data_ = &data_; | 768 p_data_ = &data_; |
| 769 | |
| 770 if (base::trace_event::AllocationContextTracker::capture_enabled()) | |
| 771 base::trace_event::AllocationContextTracker::PushPseudoStackFrame(name); | |
| 762 } | 772 } |
| 763 | 773 |
| 764 private: | 774 private: |
| 765 // This Data struct workaround is to avoid initializing all the members | 775 // This Data struct workaround is to avoid initializing all the members |
| 766 // in Data during construction of this object, since this object is always | 776 // in Data during construction of this object, since this object is always |
| 767 // constructed, even when tracing is disabled. If the members of Data were | 777 // constructed, even when tracing is disabled. If the members of Data were |
| 768 // members of this class instead, compiler warnings occur about potential | 778 // members of this class instead, compiler warnings occur about potential |
| 769 // uninitialized accesses. | 779 // uninitialized accesses. |
| 770 struct Data { | 780 struct Data { |
| 771 const unsigned char* category_group_enabled; | 781 const unsigned char* category_group_enabled; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 TRACE_EVENT_API_ATOMIC_STORE( | 831 TRACE_EVENT_API_ATOMIC_STORE( |
| 822 g_trace_state[BucketNumber], | 832 g_trace_state[BucketNumber], |
| 823 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | 833 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
| 824 const_cast<char*>(category_and_name))); | 834 const_cast<char*>(category_and_name))); |
| 825 } | 835 } |
| 826 | 836 |
| 827 private: | 837 private: |
| 828 const char* previous_state_; | 838 const char* previous_state_; |
| 829 }; | 839 }; |
| 830 | 840 |
| 841 static inline void MaybeUpdatePseudoStack(char phase, const char* name) { | |
| 842 if (!base::trace_event::AllocationContextTracker::capture_enabled()) | |
| 843 return; | |
| 844 | |
| 845 if (phase == TRACE_EVENT_PHASE_BEGIN) | |
| 846 base::trace_event::AllocationContextTracker::PushPseudoStackFrame(name); | |
| 847 else if (phase == TRACE_EVENT_PHASE_END) | |
| 848 base::trace_event::AllocationContextTracker::PopPseudoStackFrame(); | |
| 849 } | |
| 850 | |
| 831 } // namespace trace_event_internal | 851 } // namespace trace_event_internal |
| 832 | 852 |
| 833 namespace base { | 853 namespace base { |
| 834 namespace trace_event { | 854 namespace trace_event { |
| 835 | 855 |
| 836 template<typename IDType> class TraceScopedTrackableObject { | 856 template<typename IDType> class TraceScopedTrackableObject { |
| 837 public: | 857 public: |
| 838 TraceScopedTrackableObject(const char* category_group, const char* name, | 858 TraceScopedTrackableObject(const char* category_group, const char* name, |
| 839 IDType id) | 859 IDType id) |
| 840 : category_group_(category_group), | 860 : category_group_(category_group), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 856 const char* name_; | 876 const char* name_; |
| 857 IDType id_; | 877 IDType id_; |
| 858 | 878 |
| 859 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 879 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 860 }; | 880 }; |
| 861 | 881 |
| 862 } // namespace trace_event | 882 } // namespace trace_event |
| 863 } // namespace base | 883 } // namespace base |
| 864 | 884 |
| 865 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 885 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |