Skip to content

Commit 86283aa

Browse files
addaleaxcodebytere
authored andcommitted
src: handle missing TracingController everywhere
Fixes: #33800 PR-URL: #33815 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c4129f9 commit 86283aa

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/tracing/trace_event.h

+14-5
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -317,6 +317,13 @@ class NODE_EXTERN TraceEventHelper {
317317
static TracingController* GetTracingController();
318318
static Agent* GetAgent();
319319
static void SetAgent(Agent* agent);
320+
321+
static inline const uint8_t* GetCategoryGroupEnabled(const char* group) {
322+
v8::TracingController* controller = GetTracingController();
323+
static const uint8_t disabled = 0;
324+
if (UNLIKELY(controller == nullptr)) return &disabled;
325+
return controller->GetCategoryGroupEnabled(group);
326+
}
320327
};
321328

322329
// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
@@ -465,6 +472,7 @@ static inline uint64_t AddTraceEventImpl(
465472
// DCHECK(num_args, 2);
466473
v8::TracingController* controller =
467474
node::tracing::TraceEventHelper::GetTracingController();
475+
if (controller == nullptr) return 0;
468476
return controller->AddTraceEvent(phase, category_group_enabled, name, scope, id,
469477
bind_id, num_args, arg_names, arg_types,
470478
arg_values, arg_convertibles, flags);
@@ -487,6 +495,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
487495
// DCHECK_LE(num_args, 2);
488496
v8::TracingController* controller =
489497
node::tracing::TraceEventHelper::GetTracingController();
498+
if (controller == nullptr) return 0;
490499
return controller->AddTraceEventWithTimestamp(
491500
phase, category_group_enabled, name, scope, id, bind_id, num_args,
492501
arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);

0 commit comments

Comments
 (0)