Skip to content

Commit c85933c

Browse files
committed
trace_events,async_hooks: use intrinsic trace
Switch to using the intrinsic trace event method for async_hooks. This is a breaking change because of the switch to a nested data argument for exec id and trigger id values. PR-URL: #22127 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
1 parent 88bff82 commit c85933c

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

lib/internal/trace_events_async_hooks.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
exports.setup = function(traceEvents, traceEventCategory) {
4+
const { trace } = traceEvents;
45
const async_wrap = process.binding('async_wrap');
56
const async_hooks = require('async_hooks');
67

@@ -27,34 +28,33 @@ exports.setup = function(traceEvents, traceEventCategory) {
2728
if (nativeProviders.has(type)) return;
2829

2930
typeMemory.set(asyncId, type);
30-
traceEvents.emit(BEFORE_EVENT, traceEventCategory,
31-
type, asyncId,
32-
'triggerAsyncId', triggerAsyncId,
33-
'executionAsyncId', async_hooks.executionAsyncId());
31+
trace(BEFORE_EVENT, traceEventCategory,
32+
type, asyncId,
33+
{
34+
triggerAsyncId,
35+
executionAsyncId: async_hooks.executionAsyncId()
36+
});
3437
},
3538

3639
before(asyncId) {
3740
const type = typeMemory.get(asyncId);
3841
if (type === undefined) return;
3942

40-
traceEvents.emit(BEFORE_EVENT, traceEventCategory,
41-
type + '_CALLBACK', asyncId);
43+
trace(BEFORE_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
4244
},
4345

4446
after(asyncId) {
4547
const type = typeMemory.get(asyncId);
4648
if (type === undefined) return;
4749

48-
traceEvents.emit(END_EVENT, traceEventCategory,
49-
type + '_CALLBACK', asyncId);
50+
trace(END_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
5051
},
5152

5253
destroy(asyncId) {
5354
const type = typeMemory.get(asyncId);
5455
if (type === undefined) return;
5556

56-
traceEvents.emit(END_EVENT, traceEventCategory,
57-
type, asyncId);
57+
trace(END_EVENT, traceEventCategory, type, asyncId);
5858

5959
// cleanup asyncId to type map
6060
typeMemory.delete(asyncId);

src/async_wrap.cc

+13-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "env-inl.h"
2424
#include "node_internals.h"
2525
#include "util-inl.h"
26+
#include "tracing/traced_value.h"
2627

2728
#include "v8.h"
2829
#include "v8-profiler.h"
@@ -608,13 +609,18 @@ void AsyncWrap::AsyncReset(double execution_async_id, bool silent) {
608609
switch (provider_type()) {
609610
#define V(PROVIDER) \
610611
case PROVIDER_ ## PROVIDER: \
611-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( \
612-
TRACING_CATEGORY_NODE1(async_hooks), \
613-
#PROVIDER, static_cast<int64_t>(get_async_id()), \
614-
"executionAsyncId", \
615-
static_cast<int64_t>(env()->execution_async_id()), \
616-
"triggerAsyncId", \
617-
static_cast<int64_t>(get_trigger_async_id())); \
612+
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
613+
TRACING_CATEGORY_NODE1(async_hooks))) { \
614+
auto data = tracing::TracedValue::Create(); \
615+
data->SetInteger("executionAsyncId", \
616+
static_cast<int64_t>(env()->execution_async_id())); \
617+
data->SetInteger("triggerAsyncId", \
618+
static_cast<int64_t>(get_trigger_async_id())); \
619+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( \
620+
TRACING_CATEGORY_NODE1(async_hooks), \
621+
#PROVIDER, static_cast<int64_t>(get_async_id()), \
622+
"data", std::move(data)); \
623+
} \
618624
break;
619625
NODE_ASYNC_PROVIDER_TYPES(V)
620626
#undef V

test/parallel/test-trace-events-async-hooks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ proc.once('exit', common.mustCall(() => {
6161
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
6262
});
6363
assert.ok(initEvents.every((trace) => {
64-
return (trace.args.executionAsyncId > 0 &&
65-
trace.args.triggerAsyncId > 0);
64+
return (trace.args.data.executionAsyncId > 0 &&
65+
trace.args.data.triggerAsyncId > 0);
6666
}), `Unexpected initEvents format: ${util.inspect(initEvents)}`);
6767
}));
6868
}));

0 commit comments

Comments
 (0)