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: https://github.com/nodejs/node/pull/22127
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
This commit is contained in:
James M Snell 2018-08-04 09:48:50 -07:00
parent 88bff82624
commit c85933cbd0
3 changed files with 25 additions and 19 deletions

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
exports.setup = function(traceEvents, traceEventCategory) { exports.setup = function(traceEvents, traceEventCategory) {
const { trace } = traceEvents;
const async_wrap = process.binding('async_wrap'); const async_wrap = process.binding('async_wrap');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
@ -27,34 +28,33 @@ exports.setup = function(traceEvents, traceEventCategory) {
if (nativeProviders.has(type)) return; if (nativeProviders.has(type)) return;
typeMemory.set(asyncId, type); typeMemory.set(asyncId, type);
traceEvents.emit(BEFORE_EVENT, traceEventCategory, trace(BEFORE_EVENT, traceEventCategory,
type, asyncId, type, asyncId,
'triggerAsyncId', triggerAsyncId, {
'executionAsyncId', async_hooks.executionAsyncId()); triggerAsyncId,
executionAsyncId: async_hooks.executionAsyncId()
});
}, },
before(asyncId) { before(asyncId) {
const type = typeMemory.get(asyncId); const type = typeMemory.get(asyncId);
if (type === undefined) return; if (type === undefined) return;
traceEvents.emit(BEFORE_EVENT, traceEventCategory, trace(BEFORE_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
type + '_CALLBACK', asyncId);
}, },
after(asyncId) { after(asyncId) {
const type = typeMemory.get(asyncId); const type = typeMemory.get(asyncId);
if (type === undefined) return; if (type === undefined) return;
traceEvents.emit(END_EVENT, traceEventCategory, trace(END_EVENT, traceEventCategory, `${type}_CALLBACK`, asyncId);
type + '_CALLBACK', asyncId);
}, },
destroy(asyncId) { destroy(asyncId) {
const type = typeMemory.get(asyncId); const type = typeMemory.get(asyncId);
if (type === undefined) return; if (type === undefined) return;
traceEvents.emit(END_EVENT, traceEventCategory, trace(END_EVENT, traceEventCategory, type, asyncId);
type, asyncId);
// cleanup asyncId to type map // cleanup asyncId to type map
typeMemory.delete(asyncId); typeMemory.delete(asyncId);

View File

@ -23,6 +23,7 @@
#include "env-inl.h" #include "env-inl.h"
#include "node_internals.h" #include "node_internals.h"
#include "util-inl.h" #include "util-inl.h"
#include "tracing/traced_value.h"
#include "v8.h" #include "v8.h"
#include "v8-profiler.h" #include "v8-profiler.h"
@ -608,13 +609,18 @@ void AsyncWrap::AsyncReset(double execution_async_id, bool silent) {
switch (provider_type()) { switch (provider_type()) {
#define V(PROVIDER) \ #define V(PROVIDER) \
case PROVIDER_ ## PROVIDER: \ case PROVIDER_ ## PROVIDER: \
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( \ if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
TRACING_CATEGORY_NODE1(async_hooks), \ TRACING_CATEGORY_NODE1(async_hooks))) { \
#PROVIDER, static_cast<int64_t>(get_async_id()), \ auto data = tracing::TracedValue::Create(); \
"executionAsyncId", \ data->SetInteger("executionAsyncId", \
static_cast<int64_t>(env()->execution_async_id()), \ static_cast<int64_t>(env()->execution_async_id())); \
"triggerAsyncId", \ data->SetInteger("triggerAsyncId", \
static_cast<int64_t>(get_trigger_async_id())); \ 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; break;
NODE_ASYNC_PROVIDER_TYPES(V) NODE_ASYNC_PROVIDER_TYPES(V)
#undef V #undef V

View File

@ -61,8 +61,8 @@ proc.once('exit', common.mustCall(() => {
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK')); return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
}); });
assert.ok(initEvents.every((trace) => { assert.ok(initEvents.every((trace) => {
return (trace.args.executionAsyncId > 0 && return (trace.args.data.executionAsyncId > 0 &&
trace.args.triggerAsyncId > 0); trace.args.data.triggerAsyncId > 0);
}), `Unexpected initEvents format: ${util.inspect(initEvents)}`); }), `Unexpected initEvents format: ${util.inspect(initEvents)}`);
})); }));
})); }));