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

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

Issue 1239593002: Implement a new flow event API that allows binding flow events and regular events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove a redundant macro. Created 5 years, 5 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
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.h » ('j') | ipc/ipc_channel_reader.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This header file defines the set of trace_event macros without specifying 5 // This header file defines the set of trace_event macros without specifying
6 // how the events actually get collected and stored. If you need to expose trace 6 // how the events actually get collected and stored. If you need to expose trace
7 // events to some other universe, you can copy-and-paste this file as well as 7 // events to some other universe, you can copy-and-paste this file as well as
8 // trace_event.h, modifying the macros contained there as necessary for the 8 // trace_event.h, modifying the macros contained there as necessary for the
9 // target platform. The end result is that multiple libraries can funnel events 9 // target platform. The end result is that multiple libraries can funnel events
10 // through to a shared trace event collector. 10 // through to a shared trace event collector.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // scope, with 0, 1 or 2 associated arguments. If the category is not 221 // scope, with 0, 1 or 2 associated arguments. If the category is not
222 // enabled, then this does nothing. 222 // enabled, then this does nothing.
223 // - category and name strings must have application lifetime (statics or 223 // - category and name strings must have application lifetime (statics or
224 // literals). They may not include " chars. 224 // literals). They may not include " chars.
225 #define TRACE_EVENT0(category_group, name) \ 225 #define TRACE_EVENT0(category_group, name) \
226 INTERNAL_TRACE_MEMORY(category_group, name) \ 226 INTERNAL_TRACE_MEMORY(category_group, name) \
227 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name) 227 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
228 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ 228 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
229 INTERNAL_TRACE_MEMORY(category_group, name) \ 229 INTERNAL_TRACE_MEMORY(category_group, name) \
230 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val) 230 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
231 #define TRACE_EVENT1_WITH_FLOW(category_group, name, arg1_name, arg1_val) \
dsinclair 2015/07/14 13:52:10 These should be TRACE_EVENT_WITH_FLOW1 We put the
232 INTERNAL_TRACE_MEMORY(category_group, name) \
233 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, arg1_name, a rg1_val)
231 #define TRACE_EVENT2( \ 234 #define TRACE_EVENT2( \
232 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \ 235 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
233 INTERNAL_TRACE_MEMORY(category_group, name) \ 236 INTERNAL_TRACE_MEMORY(category_group, name) \
234 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ 237 INTERNAL_TRACE_EVENT_ADD_SCOPED( \
235 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) 238 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
239 #define TRACE_EVENT2_WITH_FLOW( \
dsinclair 2015/07/14 13:52:10 Why no TRACE_EVENT_WITH_FLOW0?
240 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
241 INTERNAL_TRACE_MEMORY(category_group, name) \
242 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \
243 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
236 244
237 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing. 245 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing.
238 // Use this where |name| is too generic to accurately aggregate allocations. 246 // Use this where |name| is too generic to accurately aggregate allocations.
239 #define TRACE_EVENT_WITH_MEMORY_TAG2( \ 247 #define TRACE_EVENT_WITH_MEMORY_TAG2( \
240 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \ 248 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \
241 INTERNAL_TRACE_MEMORY(category, memory_tag) \ 249 INTERNAL_TRACE_MEMORY(category, memory_tag) \
242 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ 250 INTERNAL_TRACE_EVENT_ADD_SCOPED( \
243 category, name, arg1_name, arg1_val, arg2_name, arg2_val) 251 category, name, arg1_name, arg1_val, arg2_name, arg2_val)
244 252
245 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not 253 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 arg1_name, arg1_val) \ 853 arg1_name, arg1_val) \
846 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \ 854 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, \
847 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \ 855 category_group, name, id, TRACE_EVENT_FLAG_COPY, "step", step, \
848 arg1_name, arg1_val) 856 arg1_name, arg1_val)
849 857
850 // Records a single FLOW_END event for "name" immediately. If the category 858 // Records a single FLOW_END event for "name" immediately. If the category
851 // is not enabled, then this does nothing. 859 // is not enabled, then this does nothing.
852 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \ 860 #define TRACE_EVENT_FLOW_END0(category_group, name, id) \
853 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 861 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
854 category_group, name, id, TRACE_EVENT_FLAG_NONE) 862 category_group, name, id, TRACE_EVENT_FLAG_NONE)
863 #define APPEND_TRACE_EVENT_FLOW_END0(category_group, name, id) \
864 appendFlowEvent(trace_event_internal::constructFlowEvent(TRACE_EVENT_PHASE_F LOW_END, \
865 category_group, name, id, TRACE_EVENT_FLAG_NONE))
855 #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id) \ 866 #define TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0(category_group, name, id) \
856 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 867 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
857 category_group, name, id, TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) 868 category_group, name, id, TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
858 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \ 869 #define TRACE_EVENT_FLOW_END1(category_group, name, id, arg1_name, arg1_val) \
859 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 870 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
860 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) 871 category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
861 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \ 872 #define TRACE_EVENT_FLOW_END2(category_group, name, id, arg1_name, arg1_val, \
862 arg2_name, arg2_val) \ 873 arg2_name, arg2_val) \
863 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ 874 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \
864 category_group, name, id, TRACE_EVENT_FLAG_NONE, \ 875 category_group, name, id, TRACE_EVENT_FLAG_NONE, \
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 base::trace_event::TraceEventHandle h = \ 1080 base::trace_event::TraceEventHandle h = \
1070 trace_event_internal::AddTraceEvent( \ 1081 trace_event_internal::AddTraceEvent( \
1071 TRACE_EVENT_PHASE_COMPLETE, \ 1082 TRACE_EVENT_PHASE_COMPLETE, \
1072 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 1083 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1073 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \ 1084 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
1074 ##__VA_ARGS__); \ 1085 ##__VA_ARGS__); \
1075 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ 1086 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
1076 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ 1087 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
1077 } 1088 }
1078 1089
1090 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, ...) \
1091 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1092 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
1093 base::trace_event::TraceEventHandle h = {0, 0, 0}; \
1094 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1095 h = trace_event_internal::AddTraceEvent( \
1096 TRACE_EVENT_PHASE_COMPLETE, \
1097 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1098 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
1099 ##__VA_ARGS__); \
1100 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
1101 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
1102 } \
1103 base::trace_event::TraceEventHandleWrapper INTERNAL_TRACE_EVENT_UID(wrapper) (h); \
1104 INTERNAL_TRACE_EVENT_UID(wrapper)
1105
1079 // Implementation detail: internal macro to create static category and add 1106 // Implementation detail: internal macro to create static category and add
1080 // event if the category is enabled. 1107 // event if the category is enabled.
1081 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 1108 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
1082 flags, ...) \ 1109 flags, ...) \
1083 do { \ 1110 do { \
1084 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1111 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1085 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1112 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1086 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 1113 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
1087 trace_event_internal::TraceID trace_event_trace_id( \ 1114 trace_event_internal::TraceID trace_event_trace_id( \
1088 id, &trace_event_flags); \ 1115 id, &trace_event_flags); \
1089 trace_event_internal::AddTraceEvent( \ 1116 trace_event_internal::AddTraceEvent( \
1090 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 1117 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
1091 name, trace_event_trace_id.data(), trace_event_flags, \ 1118 name, trace_event_trace_id.data(), trace_event_flags, \
1092 ##__VA_ARGS__); \ 1119 ##__VA_ARGS__); \
1093 } \ 1120 } \
1094 } while (0) 1121 } while (0)
1095 1122
1123 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_RETURN(phase, category_group, name, id, \
1124 flags, ...) \
1125 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1126 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1127 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
1128 trace_event_internal::TraceID trace_event_trace_id( \
1129 id, &trace_event_flags); \
1130 return trace_event_internal::AddTraceEvent( \
1131 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
1132 name, trace_event_trace_id.data(), trace_event_flags, \
1133 ##__VA_ARGS__); \
1134 } \
1135 base::trace_event::TraceEventHandle h = {0, 0, 0}; \
1136 return h;
1137
1096 // Implementation detail: internal macro to create static category and add 1138 // Implementation detail: internal macro to create static category and add
1097 // event if the category is enabled. 1139 // event if the category is enabled.
1098 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ 1140 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \
1099 category_group, name, id, thread_id, timestamp, flags, ...) \ 1141 category_group, name, id, thread_id, timestamp, flags, ...) \
1100 do { \ 1142 do { \
1101 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1143 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1102 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1144 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1103 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 1145 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
1104 trace_event_internal::TraceID trace_event_trace_id( \ 1146 trace_event_internal::TraceID trace_event_trace_id( \
1105 id, &trace_event_flags); \ 1147 id, &trace_event_flags); \
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 // Enum reflecting the scope of an INSTANT event. Must fit within 1209 // Enum reflecting the scope of an INSTANT event. Must fit within
1168 // TRACE_EVENT_FLAG_SCOPE_MASK. 1210 // TRACE_EVENT_FLAG_SCOPE_MASK.
1169 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) 1211 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3))
1170 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) 1212 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
1171 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) 1213 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3))
1172 1214
1173 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') 1215 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
1174 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') 1216 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
1175 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') 1217 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
1176 1218
1219 // Type values for identifying flow event direction.
1220 #define FLOW_IN (static_cast<unsigned char>(0))
1221 #define FLOW_OUT (static_cast<unsigned char>(1))
dsinclair 2015/07/14 13:52:10 These should be TRACE_EVENT_FLAG_FLOW_IN/OUT. fmea
fmeawad 2015/07/14 17:32:57 The CL has landed.
1222
1177 namespace trace_event_internal { 1223 namespace trace_event_internal {
1178 1224
1179 // Specify these values when the corresponding argument of AddTraceEvent is not 1225 // Specify these values when the corresponding argument of AddTraceEvent is not
1180 // used. 1226 // used.
1181 const int kZeroNumArgs = 0; 1227 const int kZeroNumArgs = 0;
1182 const unsigned long long kNoEventId = 0; 1228 const unsigned long long kNoEventId = 0;
1183 1229
1184 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers 1230 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers
1185 // are by default mangled with the Process ID so that they are unlikely to 1231 // are by default mangled with the Process ID so that they are unlikely to
1186 // collide when the same pointer is used on different processes. 1232 // collide when the same pointer is used on different processes.
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 const char* arg2_name, 1639 const char* arg2_name,
1594 const ARG2_TYPE& arg2_val) { 1640 const ARG2_TYPE& arg2_val) {
1595 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1641 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1596 base::TraceTicks now = base::TraceTicks::Now(); 1642 base::TraceTicks now = base::TraceTicks::Now();
1597 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1643 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
1598 name, id, thread_id, now, flags, 1644 name, id, thread_id, now, flags,
1599 arg1_name, arg1_val, 1645 arg1_name, arg1_val,
1600 arg2_name, arg2_val); 1646 arg2_name, arg2_val);
1601 } 1647 }
1602 1648
1649 static inline base::trace_event::TraceEventHandle constructFlowEvent(
1650 char phase,
1651 const char *category_group,
1652 const char *name,
1653 unsigned long long id,
1654 unsigned char flags) {
1655 INTERNAL_TRACE_EVENT_ADD_WITH_ID_RETURN(phase, category_group, name, id, flags );
1656 }
1657
1603 // Used by TRACE_EVENTx macros. Do not use directly. 1658 // Used by TRACE_EVENTx macros. Do not use directly.
1604 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { 1659 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
1605 public: 1660 public:
1606 // Note: members of data_ intentionally left uninitialized. See Initialize. 1661 // Note: members of data_ intentionally left uninitialized. See Initialize.
1607 ScopedTracer() : p_data_(NULL) {} 1662 ScopedTracer() : p_data_(NULL) {}
1608 1663
1609 ~ScopedTracer() { 1664 ~ScopedTracer() {
1610 if (p_data_ && *data_.category_group_enabled) 1665 if (p_data_ && *data_.category_group_enabled)
1611 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( 1666 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
1612 data_.category_group_enabled, data_.name, data_.event_handle); 1667 data_.category_group_enabled, data_.name, data_.event_handle);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 const char* name_; 1771 const char* name_;
1717 IDType id_; 1772 IDType id_;
1718 1773
1719 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1774 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1720 }; 1775 };
1721 1776
1722 } // namespace trace_event 1777 } // namespace trace_event
1723 } // namespace base 1778 } // namespace base
1724 1779
1725 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 1780 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.h » ('j') | ipc/ipc_channel_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698