@@ -118,6 +118,15 @@ enum CategoryGroupEnabledFlags {
118118 node::tracing::TraceEventHelper::GetTracingController () \
119119 ->UpdateTraceEventDuration
120120
121+ // Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method
122+ // on the convertable value will be called at flush time.
123+ // TRACE_EVENT_API_ADD_METADATA_EVENT(
124+ // const unsigned char* category_group_enabled,
125+ // const char* event_name,
126+ // const char* arg_name,
127+ // std::unique_ptr<ConvertableToTraceFormat> arg_value)
128+ #define TRACE_EVENT_API_ADD_METADATA_EVENT node::tracing::AddMetadataEvent
129+
121130// Defines atomic operations used internally by the tracing system.
122131#define TRACE_EVENT_API_ATOMIC_WORD intptr_t
123132#define TRACE_EVENT_API_ATOMIC_LOAD (var ) (var)
@@ -259,6 +268,16 @@ enum CategoryGroupEnabledFlags {
259268 } \
260269 } while (0 )
261270
271+ #define INTERNAL_TRACE_EVENT_METADATA_ADD (category_group, name, ...) \
272+ do { \
273+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO (category_group); \
274+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE ()) { \
275+ TRACE_EVENT_API_ADD_METADATA_EVENT ( \
276+ INTERNAL_TRACE_EVENT_UID (category_group_enabled), name, \
277+ ##__VA_ARGS__); \
278+ } \
279+ } while (0 )
280+
262281// Enter and leave a context based on the current scope.
263282#define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT (category_group, name, context ) \
264283 struct INTERNAL_TRACE_EVENT_UID (ScopedContext) { \
@@ -612,6 +631,26 @@ static V8_INLINE uint64_t AddTraceEventWithTimestamp(
612631 arg_names, arg_types, arg_values, flags, timestamp);
613632}
614633
634+ template <class ARG1_TYPE >
635+ static V8_INLINE uint64_t AddMetadataEvent (
636+ const uint8_t * category_group_enabled, const char * name,
637+ const char * arg1_name, ARG1_TYPE&& arg1_val) {
638+ const int num_args = 1 ;
639+ uint8_t arg_type;
640+ uint64_t arg_value;
641+ 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);
652+ }
653+
615654// Used by TRACE_EVENTx macros. Do not use directly.
616655class ScopedTracer {
617656 public:
0 commit comments