From 86283aaa6afa6cfd2ccf5f489788b4b8c1bfbc44 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 9 Jun 2020 20:47:48 +0200 Subject: [PATCH] src: handle missing TracingController everywhere Fixes: https://github.com/nodejs/node/issues/33800 PR-URL: https://github.com/nodejs/node/pull/33815 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/tracing/trace_event.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/tracing/trace_event.h b/src/tracing/trace_event.h index 27408eafd832ae..c11544dd42cdd0 100644 --- a/src/tracing/trace_event.h +++ b/src/tracing/trace_event.h @@ -70,8 +70,7 @@ enum CategoryGroupEnabledFlags { // const uint8_t* // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group) #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ - node::tracing::TraceEventHelper::GetTracingController() \ - ->GetCategoryGroupEnabled + node::tracing::TraceEventHelper::GetCategoryGroupEnabled // Get the number of times traces have been recorded. This is used to implement // the TRACE_EVENT_IS_NEW_TRACE facility. @@ -115,9 +114,10 @@ enum CategoryGroupEnabledFlags { // const uint8_t* category_group_enabled, // const char* name, // uint64_t id) -#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ - node::tracing::TraceEventHelper::GetTracingController() \ - ->UpdateTraceEventDuration +#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ + if (auto controller = \ + node::tracing::TraceEventHelper::GetTracingController()) \ + controller->UpdateTraceEventDuration // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method // on the convertable value will be called at flush time. @@ -317,6 +317,13 @@ class NODE_EXTERN TraceEventHelper { static TracingController* GetTracingController(); static Agent* GetAgent(); static void SetAgent(Agent* agent); + + static inline const uint8_t* GetCategoryGroupEnabled(const char* group) { + v8::TracingController* controller = GetTracingController(); + static const uint8_t disabled = 0; + if (UNLIKELY(controller == nullptr)) return &disabled; + return controller->GetCategoryGroupEnabled(group); + } }; // TraceID encapsulates an ID that can either be an integer or pointer. Pointers @@ -465,6 +472,7 @@ static inline uint64_t AddTraceEventImpl( // DCHECK(num_args, 2); v8::TracingController* controller = node::tracing::TraceEventHelper::GetTracingController(); + if (controller == nullptr) return 0; return controller->AddTraceEvent(phase, category_group_enabled, name, scope, id, bind_id, num_args, arg_names, arg_types, arg_values, arg_convertibles, flags); @@ -487,6 +495,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl( // DCHECK_LE(num_args, 2); v8::TracingController* controller = node::tracing::TraceEventHelper::GetTracingController(); + if (controller == nullptr) return 0; return controller->AddTraceEventWithTimestamp( phase, category_group_enabled, name, scope, id, bind_id, num_args, arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);