@@ -310,8 +310,9 @@ const uint64_t kNoId = 0;
310310
311311class TraceEventHelper {
312312 public:
313- static v8::TracingController* GetTracingController ();
314- static void SetTracingController (v8::TracingController* controller);
313+ static TracingController* GetTracingController ();
314+ static Agent* GetAgent ();
315+ static void SetAgent (Agent* agent);
315316};
316317
317318// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
@@ -487,6 +488,26 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
487488 arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
488489}
489490
491+ static V8_INLINE void AddMetadataEventImpl (
492+ const uint8_t * category_group_enabled, const char * name, int32_t num_args,
493+ const char ** arg_names, const uint8_t * arg_types,
494+ const uint64_t * arg_values, unsigned int flags) {
495+ std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertibles[2 ];
496+ if (num_args > 0 && arg_types[0 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
497+ arg_convertibles[0 ].reset (reinterpret_cast <v8::ConvertableToTraceFormat*>(
498+ static_cast <intptr_t >(arg_values[0 ])));
499+ }
500+ if (num_args > 1 && arg_types[1 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
501+ arg_convertibles[1 ].reset (reinterpret_cast <v8::ConvertableToTraceFormat*>(
502+ static_cast <intptr_t >(arg_values[1 ])));
503+ }
504+ node::tracing::TracingController* controller =
505+ node::tracing::TraceEventHelper::GetTracingController ();
506+ return controller->AddMetadataEvent (
507+ category_group_enabled, name, num_args, arg_names, arg_types, arg_values,
508+ arg_convertibles, flags);
509+ }
510+
490511// Define SetTraceValue for each allowed type. It stores the type and
491512// value in the return arguments. This allows this API to avoid declaring any
492513// structures so that it is portable to third_party libraries.
@@ -632,23 +653,16 @@ static V8_INLINE uint64_t AddTraceEventWithTimestamp(
632653}
633654
634655template <class ARG1_TYPE >
635- static V8_INLINE uint64_t AddMetadataEvent (
656+ static V8_INLINE void AddMetadataEvent (
636657 const uint8_t * category_group_enabled, const char * name,
637658 const char * arg1_name, ARG1_TYPE&& arg1_val) {
638659 const int num_args = 1 ;
639660 uint8_t arg_type;
640661 uint64_t arg_value;
641662 SetTraceValue (std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
642- // TODO(ofrobots): It would be good to add metadata events to a separate
643- // buffer so that they can be periodically reemitted. For now, we have a
644- // single buffer, so we just add them to the main buffer.
645- return TRACE_EVENT_API_ADD_TRACE_EVENT (
646- TRACE_EVENT_PHASE_METADATA,
647- category_group_enabled, name,
648- node::tracing::kGlobalScope , // scope
649- node::tracing::kNoId , // id
650- node::tracing::kNoId , // bind_id
651- num_args, &arg1_name, &arg_type, &arg_value, TRACE_EVENT_FLAG_NONE);
663+ AddMetadataEventImpl (
664+ category_group_enabled, name, num_args, &arg1_name, &arg_type, &arg_value,
665+ TRACE_EVENT_FLAG_NONE);
652666}
653667
654668// Used by TRACE_EVENTx macros. Do not use directly.
0 commit comments