@@ -92,6 +92,23 @@ enum CategoryGroupEnabledFlags {
9292// unsigned int flags)
9393#define TRACE_EVENT_API_ADD_TRACE_EVENT node::tracing::AddTraceEventImpl
9494
95+ // Add a trace event to the platform tracing system.
96+ // uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
97+ // char phase,
98+ // const uint8_t* category_group_enabled,
99+ // const char* name,
100+ // const char* scope,
101+ // uint64_t id,
102+ // uint64_t bind_id,
103+ // int num_args,
104+ // const char** arg_names,
105+ // const uint8_t* arg_types,
106+ // const uint64_t* arg_values,
107+ // unsigned int flags,
108+ // int64_t timestamp)
109+ #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP \
110+ node::tracing::AddTraceEventWithTimestampImpl
111+
95112// Set the duration field of a COMPLETE trace event.
96113// void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
97114// const uint8_t* category_group_enabled,
@@ -207,10 +224,18 @@ enum CategoryGroupEnabledFlags {
207224 } \
208225 } while (0 )
209226
210- // Adds a trace event with a given timestamp. Not Implemented.
227+ // Adds a trace event with a given timestamp.
211228#define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP (phase, category_group, name, \
212229 timestamp, flags, ...) \
213- UNIMPLEMENTED ()
230+ do { \
231+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO (category_group); \
232+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE ()) { \
233+ node::tracing::AddTraceEventWithTimestamp ( \
234+ phase, INTERNAL_TRACE_EVENT_UID (category_group_enabled), name, \
235+ node::tracing::kGlobalScope , node::tracing::kNoId , \
236+ node::tracing::kNoId , flags, timestamp, ##__VA_ARGS__); \
237+ } \
238+ } while (0 )
214239
215240// Adds a trace event with a given id and timestamp. Not Implemented.
216241#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP ( \
@@ -253,8 +278,6 @@ const int kZeroNumArgs = 0;
253278const decltype (nullptr ) kGlobalScope = nullptr;
254279const uint64_t kNoId = 0 ;
255280
256- extern intptr_t kRuntimeCallStatsTracingEnabled ;
257-
258281class TraceEventHelper {
259282 public:
260283 static v8::TracingController* GetTracingController ();
@@ -404,14 +427,36 @@ static inline uint64_t AddTraceEventImpl(
404427 arg_convertibles[1 ].reset (reinterpret_cast <v8::ConvertableToTraceFormat*>(
405428 static_cast <intptr_t >(arg_values[1 ])));
406429 }
407- // DCHECK(num_args <= 2);
430+ // DCHECK(num_args, 2);
408431 v8::TracingController* controller =
409432 node::tracing::TraceEventHelper::GetTracingController ();
410433 return controller->AddTraceEvent (phase, category_group_enabled, name, scope, id,
411434 bind_id, num_args, arg_names, arg_types,
412435 arg_values, arg_convertibles, flags);
413436}
414437
438+ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl (
439+ char phase, const uint8_t * category_group_enabled, const char * name,
440+ const char * scope, uint64_t id, uint64_t bind_id, int32_t num_args,
441+ const char ** arg_names, const uint8_t * arg_types,
442+ const uint64_t * arg_values, unsigned int flags, int64_t timestamp) {
443+ std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertables[2 ];
444+ if (num_args > 0 && arg_types[0 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
445+ arg_convertables[0 ].reset (reinterpret_cast <v8::ConvertableToTraceFormat*>(
446+ static_cast <intptr_t >(arg_values[0 ])));
447+ }
448+ if (num_args > 1 && arg_types[1 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
449+ arg_convertables[1 ].reset (reinterpret_cast <v8::ConvertableToTraceFormat*>(
450+ static_cast <intptr_t >(arg_values[1 ])));
451+ }
452+ // DCHECK_LE(num_args, 2);
453+ v8::TracingController* controller =
454+ node::tracing::TraceEventHelper::GetTracingController ();
455+ return controller->AddTraceEventWithTimestamp (
456+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
457+ arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
458+ }
459+
415460// Define SetTraceValue for each allowed type. It stores the type and
416461// value in the return arguments. This allows this API to avoid declaring any
417462// structures so that it is portable to third_party libraries.
@@ -514,6 +559,48 @@ static inline uint64_t AddTraceEvent(
514559 arg_names, arg_types, arg_values, flags);
515560}
516561
562+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
563+ char phase, const uint8_t * category_group_enabled, const char * name,
564+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
565+ int64_t timestamp) {
566+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
567+ phase, category_group_enabled, name, scope, id, bind_id, kZeroNumArgs ,
568+ nullptr , nullptr , nullptr , flags, timestamp);
569+ }
570+
571+ template <class ARG1_TYPE >
572+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
573+ char phase, const uint8_t * category_group_enabled, const char * name,
574+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
575+ int64_t timestamp, const char * arg1_name, ARG1_TYPE&& arg1_val) {
576+ const int num_args = 1 ;
577+ uint8_t arg_type;
578+ uint64_t arg_value;
579+ SetTraceValue (std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
580+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
581+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
582+ &arg1_name, &arg_type, &arg_value, flags, timestamp);
583+ }
584+
585+ template <class ARG1_TYPE , class ARG2_TYPE >
586+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
587+ char phase, const uint8_t * category_group_enabled, const char * name,
588+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
589+ int64_t timestamp, const char * arg1_name, ARG1_TYPE&& arg1_val,
590+ const char * arg2_name, ARG2_TYPE&& arg2_val) {
591+ const int num_args = 2 ;
592+ const char * arg_names[2 ] = {arg1_name, arg2_name};
593+ unsigned char arg_types[2 ];
594+ uint64_t arg_values[2 ];
595+ SetTraceValue (std::forward<ARG1_TYPE>(arg1_val), &arg_types[0 ],
596+ &arg_values[0 ]);
597+ SetTraceValue (std::forward<ARG2_TYPE>(arg2_val), &arg_types[1 ],
598+ &arg_values[1 ]);
599+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
600+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
601+ arg_names, arg_types, arg_values, flags, timestamp);
602+ }
603+
517604// Used by TRACE_EVENTx macros. Do not use directly.
518605class ScopedTracer {
519606 public:
0 commit comments