Skip to content

Commit ce65bb0

Browse files
committed
src: add tracing category macros
Adds `TRACING_CATEGORY_NODE`, `TRACING_CATEGORY_NODE1` and `TRACING_CATEGORY_NODE2` helper macros for consistently building trace event category strings. For instance, `TRACING_CATEGORY_NODE2(foo, bar)` would generate the category string `node,node.foo,node.foo.bar`, such that... ``` TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( TRACING_CATEGORY_NODE2(foo, bar), "baz", 1); ``` Would emit if trace events are enabled for categories: `node`, `node.foo`, or `node.foo.bar`. This allows a natural scoping down of what trace events a user may want to receive. Enabling the `node` category would receive everything Node.js produces.
1 parent 74ff743 commit ce65bb0

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/async_wrap.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ void AsyncWrap::EmitTraceEventBefore() {
179179
switch (provider_type()) {
180180
#define V(PROVIDER) \
181181
case PROVIDER_ ## PROVIDER: \
182-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("node.async_hooks", \
182+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( \
183+
TRACING_CATEGORY_NODE1(async_hooks), \
183184
#PROVIDER "_CALLBACK", static_cast<int64_t>(get_async_id())); \
184185
break;
185186
NODE_ASYNC_PROVIDER_TYPES(V)
@@ -207,7 +208,8 @@ void AsyncWrap::EmitTraceEventAfter() {
207208
switch (provider_type()) {
208209
#define V(PROVIDER) \
209210
case PROVIDER_ ## PROVIDER: \
210-
TRACE_EVENT_NESTABLE_ASYNC_END0("node.async_hooks", \
211+
TRACE_EVENT_NESTABLE_ASYNC_END0( \
212+
TRACING_CATEGORY_NODE1(async_hooks), \
211213
#PROVIDER "_CALLBACK", static_cast<int64_t>(get_async_id())); \
212214
break;
213215
NODE_ASYNC_PROVIDER_TYPES(V)
@@ -631,7 +633,8 @@ void AsyncWrap::EmitTraceEventDestroy() {
631633
switch (provider_type()) {
632634
#define V(PROVIDER) \
633635
case PROVIDER_ ## PROVIDER: \
634-
TRACE_EVENT_NESTABLE_ASYNC_END0("node.async_hooks", \
636+
TRACE_EVENT_NESTABLE_ASYNC_END0( \
637+
TRACING_CATEGORY_NODE1(async_hooks), \
635638
#PROVIDER, static_cast<int64_t>(get_async_id())); \
636639
break;
637640
NODE_ASYNC_PROVIDER_TYPES(V)
@@ -664,7 +667,8 @@ void AsyncWrap::AsyncReset(double execution_async_id, bool silent) {
664667
switch (provider_type()) {
665668
#define V(PROVIDER) \
666669
case PROVIDER_ ## PROVIDER: \
667-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2("node.async_hooks", \
670+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( \
671+
TRACING_CATEGORY_NODE1(async_hooks), \
668672
#PROVIDER, static_cast<int64_t>(get_async_id()), \
669673
"executionAsyncId", \
670674
static_cast<int64_t>(env()->execution_async_id()), \

src/node_internals.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,15 @@ static inline const char *errno_string(int errorno) {
776776
#define NODE_MODULE_CONTEXT_AWARE_INTERNAL(modname, regfunc) \
777777
NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL)
778778

779+
#define TRACING_CATEGORY_NODE "node"
780+
#define TRACING_CATEGORY_NODE1(one) \
781+
TRACING_CATEGORY_NODE "," \
782+
TRACING_CATEGORY_NODE "." #one
783+
#define TRACING_CATEGORY_NODE2(one, two) \
784+
TRACING_CATEGORY_NODE "," \
785+
TRACING_CATEGORY_NODE "." #one "," \
786+
TRACING_CATEGORY_NODE "." #one "." #two
787+
779788
} // namespace node
780789

781790

src/node_perf.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ void Mark(const FunctionCallbackInfo<Value>& args) {
135135
(*marks)[*name] = now;
136136

137137
TRACE_EVENT_COPY_MARK_WITH_TIMESTAMP(
138-
"node.perf,node.perf.usertiming", *name, now / 1000);
138+
TRACING_CATEGORY_NODE2(perf, usertiming),
139+
*name, now / 1000);
139140

140141
PerformanceEntry entry(env, *name, "mark", now, now);
141142
Local<Object> obj = entry.ToObject();
@@ -183,9 +184,11 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
183184
endTimestamp = startTimestamp;
184185

185186
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
186-
"node.perf,node.perf.usertiming", *name, *name, startTimestamp / 1000);
187+
TRACING_CATEGORY_NODE2(perf, usertiming),
188+
*name, *name, startTimestamp / 1000);
187189
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
188-
"node.perf,node.perf.usertiming", *name, *name, endTimestamp / 1000);
190+
TRACING_CATEGORY_NODE2(perf, usertiming),
191+
*name, *name, endTimestamp / 1000);
189192

190193
PerformanceEntry entry(env, *name, "measure", startTimestamp, endTimestamp);
191194
Local<Object> obj = entry.ToObject();
@@ -301,13 +304,15 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
301304
if (args.IsConstructCall()) {
302305
start = PERFORMANCE_NOW();
303306
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
304-
"node.perf,node.perf.timerify", *name, *name, start / 1000);
307+
TRACING_CATEGORY_NODE2(perf, timerify),
308+
*name, *name, start / 1000);
305309
v8::MaybeLocal<Object> ret = fn->NewInstance(context,
306310
call_args.size(),
307311
call_args.data());
308312
end = PERFORMANCE_NOW();
309313
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
310-
"node.perf,node.perf.timerify", *name, *name, end / 1000);
314+
TRACING_CATEGORY_NODE2(perf, timerify),
315+
*name, *name, end / 1000);
311316

312317
if (ret.IsEmpty()) {
313318
try_catch.ReThrow();
@@ -317,14 +322,16 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
317322
} else {
318323
start = PERFORMANCE_NOW();
319324
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
320-
"node.perf,node.perf.timerify", *name, *name, start / 1000);
325+
TRACING_CATEGORY_NODE2(perf, timerify),
326+
*name, *name, start / 1000);
321327
v8::MaybeLocal<Value> ret = fn->Call(context,
322328
args.This(),
323329
call_args.size(),
324330
call_args.data());
325331
end = PERFORMANCE_NOW();
326332
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
327-
"node.perf,node.perf.timerify", *name, *name, end / 1000);
333+
TRACING_CATEGORY_NODE2(perf, timerify),
334+
*name, *name, end / 1000);
328335

329336
if (ret.IsEmpty()) {
330337
try_catch.ReThrow();

0 commit comments

Comments
 (0)