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/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::UpdatePseudoStack(phase, name); \ | |
|
Primiano Tucci (use gerrit)
2015/09/18 16:10:01
Rename to MaybeUpdatePseudoStack, as that will hap
Ruud van Asseldonk
2015/09/21 10:10:05
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 // Used by TRACE_EVENTx macros. Do not use directly. | 745 // Used by TRACE_EVENTx macros. Do not use directly. |
| 744 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { | 746 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
| 745 public: | 747 public: |
| 746 // Note: members of data_ intentionally left uninitialized. See Initialize. | 748 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 747 ScopedTracer() : p_data_(NULL) {} | 749 ScopedTracer() : p_data_(NULL) {} |
| 748 | 750 |
| 749 ~ScopedTracer() { | 751 ~ScopedTracer() { |
| 750 if (p_data_ && *data_.category_group_enabled) | 752 if (p_data_ && *data_.category_group_enabled) |
| 751 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 753 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
| 752 data_.category_group_enabled, data_.name, data_.event_handle); | 754 data_.category_group_enabled, data_.name, data_.event_handle); |
| 755 | |
| 756 if (base::trace_event::AllocationContextManager::capture_enabled()) { | |
| 757 auto mgr = base::trace_event::AllocationContextManager::GetInstance(); | |
|
Primiano Tucci (use gerrit)
2015/09/18 16:10:01
mgr is a bit of a generic name. This should be all
Ruud van Asseldonk
2015/09/21 10:10:05
Yeah I split that because I thought the line wrap
| |
| 758 mgr->pseudo_stack().Pop(); | |
| 759 } | |
| 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::AllocationContextManager::capture_enabled()) { | |
| 771 auto mgr = base::trace_event::AllocationContextManager::GetInstance(); | |
| 772 mgr->pseudo_stack().Push(name); | |
| 773 } | |
| 762 } | 774 } |
| 763 | 775 |
| 764 private: | 776 private: |
| 765 // This Data struct workaround is to avoid initializing all the members | 777 // This Data struct workaround is to avoid initializing all the members |
| 766 // in Data during construction of this object, since this object is always | 778 // 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 | 779 // constructed, even when tracing is disabled. If the members of Data were |
| 768 // members of this class instead, compiler warnings occur about potential | 780 // members of this class instead, compiler warnings occur about potential |
| 769 // uninitialized accesses. | 781 // uninitialized accesses. |
| 770 struct Data { | 782 struct Data { |
| 771 const unsigned char* category_group_enabled; | 783 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( | 833 TRACE_EVENT_API_ATOMIC_STORE( |
| 822 g_trace_state[BucketNumber], | 834 g_trace_state[BucketNumber], |
| 823 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | 835 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
| 824 const_cast<char*>(category_and_name))); | 836 const_cast<char*>(category_and_name))); |
| 825 } | 837 } |
| 826 | 838 |
| 827 private: | 839 private: |
| 828 const char* previous_state_; | 840 const char* previous_state_; |
| 829 }; | 841 }; |
| 830 | 842 |
| 843 static inline void UpdatePseudoStack(char phase, const char* name) { | |
| 844 if (base::trace_event::AllocationContextManager::capture_enabled()) { | |
|
Primiano Tucci (use gerrit)
2015/09/18 16:10:01
In chromium we tend to prefer early return instead
Ruud van Asseldonk
2015/09/21 10:10:05
Done.
| |
| 845 auto mgr = base::trace_event::AllocationContextManager::GetInstance(); | |
| 846 | |
| 847 if (phase == TRACE_EVENT_PHASE_BEGIN) | |
| 848 mgr->pseudo_stack().Push(name); | |
| 849 if (phase == TRACE_EVENT_PHASE_END) | |
|
Primiano Tucci (use gerrit)
2015/09/18 16:10:01
s/if/else if/
Ruud van Asseldonk
2015/09/21 10:10:05
Done. The compiler will emit the same code anyway,
| |
| 850 mgr->pseudo_stack().Pop(); | |
| 851 } | |
| 852 } | |
| 853 | |
| 831 } // namespace trace_event_internal | 854 } // namespace trace_event_internal |
| 832 | 855 |
| 833 namespace base { | 856 namespace base { |
| 834 namespace trace_event { | 857 namespace trace_event { |
| 835 | 858 |
| 836 template<typename IDType> class TraceScopedTrackableObject { | 859 template<typename IDType> class TraceScopedTrackableObject { |
| 837 public: | 860 public: |
| 838 TraceScopedTrackableObject(const char* category_group, const char* name, | 861 TraceScopedTrackableObject(const char* category_group, const char* name, |
| 839 IDType id) | 862 IDType id) |
| 840 : category_group_(category_group), | 863 : category_group_(category_group), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 856 const char* name_; | 879 const char* name_; |
| 857 IDType id_; | 880 IDType id_; |
| 858 | 881 |
| 859 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 882 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 860 }; | 883 }; |
| 861 | 884 |
| 862 } // namespace trace_event | 885 } // namespace trace_event |
| 863 } // namespace base | 886 } // namespace base |
| 864 | 887 |
| 865 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 888 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |