-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
async-hooks: add trace events to AsyncWrap #14347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,16 @@ bool DomainExit(Environment* env, v8::Local<v8::Object> object) { | |
|
||
|
||
static bool PreCallbackExecution(AsyncWrap* wrap, bool run_domain_cbs) { | ||
switch (wrap->provider_type()) { | ||
#define V(PROVIDER) \ | ||
case AsyncWrap::PROVIDER_ ## PROVIDER: \ | ||
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("node", #PROVIDER " cb", \ | ||
static_cast<int64_t>(wrap->get_id())); \ | ||
break; | ||
NODE_ASYNC_PROVIDER_TYPES(V) | ||
#undef V | ||
} | ||
|
||
if (wrap->env()->using_domains() && run_domain_cbs) { | ||
bool is_disposed = DomainEnter(wrap->env(), wrap->object()); | ||
if (is_disposed) | ||
|
@@ -249,6 +259,16 @@ bool AsyncWrap::EmitBefore(Environment* env, double async_id) { | |
|
||
|
||
static bool PostCallbackExecution(AsyncWrap* wrap, bool run_domain_cbs) { | ||
switch (wrap->provider_type()) { | ||
#define V(PROVIDER) \ | ||
case AsyncWrap::PROVIDER_ ## PROVIDER: \ | ||
TRACE_EVENT_NESTABLE_ASYNC_END0("node", #PROVIDER " cb", \ | ||
static_cast<int64_t>(wrap->get_id())); \ | ||
break; | ||
NODE_ASYNC_PROVIDER_TYPES(V) | ||
#undef V | ||
} | ||
|
||
if (!AsyncWrap::EmitAfter(wrap->env(), wrap->get_id())) | ||
return false; | ||
|
||
|
@@ -617,10 +637,29 @@ AsyncWrap::AsyncWrap(Environment* env, | |
|
||
// Use AsyncReset() call to execute the init() callbacks. | ||
AsyncReset(silent); | ||
|
||
switch (provider_type()) { | ||
#define V(PROVIDER) \ | ||
case PROVIDER_ ## PROVIDER: \ | ||
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("node", #PROVIDER, \ | ||
static_cast<int64_t>(get_id())); \ | ||
break; | ||
NODE_ASYNC_PROVIDER_TYPES(V) | ||
#undef V | ||
} | ||
} | ||
|
||
|
||
AsyncWrap::~AsyncWrap() { | ||
switch (provider_type()) { | ||
#define V(PROVIDER) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are places where this will fail:
Neither of these would be a blocker for me landing this PR. Just note that (1) will not have the same async ids going in as it does going out. Also I would suggest we exclude There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure I understand, currently, no trace events will be reported for httpparser or the js side of timers. Is there a chance for any malformed events (start without end, etc)? Why should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You will get an When the The The |
||
case PROVIDER_ ## PROVIDER: \ | ||
TRACE_EVENT_NESTABLE_ASYNC_END0("node", #PROVIDER, \ | ||
static_cast<int64_t>(get_id())); \ | ||
break; | ||
NODE_ASYNC_PROVIDER_TYPES(V) | ||
#undef V | ||
} | ||
PushBackDestroyId(env(), get_id()); | ||
} | ||
|
||
|
@@ -774,6 +813,9 @@ async_context EmitAsyncInit(Isolate* isolate, | |
trigger_async_id // trigger_async_id_ | ||
}; | ||
|
||
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("node", "custom_event", | ||
static_cast<int64_t>(context.async_id)); | ||
|
||
// Run init hooks | ||
Local<String> type = | ||
String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized) | ||
|
@@ -785,6 +827,8 @@ async_context EmitAsyncInit(Isolate* isolate, | |
} | ||
|
||
void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) { | ||
TRACE_EVENT_NESTABLE_ASYNC_END0("node", "custom_event", | ||
static_cast<int64_t>(asyncContext.async_id)); | ||
PushBackDestroyId(Environment::GetCurrent(isolate), asyncContext.async_id); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to place these
switch
statements into a conditional that checks whether trace events are enabled?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could expose a check for whether trace events are enabled if necessary but each of these macros starts by running such a check and I would guess the overhead of the switch alone would be minimal.