@@ -70,8 +70,7 @@ enum CategoryGroupEnabledFlags {
7070// const uint8_t*
7171// TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
7272#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
73- node::tracing::TraceEventHelper::GetTracingController () \
74- ->GetCategoryGroupEnabled
73+ node::tracing::TraceEventHelper::GetCategoryGroupEnabled
7574
7675// Get the number of times traces have been recorded. This is used to implement
7776// the TRACE_EVENT_IS_NEW_TRACE facility.
@@ -115,9 +114,10 @@ enum CategoryGroupEnabledFlags {
115114// const uint8_t* category_group_enabled,
116115// const char* name,
117116// uint64_t id)
118- #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
119- node::tracing::TraceEventHelper::GetTracingController () \
120- ->UpdateTraceEventDuration
117+ #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
118+ if (auto controller = \
119+ node::tracing::TraceEventHelper::GetTracingController ()) \
120+ controller->UpdateTraceEventDuration
121121
122122// Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method
123123// on the convertable value will be called at flush time.
@@ -319,6 +319,13 @@ class NODE_EXTERN TraceEventHelper {
319319
320320 static Agent* GetAgent ();
321321 static void SetAgent (Agent* agent);
322+
323+ static inline const uint8_t * GetCategoryGroupEnabled (const char * group) {
324+ v8::TracingController* controller = GetTracingController ();
325+ static const uint8_t disabled = 0 ;
326+ if (UNLIKELY (controller == nullptr )) return &disabled;
327+ return controller->GetCategoryGroupEnabled (group);
328+ }
322329};
323330
324331// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
@@ -467,6 +474,7 @@ static inline uint64_t AddTraceEventImpl(
467474 // DCHECK(num_args, 2);
468475 v8::TracingController* controller =
469476 node::tracing::TraceEventHelper::GetTracingController ();
477+ if (controller == nullptr ) return 0 ;
470478 return controller->AddTraceEvent (phase, category_group_enabled, name, scope, id,
471479 bind_id, num_args, arg_names, arg_types,
472480 arg_values, arg_convertibles, flags);
@@ -489,6 +497,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
489497 // DCHECK_LE(num_args, 2);
490498 v8::TracingController* controller =
491499 node::tracing::TraceEventHelper::GetTracingController ();
500+ if (controller == nullptr ) return 0 ;
492501 return controller->AddTraceEventWithTimestamp (
493502 phase, category_group_enabled, name, scope, id, bind_id, num_args,
494503 arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
0 commit comments