Skip to content

Commit

Permalink
src: handle missing TracingController everywhere
Browse files Browse the repository at this point in the history
Fixes: nodejs#33800

PR-URL: nodejs#33815
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Jun 11, 2020
1 parent c4a33f7 commit dfdbbd1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/tracing/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -319,6 +319,13 @@ class NODE_EXTERN TraceEventHelper {

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
Expand Down Expand Up @@ -467,6 +474,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);
Expand All @@ -489,6 +497,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);
Expand Down

0 comments on commit dfdbbd1

Please sign in to comment.