Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace_events,async_hooks: use intrinsic trace #22127

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jasnell committed Aug 9, 2018
commit c0246c759e54e9b1245edb104d46f3c25beb5b91
20 changes: 10 additions & 10 deletions lib/internal/trace_events_async_hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

exports.setup = function(traceEvents, traceEventCategory) {
const { trace } = traceEvents;
const async_wrap = process.binding('async_wrap');
const async_hooks = require('async_hooks');

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

typeMemory.set(asyncId, type);
traceEvents.emit(BEFORE_EVENT, traceEventCategory,
type, asyncId,
'triggerAsyncId', triggerAsyncId,
'executionAsyncId', async_hooks.executionAsyncId());
trace(BEFORE_EVENT, traceEventCategory,
type, asyncId,
{
triggerAsyncId,
executionAsyncId: async_hooks.executionAsyncId()
});
},

before(asyncId) {
const type = typeMemory.get(asyncId);
if (type === undefined) return;

traceEvents.emit(BEFORE_EVENT, traceEventCategory,
type + '_CALLBACK', asyncId);
trace(BEFORE_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
},

after(asyncId) {
const type = typeMemory.get(asyncId);
if (type === undefined) return;

traceEvents.emit(END_EVENT, traceEventCategory,
type + '_CALLBACK', asyncId);
trace(END_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
},

destroy(asyncId) {
const type = typeMemory.get(asyncId);
if (type === undefined) return;

traceEvents.emit(END_EVENT, traceEventCategory,
type, asyncId);
trace(END_EVENT, traceEventCategory, type, asyncId);

// cleanup asyncId to type map
typeMemory.delete(asyncId);
Expand Down
20 changes: 13 additions & 7 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "env-inl.h"
#include "node_internals.h"
#include "util-inl.h"
#include "tracing/traced_value.h"

#include "v8.h"
#include "v8-profiler.h"
Expand Down Expand Up @@ -608,13 +609,18 @@ void AsyncWrap::AsyncReset(double execution_async_id, bool silent) {
switch (provider_type()) {
#define V(PROVIDER) \
case PROVIDER_ ## PROVIDER: \
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( \
TRACING_CATEGORY_NODE1(async_hooks), \
#PROVIDER, static_cast<int64_t>(get_async_id()), \
"executionAsyncId", \
static_cast<int64_t>(env()->execution_async_id()), \
"triggerAsyncId", \
static_cast<int64_t>(get_trigger_async_id())); \
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
TRACING_CATEGORY_NODE1(async_hooks))) { \
auto data = tracing::TracedValue::Create(); \
data->SetInteger("executionAsyncId", \
static_cast<int64_t>(env()->execution_async_id())); \
data->SetInteger("triggerAsyncId", \
static_cast<int64_t>(get_trigger_async_id())); \
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( \
TRACING_CATEGORY_NODE1(async_hooks), \
#PROVIDER, static_cast<int64_t>(get_async_id()), \
"data", std::move(data)); \
} \
break;
NODE_ASYNC_PROVIDER_TYPES(V)
#undef V
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-trace-events-async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ proc.once('exit', common.mustCall(() => {
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
});
assert.ok(initEvents.every((trace) => {
return (trace.args.executionAsyncId > 0 &&
trace.args.triggerAsyncId > 0);
return (trace.args.data.executionAsyncId > 0 &&
trace.args.data.triggerAsyncId > 0);
}), `Unexpected initEvents format: ${util.inspect(initEvents)}`);
}));
}));