@@ -96,6 +96,23 @@ enum CategoryGroupEnabledFlags {
96
96
// unsigned int flags)
97
97
#define TRACE_EVENT_API_ADD_TRACE_EVENT v8::internal::tracing::AddTraceEventImpl
98
98
99
+ // Add a trace event to the platform tracing system.
100
+ // uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
101
+ // char phase,
102
+ // const uint8_t* category_group_enabled,
103
+ // const char* name,
104
+ // const char* scope,
105
+ // uint64_t id,
106
+ // uint64_t bind_id,
107
+ // int num_args,
108
+ // const char** arg_names,
109
+ // const uint8_t* arg_types,
110
+ // const uint64_t* arg_values,
111
+ // unsigned int flags,
112
+ // int64_t timestamp)
113
+ #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP \
114
+ v8::internal::tracing::AddTraceEventWithTimestampImpl
115
+
99
116
// Set the duration field of a COMPLETE trace event.
100
117
// void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
101
118
// const uint8_t* category_group_enabled,
@@ -212,10 +229,18 @@ enum CategoryGroupEnabledFlags {
212
229
} \
213
230
} while (0 )
214
231
215
- // Adds a trace event with a given timestamp. Not Implemented.
232
+ // Adds a trace event with a given timestamp.
216
233
#define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP (phase, category_group, name, \
217
234
timestamp, flags, ...) \
218
- UNIMPLEMENTED ()
235
+ do { \
236
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO (category_group); \
237
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE ()) { \
238
+ v8::internal::tracing::AddTraceEventWithTimestamp ( \
239
+ phase, INTERNAL_TRACE_EVENT_UID (category_group_enabled), name, \
240
+ v8::internal::tracing::kGlobalScope , v8::internal::tracing::kNoId , \
241
+ v8::internal::tracing::kNoId , flags, timestamp, ##__VA_ARGS__); \
242
+ } \
243
+ } while (0 )
219
244
220
245
// Adds a trace event with a given id and timestamp. Not Implemented.
221
246
#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP ( \
@@ -431,6 +456,28 @@ static V8_INLINE uint64_t AddTraceEventImpl(
431
456
arg_values, arg_convertables, flags);
432
457
}
433
458
459
+ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl (
460
+ char phase, const uint8_t * category_group_enabled, const char * name,
461
+ const char * scope, uint64_t id, uint64_t bind_id, int32_t num_args,
462
+ const char ** arg_names, const uint8_t * arg_types,
463
+ const uint64_t * arg_values, unsigned int flags, int64_t timestamp) {
464
+ std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2 ];
465
+ if (num_args > 0 && arg_types[0 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
466
+ arg_convertables[0 ].reset (reinterpret_cast <ConvertableToTraceFormat*>(
467
+ static_cast <intptr_t >(arg_values[0 ])));
468
+ }
469
+ if (num_args > 1 && arg_types[1 ] == TRACE_VALUE_TYPE_CONVERTABLE) {
470
+ arg_convertables[1 ].reset (reinterpret_cast <ConvertableToTraceFormat*>(
471
+ static_cast <intptr_t >(arg_values[1 ])));
472
+ }
473
+ DCHECK_LE (num_args, 2 );
474
+ v8::TracingController* controller =
475
+ v8::internal::tracing::TraceEventHelper::GetTracingController ();
476
+ return controller->AddTraceEventWithTimestamp (
477
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
478
+ arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
479
+ }
480
+
434
481
// Define SetTraceValue for each allowed type. It stores the type and
435
482
// value in the return arguments. This allows this API to avoid declaring any
436
483
// structures so that it is portable to third_party libraries.
@@ -533,6 +580,48 @@ static V8_INLINE uint64_t AddTraceEvent(
533
580
arg_names, arg_types, arg_values, flags);
534
581
}
535
582
583
+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
584
+ char phase, const uint8_t * category_group_enabled, const char * name,
585
+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
586
+ int64_t timestamp) {
587
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
588
+ phase, category_group_enabled, name, scope, id, bind_id, kZeroNumArgs ,
589
+ nullptr , nullptr , nullptr , flags, timestamp);
590
+ }
591
+
592
+ template <class ARG1_TYPE >
593
+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
594
+ char phase, const uint8_t * category_group_enabled, const char * name,
595
+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
596
+ int64_t timestamp, const char * arg1_name, ARG1_TYPE&& arg1_val) {
597
+ const int num_args = 1 ;
598
+ uint8_t arg_type;
599
+ uint64_t arg_value;
600
+ SetTraceValue (std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
601
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
602
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
603
+ &arg1_name, &arg_type, &arg_value, flags, timestamp);
604
+ }
605
+
606
+ template <class ARG1_TYPE , class ARG2_TYPE >
607
+ static V8_INLINE uint64_t AddTraceEventWithTimestamp (
608
+ char phase, const uint8_t * category_group_enabled, const char * name,
609
+ const char * scope, uint64_t id, uint64_t bind_id, unsigned int flags,
610
+ int64_t timestamp, const char * arg1_name, ARG1_TYPE&& arg1_val,
611
+ const char * arg2_name, ARG2_TYPE&& arg2_val) {
612
+ const int num_args = 2 ;
613
+ const char * arg_names[2 ] = {arg1_name, arg2_name};
614
+ unsigned char arg_types[2 ];
615
+ uint64_t arg_values[2 ];
616
+ SetTraceValue (std::forward<ARG1_TYPE>(arg1_val), &arg_types[0 ],
617
+ &arg_values[0 ]);
618
+ SetTraceValue (std::forward<ARG2_TYPE>(arg2_val), &arg_types[1 ],
619
+ &arg_values[1 ]);
620
+ return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP (
621
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
622
+ arg_names, arg_types, arg_values, flags, timestamp);
623
+ }
624
+
536
625
// Used by TRACE_EVENTx macros. Do not use directly.
537
626
class ScopedTracer {
538
627
public:
0 commit comments