Skip to content

Commit d8ec49e

Browse files
kjinjasnell
authored andcommitted
src: update trace event macros to v8 6.4 version
PR-URL: #17640 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 7dffabb commit d8ec49e

File tree

2 files changed

+117
-7
lines changed

2 files changed

+117
-7
lines changed

src/tracing/trace_event.h

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
253278
const decltype(nullptr) kGlobalScope = nullptr;
254279
const uint64_t kNoId = 0;
255280

256-
extern intptr_t kRuntimeCallStatsTracingEnabled;
257-
258281
class 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.
518605
class ScopedTracer {
519606
public:

src/tracing/trace_event_common.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
// trace points would carry a significant performance cost of acquiring a lock
190190
// and resolving the category.
191191

192+
// Check that nobody includes this file directly. Clients are supposed to
193+
// include the surrounding "trace_event.h" of their project instead.
192194
#if defined(TRACE_EVENT0)
193195
#error "Another copy of this file has already been included."
194196
#endif
@@ -258,6 +260,12 @@
258260
TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp, \
259261
TRACE_EVENT_FLAG_NONE | scope)
260262

263+
#define TRACE_EVENT_INSTANT_WITH_TIMESTAMP1(category_group, name, scope, \
264+
timestamp, arg_name, arg_val) \
265+
INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
266+
TRACE_EVENT_PHASE_INSTANT, category_group, name, timestamp, \
267+
TRACE_EVENT_FLAG_NONE | scope, arg_name, arg_val)
268+
261269
// Records a single BEGIN event called "name" immediately, with 0, 1 or 2
262270
// associated arguments. If the category is not enabled, then this
263271
// does nothing.
@@ -353,6 +361,12 @@
353361
TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
354362
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
355363

364+
#define TRACE_EVENT_MARK_WITH_TIMESTAMP2( \
365+
category_group, name, timestamp, arg1_name, arg1_val, arg2_name, arg2_val) \
366+
INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP( \
367+
TRACE_EVENT_PHASE_MARK, category_group, name, timestamp, \
368+
TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
369+
356370
#define TRACE_EVENT_COPY_MARK(category_group, name) \
357371
INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_MARK, category_group, name, \
358372
TRACE_EVENT_FLAG_COPY)
@@ -771,13 +785,22 @@
771785
INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
772786
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, category_group, name, id, \
773787
TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
774-
775788
#define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(category_group, name, \
776789
id, timestamp) \
777790
INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
778791
TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
779792
TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
780-
793+
#define TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP1( \
794+
category_group, name, id, timestamp, arg1_name, arg1_val) \
795+
INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
796+
TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, category_group, name, id, \
797+
TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE, \
798+
arg1_name, arg1_val)
799+
#define TRACE_EVENT_NESTABLE_ASYNC_INSTANT_WITH_TIMESTAMP0( \
800+
category_group, name, id, timestamp) \
801+
INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
802+
TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT, category_group, name, id, \
803+
TRACE_EVENT_API_CURRENT_THREAD_ID, timestamp, TRACE_EVENT_FLAG_NONE)
781804
#define TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( \
782805
category_group, name, id, timestamp) \
783806
INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \

0 commit comments

Comments
 (0)