5 #ifndef SRC_TRACING_TRACE_EVENT_H_ 6 #define SRC_TRACING_TRACE_EVENT_H_ 11 #include "v8-platform.h" 35 #define TRACE_STR_COPY(str) node::tracing::TraceStringWithCopy(str) 39 #define TRACE_ID_MANGLE(id) node::tracing::TraceID::ForceMangle(id) 43 #define TRACE_ID_DONT_MANGLE(id) node::tracing::TraceID::DontMangle(id) 47 #define TRACE_ID_WITH_SCOPE(scope, id) \ 48 trace_event_internal::TraceID::WithScope(scope, id) 50 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ 51 *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ 52 (kEnabledForRecording_CategoryGroupEnabledFlags | \ 53 kEnabledForEventCallback_CategoryGroupEnabledFlags) 58 #define INTERNAL_TRACE_MEMORY(category, name) 73 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ 74 node::tracing::TraceEventHelper::GetTracingController() \ 75 ->GetCategoryGroupEnabled 80 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED UNIMPLEMENTED() 95 #define TRACE_EVENT_API_ADD_TRACE_EVENT node::tracing::AddTraceEventImpl 102 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ 103 node::tracing::TraceEventHelper::GetTracingController() \ 104 ->UpdateTraceEventDuration 107 #define TRACE_EVENT_API_ATOMIC_WORD intptr_t 108 #define TRACE_EVENT_API_ATOMIC_LOAD(var) (var) 109 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) (var) = (value) 116 #define INTERNAL_TRACE_EVENT_UID3(a, b) trace_event_unique_##a##b 117 #define INTERNAL_TRACE_EVENT_UID2(a, b) INTERNAL_TRACE_EVENT_UID3(a, b) 118 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ 119 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) 128 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \ 129 category_group, atomic, category_group_enabled) \ 130 category_group_enabled = \ 131 reinterpret_cast<const uint8_t*>(TRACE_EVENT_API_ATOMIC_LOAD(atomic)); \ 132 if (!category_group_enabled) { \ 133 category_group_enabled = \ 134 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \ 135 TRACE_EVENT_API_ATOMIC_STORE( \ 136 atomic, reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \ 137 category_group_enabled)); \ 140 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \ 141 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 142 const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \ 143 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \ 144 category_group, INTERNAL_TRACE_EVENT_UID(atomic), \ 145 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); 149 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ 151 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 152 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 153 node::tracing::AddTraceEvent( \ 154 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 155 node::tracing::kGlobalScope, node::tracing::kNoId, \ 156 node::tracing::kNoId, flags, ##__VA_ARGS__); \ 163 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ 164 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 165 node::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 166 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 167 uint64_t h = node::tracing::AddTraceEvent( \ 168 TRACE_EVENT_PHASE_COMPLETE, \ 169 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 170 node::tracing::kGlobalScope, node::tracing::kNoId, \ 171 node::tracing::kNoId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 172 INTERNAL_TRACE_EVENT_UID(tracer) \ 173 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 177 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \ 178 bind_id, flow_flags, ...) \ 179 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 180 node::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 181 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 182 unsigned int trace_event_flags = flow_flags; \ 183 node::tracing::TraceID trace_event_bind_id(bind_id, \ 184 &trace_event_flags); \ 185 uint64_t h = node::tracing::AddTraceEvent( \ 186 TRACE_EVENT_PHASE_COMPLETE, \ 187 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 188 node::tracing::kGlobalScope, node::tracing::kNoId, \ 189 trace_event_bind_id.raw_id(), trace_event_flags, ##__VA_ARGS__); \ 190 INTERNAL_TRACE_EVENT_UID(tracer) \ 191 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 197 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 200 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 201 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 202 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 203 node::tracing::TraceID trace_event_trace_id(id, \ 204 &trace_event_flags); \ 205 node::tracing::AddTraceEvent( \ 206 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 207 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ 208 node::tracing::kNoId, trace_event_flags, ##__VA_ARGS__); \ 213 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ 214 timestamp, flags, ...) \ 218 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \ 219 phase, category_group, name, id, timestamp, flags, ...) \ 224 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 225 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ 229 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ 230 struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \ 232 INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \ 233 TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \ 235 ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \ 236 TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \ 241 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ 242 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \ 243 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \ 246 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ 247 INTERNAL_TRACE_EVENT_UID(scoped_context)(context); 262 static v8::TracingController* GetTracingController();
263 static void SetTracingController(v8::TracingController* controller);
274 : scope_(scope), raw_id_(raw_id) {}
275 uint64_t
raw_id()
const {
return raw_id_; }
276 const char*
scope()
const {
return scope_; }
279 const char* scope_ =
nullptr;
286 : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {}
292 : raw_id_(static_cast<uint64_t>(raw_id)) {}
295 : raw_id_(static_cast<uint64_t>(raw_id)) {}
297 : raw_id_(static_cast<uint64_t>(raw_id)) {}
299 : scope_(scoped_id.
scope()), raw_id_(scoped_id.
raw_id()) {}
300 const char*
scope()
const {
return scope_; }
301 uint64_t
raw_id()
const {
return raw_id_; }
304 const char* scope_ =
nullptr;
315 : raw_id_(static_cast<uint64_t>(raw_id)) {}
318 : raw_id_(static_cast<uint64_t>(raw_id)) {}
320 : raw_id_(static_cast<uint64_t>(raw_id)) {}
321 uint64_t
raw_id()
const {
return raw_id_; }
328 : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {
335 : scope_(maybe_scoped_id.
scope()), raw_id_(maybe_scoped_id.
raw_id()) {}
349 : raw_id_(static_cast<uint64_t>(raw_id)) {
353 : raw_id_(static_cast<uint64_t>(raw_id)) {
357 : raw_id_(static_cast<uint64_t>(raw_id)) {
361 : raw_id_(static_cast<uint64_t>(raw_id)) {
365 : scope_(scoped_id.
scope()), raw_id_(scoped_id.
raw_id()) {}
367 uint64_t
raw_id()
const {
return raw_id_; }
368 const char*
scope()
const {
return scope_; }
371 const char* scope_ =
nullptr;
389 operator const char*()
const {
return str_; }
395 static inline uint64_t AddTraceEventImpl(
396 char phase,
const uint8_t* category_group_enabled,
const char* name,
397 const char*
scope, uint64_t
id, uint64_t bind_id, int32_t num_args,
398 const char** arg_names,
const uint8_t* arg_types,
399 const uint64_t* arg_values,
unsigned int flags) {
400 std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertibles[2];
402 arg_convertibles[0].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
403 static_cast<intptr_t>(arg_values[0])));
406 arg_convertibles[1].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
407 static_cast<intptr_t>(arg_values[1])));
410 v8::TracingController* controller =
412 return controller->AddTraceEvent(phase, category_group_enabled, name, scope,
id,
413 bind_id, num_args, arg_names, arg_types,
414 arg_values, arg_convertibles, flags);
420 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \ 422 static inline void SetTraceValue(actual_type arg, unsigned char* type, \ 424 TraceValueUnion type_value; \ 425 type_value.union_member = arg; \ 426 *type = value_type_id; \ 427 *value = type_value.as_uint; \ 430 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \ 431 static inline void SetTraceValue(actual_type arg, unsigned char* type, \ 433 *type = value_type_id; \ 434 *value = static_cast<uint64_t>(arg); \ 454 #undef INTERNAL_DECLARE_SET_TRACE_VALUE 455 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT 457 static inline void SetTraceValue(v8::ConvertableToTraceFormat* convertable_value,
458 unsigned char* type, uint64_t* value) {
460 *value =
static_cast<uint64_t
>(
reinterpret_cast<intptr_t
>(convertable_value));
463 template <
typename T>
464 static inline typename std::enable_if<
465 std::is_convertible<T*, v8::ConvertableToTraceFormat*>::value>::type
466 SetTraceValue(std::unique_ptr<T> ptr,
unsigned char* type, uint64_t* value) {
467 SetTraceValue(ptr.release(), type, value);
476 static inline uint64_t AddTraceEvent(
char phase,
477 const uint8_t* category_group_enabled,
478 const char* name,
const char* scope,
479 uint64_t
id, uint64_t bind_id,
480 unsigned int flags) {
482 scope,
id, bind_id, kZeroNumArgs,
483 nullptr,
nullptr,
nullptr, flags);
486 template <
class ARG1_TYPE>
487 static inline uint64_t AddTraceEvent(
488 char phase,
const uint8_t* category_group_enabled,
const char* name,
489 const char* scope, uint64_t
id, uint64_t bind_id,
unsigned int flags,
490 const char* arg1_name, ARG1_TYPE&& arg1_val) {
491 const int num_args = 1;
494 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
496 phase, category_group_enabled, name, scope,
id, bind_id, num_args,
497 &arg1_name, &arg_type, &arg_value, flags);
500 template <
class ARG1_TYPE,
class ARG2_TYPE>
501 static inline uint64_t AddTraceEvent(
502 char phase,
const uint8_t* category_group_enabled,
const char* name,
503 const char* scope, uint64_t
id, uint64_t bind_id,
unsigned int flags,
504 const char* arg1_name, ARG1_TYPE&& arg1_val,
const char* arg2_name,
505 ARG2_TYPE&& arg2_val) {
506 const int num_args = 2;
507 const char* arg_names[2] = {arg1_name, arg2_name};
508 unsigned char arg_types[2];
509 uint64_t arg_values[2];
510 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
512 SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
515 phase, category_group_enabled, name, scope,
id, bind_id, num_args,
516 arg_names, arg_types, arg_values, flags);
526 if (p_data_ && *data_.category_group_enabled)
528 data_.category_group_enabled, data_.name, data_.event_handle);
531 void Initialize(
const uint8_t* category_group_enabled,
const char* name,
532 uint64_t event_handle) {
533 data_.category_group_enabled = category_group_enabled;
535 data_.event_handle = event_handle;
546 const uint8_t* category_group_enabled;
548 uint64_t event_handle;
557 #endif // SRC_TRACING_TRACE_EVENT_H_ TraceStringWithCopy(const char *str)
intptr_t kRuntimeCallStatsTracingEnabled
#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id)
#define TRACE_VALUE_TYPE_POINTER
DontMangle(signed char raw_id)
DontMangle(unsigned char raw_id)
CategoryGroupEnabledFlags
const char * scope() const
TraceID(int raw_id, unsigned int *flags)
TraceID(uint64_t raw_id, unsigned int *flags)
TraceID(int64_t raw_id, unsigned int *flags)
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION
#define TRACE_VALUE_TYPE_CONVERTABLE
DontMangle(int64_t raw_id)
DontMangle(const void *raw_id)
DontMangle(int16_t raw_id)
TraceID(ForceMangle raw_id, unsigned int *flags)
TraceID(int16_t raw_id, unsigned int *flags)
INTERNAL_DECLARE_SET_TRACE_VALUE(const void *, as_pointer, TRACE_VALUE_TYPE_POINTER) INTERNAL_DECLARE_SET_TRACE_VALUE(const char *
DontMangle(unsigned int raw_id)
TraceID(DontMangle maybe_scoped_id, unsigned int *flags)
TraceID(uint16_t raw_id, unsigned int *flags)
ForceMangle(unsigned int raw_id)
char * Data(Local< Value > val)
#define TRACE_VALUE_TYPE_STRING
DontMangle(uint64_t raw_id)
TraceID(unsigned int raw_id, unsigned int *flags)
ForceMangle(unsigned char raw_id)
#define TRACE_EVENT_API_ADD_TRACE_EVENT
#define TRACE_VALUE_TYPE_DOUBLE
const char * scope() const
#define TRACE_VALUE_TYPE_BOOL
ForceMangle(signed char raw_id)
void Initialize(const uint8_t *category_group_enabled, const char *name, uint64_t event_handle)
#define TRACE_VALUE_TYPE_COPY_STRING
ForceMangle(uint16_t raw_id)
ForceMangle(int64_t raw_id)
#define TRACE_EVENT_FLAG_MANGLE_ID
TraceID(WithScope scoped_id, unsigned int *flags)
const char * scope() const
DontMangle(uint16_t raw_id)
TraceID(const void *raw_id, unsigned int *flags)
ForceMangle(uint64_t raw_id)
DontMangle(WithScope scoped_id)
WithScope(const char *scope, uint64_t raw_id)
TraceID(unsigned char raw_id, unsigned int *flags)
#define TRACE_VALUE_TYPE_INT
#define TRACE_VALUE_TYPE_UINT
static v8::TracingController * GetTracingController()
ForceMangle(int16_t raw_id)
TraceID(signed char raw_id, unsigned int *flags)
decltype(nullptr) const kGlobalScope