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

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: Implement binding flow events to slices for PostTasks. 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
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 trace_event_internal::TraceID::DontMangle(id) 218 trace_event_internal::TraceID::DontMangle(id)
219 219
220 // Records a pair of begin and end events called "name" for the current 220 // Records a pair of begin and end events called "name" for the current
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_EVENT_WITH_FLOW0(category_group, name, bind_id, flow_direction) \
229 INTERNAL_TRACE_MEMORY(category_group, name) \
230 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
231 flow_direction)
228 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \ 232 #define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
229 INTERNAL_TRACE_MEMORY(category_group, name) \ 233 INTERNAL_TRACE_MEMORY(category_group, name) \
230 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val) 234 INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
235 #define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_direction, \
236 arg1_name, arg1_val) \
237 INTERNAL_TRACE_MEMORY(category_group, name) \
238 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \
239 category_group, name, bind_id, flow_direction, arg1_name, arg1_val)
231 #define TRACE_EVENT2( \ 240 #define TRACE_EVENT2( \
232 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \ 241 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
233 INTERNAL_TRACE_MEMORY(category_group, name) \ 242 INTERNAL_TRACE_MEMORY(category_group, name) \
234 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ 243 INTERNAL_TRACE_EVENT_ADD_SCOPED( \
235 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) 244 category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
245 #define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_direction, \
246 arg1_name, arg1_val, arg2_name, arg2_val) \
247 INTERNAL_TRACE_MEMORY(category_group, name) \
248 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
249 flow_direction, arg1_name, \
250 arg1_val, arg2_name, arg2_val)
236 251
237 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing. 252 // Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing.
238 // Use this where |name| is too generic to accurately aggregate allocations. 253 // Use this where |name| is too generic to accurately aggregate allocations.
239 #define TRACE_EVENT_WITH_MEMORY_TAG2( \ 254 #define TRACE_EVENT_WITH_MEMORY_TAG2( \
240 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \ 255 category, name, memory_tag, arg1_name, arg1_val, arg2_name, arg2_val) \
241 INTERNAL_TRACE_MEMORY(category, memory_tag) \ 256 INTERNAL_TRACE_MEMORY(category, memory_tag) \
242 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ 257 INTERNAL_TRACE_EVENT_ADD_SCOPED( \
243 category, name, arg1_name, arg1_val, arg2_name, arg2_val) 258 category, name, arg1_name, arg1_val, arg2_name, arg2_val)
244 259
260 #define TRACE_EVENT_WITH_MEMORY_TAG_WITH_FLOW2(category, name, memory_tag, \
261 bind_id, flow_direction, \
262 arg1_name, arg1_val, arg2_name, \
263 arg2_val) \
264 INTERNAL_TRACE_MEMORY(category, memory_tag) \
265 INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category, name, bind_id, \
266 flow_direction, arg1_name, \
267 arg1_val, arg2_name, arg2_val)
268
245 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not 269 // UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
246 // included in official builds. 270 // included in official builds.
247 271
248 #if OFFICIAL_BUILD 272 #if OFFICIAL_BUILD
249 #undef TRACING_IS_OFFICIAL_BUILD 273 #undef TRACING_IS_OFFICIAL_BUILD
250 #define TRACING_IS_OFFICIAL_BUILD 1 274 #define TRACING_IS_OFFICIAL_BUILD 1
251 #elif !defined(TRACING_IS_OFFICIAL_BUILD) 275 #elif !defined(TRACING_IS_OFFICIAL_BUILD)
252 #define TRACING_IS_OFFICIAL_BUILD 0 276 #define TRACING_IS_OFFICIAL_BUILD 0
253 #endif 277 #endif
254 278
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1066
1043 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ 1067 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
1044 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 1068 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
1045 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ 1069 const unsigned char* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
1046 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \ 1070 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(category_group, \
1047 INTERNAL_TRACE_EVENT_UID(atomic), \ 1071 INTERNAL_TRACE_EVENT_UID(atomic), \
1048 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); 1072 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
1049 1073
1050 // Implementation detail: internal macro to create static category and add 1074 // Implementation detail: internal macro to create static category and add
1051 // event if the category is enabled. 1075 // event if the category is enabled.
1052 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ 1076 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
dsinclair 2015/07/17 13:39:40 Can you undo the formatting that puts the \'s line
1053 do { \ 1077 do { \
1054 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1078 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1055 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1079 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1056 trace_event_internal::AddTraceEvent( \ 1080 trace_event_internal::AddTraceEvent( \
1057 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 1081 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1058 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ 1082 trace_event_internal::kNoEventId, flags, \
1059 } \ 1083 trace_event_internal::kNoBindId, ##__VA_ARGS__); \
1060 } while (0) 1084 } \
1085 } while (0)
1061 1086
1062 // Implementation detail: internal macro to create static category and add begin 1087 // Implementation detail: internal macro to create static category and add begin
1063 // event if the category is enabled. Also adds the end event when the scope 1088 // event if the category is enabled. Also adds the end event when the scope
1064 // ends. 1089 // ends.
1065 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ 1090 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
1066 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1091 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1067 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 1092 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
1068 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1093 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1069 base::trace_event::TraceEventHandle h = \ 1094 base::trace_event::TraceEventHandle h = \
1070 trace_event_internal::AddTraceEvent( \ 1095 trace_event_internal::AddTraceEvent( \
1071 TRACE_EVENT_PHASE_COMPLETE, \ 1096 TRACE_EVENT_PHASE_COMPLETE, \
1072 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 1097 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1073 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \ 1098 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
1074 ##__VA_ARGS__); \ 1099 trace_event_internal::kNoBindId, ##__VA_ARGS__); \
1075 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ 1100 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
1076 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ 1101 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
1077 } 1102 }
1103
1104 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \
1105 category_group, name, bind_id, flow_direction, ...) \
1106 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1107 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
1108 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1109 unsigned int trace_event_flags = flow_direction; \
1110 trace_event_internal::TraceID trace_event_bind_id(bind_id, \
1111 &trace_event_flags); \
1112 base::trace_event::TraceEventHandle h = \
1113 trace_event_internal::AddTraceEvent( \
1114 TRACE_EVENT_PHASE_COMPLETE, \
1115 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1116 trace_event_internal::kNoEventId, flow_direction, \
1117 trace_event_bind_id.data(), ##__VA_ARGS__); \
1118 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
1119 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
1120 }
1078 1121
1079 // Implementation detail: internal macro to create static category and add 1122 // Implementation detail: internal macro to create static category and add
1080 // event if the category is enabled. 1123 // event if the category is enabled.
1081 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 1124 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
1082 flags, ...) \ 1125 flags, ...) \
1083 do { \ 1126 do { \
1084 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1127 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1085 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1128 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1086 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 1129 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
1087 trace_event_internal::TraceID trace_event_trace_id( \ 1130 trace_event_internal::TraceID trace_event_trace_id(id, \
1088 id, &trace_event_flags); \ 1131 &trace_event_flags); \
1089 trace_event_internal::AddTraceEvent( \ 1132 trace_event_internal::AddTraceEvent( \
1090 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 1133 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1091 name, trace_event_trace_id.data(), trace_event_flags, \ 1134 trace_event_trace_id.data(), trace_event_flags, \
1092 ##__VA_ARGS__); \ 1135 trace_event_internal::kNoBindId, ##__VA_ARGS__); \
1093 } \ 1136 } \
1094 } while (0) 1137 } while (0)
1095 1138
1096 // Implementation detail: internal macro to create static category and add 1139 // Implementation detail: internal macro to create static category and add
1097 // event if the category is enabled. 1140 // event if the category is enabled.
1098 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \ 1141 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
1099 category_group, name, id, thread_id, timestamp, flags, ...) \ 1142 phase, category_group, name, id, thread_id, timestamp, flags, ...) \
1100 do { \ 1143 do { \
1101 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 1144 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
1102 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 1145 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
1103 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 1146 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
1104 trace_event_internal::TraceID trace_event_trace_id( \ 1147 trace_event_internal::TraceID trace_event_trace_id(id, \
1105 id, &trace_event_flags); \ 1148 &trace_event_flags); \
1106 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ 1149 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \
1107 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 1150 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
1108 name, trace_event_trace_id.data(), \ 1151 trace_event_trace_id.data(), thread_id, \
1109 thread_id, base::TraceTicks::FromInternalValue(timestamp), \ 1152 base::TraceTicks::FromInternalValue(timestamp), \
1110 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ 1153 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
1111 ##__VA_ARGS__); \ 1154 trace_event_internal::kNoBindId, ##__VA_ARGS__); \
1112 } \ 1155 } \
1113 } while (0) 1156 } while (0)
1114 1157
1115 // Notes regarding the following definitions: 1158 // Notes regarding the following definitions:
1116 // New values can be added and propagated to third party libraries, but existing 1159 // New values can be added and propagated to third party libraries, but existing
1117 // definitions must never be changed, because third party libraries may use old 1160 // definitions must never be changed, because third party libraries may use old
1118 // definitions. 1161 // definitions.
1119 1162
1120 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. 1163 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
1121 #define TRACE_EVENT_PHASE_BEGIN ('B') 1164 #define TRACE_EVENT_PHASE_BEGIN ('B')
1122 #define TRACE_EVENT_PHASE_END ('E') 1165 #define TRACE_EVENT_PHASE_END ('E')
1123 #define TRACE_EVENT_PHASE_COMPLETE ('X') 1166 #define TRACE_EVENT_PHASE_COMPLETE ('X')
(...skipping 19 matching lines...) Expand all
1143 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. 1186 // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
1144 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0)) 1187 #define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
1145 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0)) 1188 #define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
1146 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1)) 1189 #define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
1147 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2)) 1190 #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2))
1148 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3)) 1191 #define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3))
1149 #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4)) 1192 #define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4))
1150 #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5)) 1193 #define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
1151 #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6)) 1194 #define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
1152 #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7)) 1195 #define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
1196 #define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
1197 #define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
dsinclair 2015/07/17 13:39:40 nit: Can you line the ('s up on these ones with AS
1153 1198
1154 #define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast<unsigned int>( \ 1199 #define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast<unsigned int>( \
1155 TRACE_EVENT_FLAG_SCOPE_OFFSET | TRACE_EVENT_FLAG_SCOPE_EXTRA)) 1200 TRACE_EVENT_FLAG_SCOPE_OFFSET | TRACE_EVENT_FLAG_SCOPE_EXTRA))
1156 1201
1157 // Type values for identifying types in the TraceValue union. 1202 // Type values for identifying types in the TraceValue union.
1158 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) 1203 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
1159 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) 1204 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
1160 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) 1205 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
1161 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) 1206 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
1162 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) 1207 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
(...skipping 10 matching lines...) Expand all
1173 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') 1218 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
1174 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') 1219 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
1175 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') 1220 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
1176 1221
1177 namespace trace_event_internal { 1222 namespace trace_event_internal {
1178 1223
1179 // Specify these values when the corresponding argument of AddTraceEvent is not 1224 // Specify these values when the corresponding argument of AddTraceEvent is not
1180 // used. 1225 // used.
1181 const int kZeroNumArgs = 0; 1226 const int kZeroNumArgs = 0;
1182 const unsigned long long kNoEventId = 0; 1227 const unsigned long long kNoEventId = 0;
1228 const unsigned long long kNoBindId = 0;
dsinclair 2015/07/17 13:39:40 Let's just rename kNoEventId to kNoId = 0 and use
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.
1187 class TraceID { 1233 class TraceID {
1188 public: 1234 public:
1189 class DontMangle { 1235 class DontMangle {
1190 public: 1236 public:
1191 explicit DontMangle(const void* id) 1237 explicit DontMangle(const void* id)
1192 : data_(static_cast<unsigned long long>( 1238 : data_(static_cast<unsigned long long>(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 1432
1387 static inline base::trace_event::TraceEventHandle 1433 static inline base::trace_event::TraceEventHandle
1388 AddTraceEventWithThreadIdAndTimestamp( 1434 AddTraceEventWithThreadIdAndTimestamp(
1389 char phase, 1435 char phase,
1390 const unsigned char* category_group_enabled, 1436 const unsigned char* category_group_enabled,
1391 const char* name, 1437 const char* name,
1392 unsigned long long id, 1438 unsigned long long id,
1393 int thread_id, 1439 int thread_id,
1394 const base::TraceTicks& timestamp, 1440 const base::TraceTicks& timestamp,
1395 unsigned int flags, 1441 unsigned int flags,
1442 unsigned long long bind_id,
1396 const char* arg1_name, 1443 const char* arg1_name,
1397 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& 1444 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1398 arg1_val) { 1445 arg1_val) {
1399 const int num_args = 1; 1446 const int num_args = 1;
1400 unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE }; 1447 unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE };
1401 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1448 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1402 phase, category_group_enabled, name, id, thread_id, timestamp, 1449 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1403 num_args, &arg1_name, arg_types, NULL, &arg1_val, flags); 1450 &arg1_name, arg_types, NULL, &arg1_val, flags, bind_id);
1404 } 1451 }
1405 1452
1406 template<class ARG1_TYPE> 1453 template <class ARG1_TYPE>
1407 static inline base::trace_event::TraceEventHandle 1454 static inline base::trace_event::TraceEventHandle
1408 AddTraceEventWithThreadIdAndTimestamp( 1455 AddTraceEventWithThreadIdAndTimestamp(
1409 char phase, 1456 char phase,
1410 const unsigned char* category_group_enabled, 1457 const unsigned char* category_group_enabled,
1411 const char* name, 1458 const char* name,
1412 unsigned long long id, 1459 unsigned long long id,
1413 int thread_id, 1460 int thread_id,
1414 const base::TraceTicks& timestamp, 1461 const base::TraceTicks& timestamp,
1415 unsigned int flags, 1462 unsigned int flags,
1463 unsigned long long bind_id,
1416 const char* arg1_name, 1464 const char* arg1_name,
1417 const ARG1_TYPE& arg1_val, 1465 const ARG1_TYPE& arg1_val,
1418 const char* arg2_name, 1466 const char* arg2_name,
1419 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& 1467 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1420 arg2_val) { 1468 arg2_val) {
1421 const int num_args = 2; 1469 const int num_args = 2;
1422 const char* arg_names[2] = { arg1_name, arg2_name }; 1470 const char* arg_names[2] = { arg1_name, arg2_name };
1423 1471
1424 unsigned char arg_types[2]; 1472 unsigned char arg_types[2];
1425 unsigned long long arg_values[2]; 1473 unsigned long long arg_values[2];
1426 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1474 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1427 arg_types[1] = TRACE_VALUE_TYPE_CONVERTABLE; 1475 arg_types[1] = TRACE_VALUE_TYPE_CONVERTABLE;
1428 1476
1429 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 1477 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1430 convertable_values[2]; 1478 convertable_values[2];
1431 convertable_values[1] = arg2_val; 1479 convertable_values[1] = arg2_val;
1432 1480
1433 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1481 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1434 phase, category_group_enabled, name, id, thread_id, timestamp, 1482 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1435 num_args, arg_names, arg_types, arg_values, convertable_values, flags); 1483 arg_names, arg_types, arg_values, convertable_values, flags, bind_id);
1436 } 1484 }
1437 1485
1438 template<class ARG2_TYPE> 1486 template <class ARG2_TYPE>
dsinclair 2015/07/17 13:39:40 nit: remove space.
1439 static inline base::trace_event::TraceEventHandle 1487 static inline base::trace_event::TraceEventHandle
1440 AddTraceEventWithThreadIdAndTimestamp( 1488 AddTraceEventWithThreadIdAndTimestamp(
1441 char phase, 1489 char phase,
1442 const unsigned char* category_group_enabled, 1490 const unsigned char* category_group_enabled,
1443 const char* name, 1491 const char* name,
1444 unsigned long long id, 1492 unsigned long long id,
1445 int thread_id, 1493 int thread_id,
1446 const base::TraceTicks& timestamp, 1494 const base::TraceTicks& timestamp,
1447 unsigned int flags, 1495 unsigned int flags,
1496 unsigned long long bind_id,
1448 const char* arg1_name, 1497 const char* arg1_name,
1449 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val, 1498 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
1450 const char* arg2_name, 1499 const char* arg2_name,
1451 const ARG2_TYPE& arg2_val) { 1500 const ARG2_TYPE& arg2_val) {
1452 const int num_args = 2; 1501 const int num_args = 2;
1453 const char* arg_names[2] = { arg1_name, arg2_name }; 1502 const char* arg_names[2] = { arg1_name, arg2_name };
1454 1503
1455 unsigned char arg_types[2]; 1504 unsigned char arg_types[2];
1456 unsigned long long arg_values[2]; 1505 unsigned long long arg_values[2];
1457 arg_types[0] = TRACE_VALUE_TYPE_CONVERTABLE; 1506 arg_types[0] = TRACE_VALUE_TYPE_CONVERTABLE;
1458 arg_values[0] = 0; 1507 arg_values[0] = 0;
1459 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 1508 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
1460 1509
1461 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 1510 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1462 convertable_values[2]; 1511 convertable_values[2];
1463 convertable_values[0] = arg1_val; 1512 convertable_values[0] = arg1_val;
1464 1513
1465 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1514 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1466 phase, category_group_enabled, name, id, thread_id, timestamp, 1515 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1467 num_args, arg_names, arg_types, arg_values, convertable_values, flags); 1516 arg_names, arg_types, arg_values, convertable_values, flags, bind_id);
1468 } 1517 }
1469 1518
1470 static inline base::trace_event::TraceEventHandle 1519 static inline base::trace_event::TraceEventHandle
1471 AddTraceEventWithThreadIdAndTimestamp( 1520 AddTraceEventWithThreadIdAndTimestamp(
1472 char phase, 1521 char phase,
1473 const unsigned char* category_group_enabled, 1522 const unsigned char* category_group_enabled,
1474 const char* name, 1523 const char* name,
1475 unsigned long long id, 1524 unsigned long long id,
1476 int thread_id, 1525 int thread_id,
1477 const base::TraceTicks& timestamp, 1526 const base::TraceTicks& timestamp,
1478 unsigned int flags, 1527 unsigned int flags,
1528 unsigned long long bind_id,
1479 const char* arg1_name, 1529 const char* arg1_name,
1480 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val, 1530 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
1481 const char* arg2_name, 1531 const char* arg2_name,
1482 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& 1532 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1483 arg2_val) { 1533 arg2_val) {
1484 const int num_args = 2; 1534 const int num_args = 2;
1485 const char* arg_names[2] = { arg1_name, arg2_name }; 1535 const char* arg_names[2] = { arg1_name, arg2_name };
1486 unsigned char arg_types[2] = 1536 unsigned char arg_types[2] =
1487 { TRACE_VALUE_TYPE_CONVERTABLE, TRACE_VALUE_TYPE_CONVERTABLE }; 1537 { TRACE_VALUE_TYPE_CONVERTABLE, TRACE_VALUE_TYPE_CONVERTABLE };
1488 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 1538 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1489 convertable_values[2] = {arg1_val, arg2_val}; 1539 convertable_values[2] = {arg1_val, arg2_val};
1490 1540
1491 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1541 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1492 phase, category_group_enabled, name, id, thread_id, timestamp, 1542 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1493 num_args, arg_names, arg_types, NULL, convertable_values, flags); 1543 arg_names, arg_types, NULL, convertable_values, flags, bind_id);
1494 } 1544 }
1495 1545
1496 static inline base::trace_event::TraceEventHandle 1546 static inline base::trace_event::TraceEventHandle
1497 AddTraceEventWithThreadIdAndTimestamp( 1547 AddTraceEventWithThreadIdAndTimestamp(
1498 char phase, 1548 char phase,
1499 const unsigned char* category_group_enabled, 1549 const unsigned char* category_group_enabled,
1500 const char* name, 1550 const char* name,
1501 unsigned long long id, 1551 unsigned long long id,
1502 int thread_id, 1552 int thread_id,
1503 const base::TraceTicks& timestamp, 1553 const base::TraceTicks& timestamp,
1504 unsigned int flags) { 1554 unsigned int flags,
1555 unsigned long long bind_id) {
dsinclair 2015/07/17 13:39:40 Let's move bind_id up below int thread_id so we ke
1505 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1556 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1506 phase, category_group_enabled, name, id, thread_id, timestamp, 1557 phase, category_group_enabled, name, id, thread_id, timestamp,
1507 kZeroNumArgs, NULL, NULL, NULL, NULL, flags); 1558 kZeroNumArgs, NULL, NULL, NULL, NULL, flags, bind_id);
1508 } 1559 }
1509 1560
1510 static inline base::trace_event::TraceEventHandle AddTraceEvent( 1561 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1511 char phase, 1562 char phase,
1512 const unsigned char* category_group_enabled, 1563 const unsigned char* category_group_enabled,
1513 const char* name, 1564 const char* name,
1514 unsigned long long id, 1565 unsigned long long id,
1515 unsigned int flags) { 1566 unsigned int flags,
1567 unsigned long long bind_id) {
1516 const int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1568 const int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1517 const base::TraceTicks now = base::TraceTicks::Now(); 1569 const base::TraceTicks now = base::TraceTicks::Now();
1518 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1570 return AddTraceEventWithThreadIdAndTimestamp(
1519 name, id, thread_id, now, flags); 1571 phase, category_group_enabled, name, id, thread_id, now, flags, bind_id);
1520 } 1572 }
1521 1573
1522 template<class ARG1_TYPE> 1574 template <class ARG1_TYPE>
1523 static inline base::trace_event::TraceEventHandle 1575 static inline base::trace_event::TraceEventHandle
1524 AddTraceEventWithThreadIdAndTimestamp( 1576 AddTraceEventWithThreadIdAndTimestamp(
1525 char phase, 1577 char phase,
1526 const unsigned char* category_group_enabled, 1578 const unsigned char* category_group_enabled,
1527 const char* name, 1579 const char* name,
1528 unsigned long long id, 1580 unsigned long long id,
1529 int thread_id, 1581 int thread_id,
1530 const base::TraceTicks& timestamp, 1582 const base::TraceTicks& timestamp,
1531 unsigned int flags, 1583 unsigned int flags,
1584 unsigned long long bind_id,
1532 const char* arg1_name, 1585 const char* arg1_name,
1533 const ARG1_TYPE& arg1_val) { 1586 const ARG1_TYPE& arg1_val) {
1534 const int num_args = 1; 1587 const int num_args = 1;
1535 unsigned char arg_types[1]; 1588 unsigned char arg_types[1];
1536 unsigned long long arg_values[1]; 1589 unsigned long long arg_values[1];
1537 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1590 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1538 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1591 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1539 phase, category_group_enabled, name, id, thread_id, timestamp, 1592 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1540 num_args, &arg1_name, arg_types, arg_values, NULL, flags); 1593 &arg1_name, arg_types, arg_values, NULL, flags, bind_id);
1541 } 1594 }
1542 1595
1543 template<class ARG1_TYPE> 1596 template <class ARG1_TYPE>
1544 static inline base::trace_event::TraceEventHandle AddTraceEvent( 1597 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1545 char phase, 1598 char phase,
1546 const unsigned char* category_group_enabled, 1599 const unsigned char* category_group_enabled,
1547 const char* name, 1600 const char* name,
1548 unsigned long long id, 1601 unsigned long long id,
1549 unsigned int flags, 1602 unsigned int flags,
1603 unsigned long long bind_id,
1550 const char* arg1_name, 1604 const char* arg1_name,
1551 const ARG1_TYPE& arg1_val) { 1605 const ARG1_TYPE& arg1_val) {
1552 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1606 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1553 base::TraceTicks now = base::TraceTicks::Now(); 1607 base::TraceTicks now = base::TraceTicks::Now();
1554 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1608 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
1555 name, id, thread_id, now, flags, 1609 name, id, thread_id, now, flags,
1556 arg1_name, arg1_val); 1610 bind_id, arg1_name, arg1_val);
1557 } 1611 }
1558 1612
1559 template<class ARG1_TYPE, class ARG2_TYPE> 1613 template <class ARG1_TYPE, class ARG2_TYPE>
1560 static inline base::trace_event::TraceEventHandle 1614 static inline base::trace_event::TraceEventHandle
1561 AddTraceEventWithThreadIdAndTimestamp( 1615 AddTraceEventWithThreadIdAndTimestamp(
1562 char phase, 1616 char phase,
1563 const unsigned char* category_group_enabled, 1617 const unsigned char* category_group_enabled,
1564 const char* name, 1618 const char* name,
1565 unsigned long long id, 1619 unsigned long long id,
1566 int thread_id, 1620 int thread_id,
1567 const base::TraceTicks& timestamp, 1621 const base::TraceTicks& timestamp,
1568 unsigned int flags, 1622 unsigned int flags,
1623 unsigned long long bind_id,
1569 const char* arg1_name, 1624 const char* arg1_name,
1570 const ARG1_TYPE& arg1_val, 1625 const ARG1_TYPE& arg1_val,
1571 const char* arg2_name, 1626 const char* arg2_name,
1572 const ARG2_TYPE& arg2_val) { 1627 const ARG2_TYPE& arg2_val) {
1573 const int num_args = 2; 1628 const int num_args = 2;
1574 const char* arg_names[2] = { arg1_name, arg2_name }; 1629 const char* arg_names[2] = { arg1_name, arg2_name };
1575 unsigned char arg_types[2]; 1630 unsigned char arg_types[2];
1576 unsigned long long arg_values[2]; 1631 unsigned long long arg_values[2];
1577 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1632 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1578 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 1633 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
1579 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1634 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1580 phase, category_group_enabled, name, id, thread_id, timestamp, 1635 phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
1581 num_args, arg_names, arg_types, arg_values, NULL, flags); 1636 arg_names, arg_types, arg_values, NULL, flags, bind_id);
1582 } 1637 }
1583 1638
1584 template<class ARG1_TYPE, class ARG2_TYPE> 1639 template <class ARG1_TYPE, class ARG2_TYPE>
1585 static inline base::trace_event::TraceEventHandle AddTraceEvent( 1640 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1586 char phase, 1641 char phase,
1587 const unsigned char* category_group_enabled, 1642 const unsigned char* category_group_enabled,
1588 const char* name, 1643 const char* name,
1589 unsigned long long id, 1644 unsigned long long id,
1590 unsigned int flags, 1645 unsigned int flags,
1646 unsigned long long bind_id,
1591 const char* arg1_name, 1647 const char* arg1_name,
1592 const ARG1_TYPE& arg1_val, 1648 const ARG1_TYPE& arg1_val,
1593 const char* arg2_name, 1649 const char* arg2_name,
1594 const ARG2_TYPE& arg2_val) { 1650 const ARG2_TYPE& arg2_val) {
1595 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1651 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1596 base::TraceTicks now = base::TraceTicks::Now(); 1652 base::TraceTicks now = base::TraceTicks::Now();
1597 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1653 return AddTraceEventWithThreadIdAndTimestamp(
1598 name, id, thread_id, now, flags, 1654 phase, category_group_enabled, name, id, thread_id, now, flags, bind_id,
1599 arg1_name, arg1_val, 1655 arg1_name, arg1_val, arg2_name, arg2_val);
1600 arg2_name, arg2_val);
1601 } 1656 }
1602 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)
(...skipping 105 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

Powered by Google App Engine
This is Rietveld 408576698