Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: base/trace_event/trace_event.h

Issue 1340013002: Add thread-local allocation context for tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not allow frame metadata, hook begin/end macros Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/pseudo_stack.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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 202
202 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ 203 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
203 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 204 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
204 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ 205 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
205 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \ 206 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \
206 INTERNAL_TRACE_EVENT_UID(atomic), \ 207 INTERNAL_TRACE_EVENT_UID(atomic), \
207 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); 208 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
208 209
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, ...) \
dsinclair 2015/09/17 14:22:32 Can you please put the \'s back where they were to
Ruud van Asseldonk 2015/09/17 15:19:56 Done. Just know that git cl format did this.
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, trace_event_internal::kNoId, \
dsinclair 2015/09/17 14:22:32 Put wrapping back as well, makes it easier to see
Ruud van Asseldonk 2015/09/17 15:19:56 Done.
218 trace_event_internal::kNoId, ##__VA_ARGS__); \ 219 ##__VA_ARGS__); \
219 } \ 220 trace_event_internal::UpdatePseudoStack(phase, name); \
220 } while (0) 221 } \
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()) { \
229 base::trace_event::TraceEventHandle h = \ 231 base::trace_event::TraceEventHandle h = \
230 trace_event_internal::AddTraceEvent( \ 232 trace_event_internal::AddTraceEvent( \
(...skipping 18 matching lines...) Expand all
249 TRACE_EVENT_PHASE_COMPLETE, \ 251 TRACE_EVENT_PHASE_COMPLETE, \
250 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 252 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
251 trace_event_internal::kNoId, trace_event_flags, \ 253 trace_event_internal::kNoId, trace_event_flags, \
252 trace_event_bind_id.data(), ##__VA_ARGS__); \ 254 trace_event_bind_id.data(), ##__VA_ARGS__); \
253 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ 255 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
254 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ 256 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
255 } 257 }
256 258
257 // Implementation detail: internal macro to create static category and add 259 // Implementation detail: internal macro to create static category and add
258 // event if the category is enabled. 260 // event if the category is enabled.
259 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 261 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
dsinclair 2015/09/17 14:22:32 What about these variants?
260 flags, ...) \ 262 flags, ...) \
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, \
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::GetPseudoStackCaptureEnabled())
757 base::trace_event::PseudoStack::GetInstance()->Pop();
753 } 758 }
dsinclair 2015/09/17 14:22:32 nit: no {}'s on single line bodies.
Ruud van Asseldonk 2015/09/17 15:19:56 Done.
754 759
755 void Initialize(const unsigned char* category_group_enabled, 760 void Initialize(const unsigned char* category_group_enabled,
756 const char* name, 761 const char* name,
757 base::trace_event::TraceEventHandle event_handle) { 762 base::trace_event::TraceEventHandle event_handle) {
758 data_.category_group_enabled = category_group_enabled; 763 data_.category_group_enabled = category_group_enabled;
759 data_.name = name; 764 data_.name = name;
760 data_.event_handle = event_handle; 765 data_.event_handle = event_handle;
761 p_data_ = &data_; 766 p_data_ = &data_;
767
768 if (base::trace_event::GetPseudoStackCaptureEnabled()) {
769 base::trace_event::PseudoStack::GetInstance()->Push(name);
770 }
762 } 771 }
763 772
764 private: 773 private:
765 // This Data struct workaround is to avoid initializing all the members 774 // This Data struct workaround is to avoid initializing all the members
766 // in Data during construction of this object, since this object is always 775 // 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 776 // constructed, even when tracing is disabled. If the members of Data were
768 // members of this class instead, compiler warnings occur about potential 777 // members of this class instead, compiler warnings occur about potential
769 // uninitialized accesses. 778 // uninitialized accesses.
770 struct Data { 779 struct Data {
771 const unsigned char* category_group_enabled; 780 const unsigned char* category_group_enabled;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 TRACE_EVENT_API_ATOMIC_STORE( 830 TRACE_EVENT_API_ATOMIC_STORE(
822 g_trace_state[BucketNumber], 831 g_trace_state[BucketNumber],
823 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( 832 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
824 const_cast<char*>(category_and_name))); 833 const_cast<char*>(category_and_name)));
825 } 834 }
826 835
827 private: 836 private:
828 const char* previous_state_; 837 const char* previous_state_;
829 }; 838 };
830 839
840 static inline void UpdatePseudoStack(char phase, const char* name) {
841 if (base::trace_event::GetPseudoStackCaptureEnabled()) {
842 if (phase == TRACE_EVENT_PHASE_BEGIN)
843 base::trace_event::PseudoStack::GetInstance()->Push(name);
844 if (phase == TRACE_EVENT_PHASE_END)
845 base::trace_event::PseudoStack::GetInstance()->Pop();
846 }
847 }
848
831 } // namespace trace_event_internal 849 } // namespace trace_event_internal
832 850
833 namespace base { 851 namespace base {
834 namespace trace_event { 852 namespace trace_event {
835 853
836 template<typename IDType> class TraceScopedTrackableObject { 854 template<typename IDType> class TraceScopedTrackableObject {
837 public: 855 public:
838 TraceScopedTrackableObject(const char* category_group, const char* name, 856 TraceScopedTrackableObject(const char* category_group, const char* name,
839 IDType id) 857 IDType id)
840 : category_group_(category_group), 858 : category_group_(category_group),
(...skipping 15 matching lines...) Expand all
856 const char* name_; 874 const char* name_;
857 IDType id_; 875 IDType id_;
858 876
859 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 877 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
860 }; 878 };
861 879
862 } // namespace trace_event 880 } // namespace trace_event
863 } // namespace base 881 } // namespace base
864 882
865 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 883 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698