Skip to content

Commit

Permalink
src: register external references of dtrace for snapshot
Browse files Browse the repository at this point in the history
PR-URL: #39961
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
joyeecheung committed Sep 6, 2021
1 parent 80785f6 commit ed13228
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
31 changes: 22 additions & 9 deletions src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"

#include <cstring>

Expand Down Expand Up @@ -288,23 +289,35 @@ void InitDTrace(Environment* env) {
}, env);
}

#define NODE_PROBES(V) \
V(DTRACE_NET_SERVER_CONNECTION) \
V(DTRACE_NET_STREAM_END) \
V(DTRACE_HTTP_SERVER_REQUEST) \
V(DTRACE_HTTP_SERVER_RESPONSE) \
V(DTRACE_HTTP_CLIENT_REQUEST) \
V(DTRACE_HTTP_CLIENT_RESPONSE)

void InitializeDTrace(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);

#if defined HAVE_DTRACE || defined HAVE_ETW
# define NODE_PROBE(name) env->SetMethod(target, #name, name);
NODE_PROBE(DTRACE_NET_SERVER_CONNECTION)
NODE_PROBE(DTRACE_NET_STREAM_END)
NODE_PROBE(DTRACE_HTTP_SERVER_REQUEST)
NODE_PROBE(DTRACE_HTTP_SERVER_RESPONSE)
NODE_PROBE(DTRACE_HTTP_CLIENT_REQUEST)
NODE_PROBE(DTRACE_HTTP_CLIENT_RESPONSE)
# undef NODE_PROBE
#endif
#define V(name) env->SetMethod(target, #name, name);
NODE_PROBES(V)
#undef V
#endif // defined HAVE_DTRACE || defined HAVE_ETW
}

void RegisterDtraceExternalReferences(ExternalReferenceRegistry* registry) {
#if defined HAVE_DTRACE || defined HAVE_ETW
#define V(name) registry->Register(name);
NODE_PROBES(V)
#undef V
#endif // defined HAVE_DTRACE || defined HAVE_ETW
}

} // namespace node
NODE_MODULE_CONTEXT_AWARE_INTERNAL(dtrace, node::InitializeDTrace)
NODE_MODULE_EXTERNAL_REFERENCE(dtrace, node::RegisterDtraceExternalReferences)
9 changes: 8 additions & 1 deletion src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ class ExternalReferenceRegistry {
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
#endif // HAVE_INSPECTOR

#if HAVE_DTRACE || HAVE_ETW
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) V(dtrace)
#else
#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)
#endif

#define EXTERNAL_REFERENCE_BINDING_LIST(V) \
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \
EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) \
EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V)

} // namespace node

Expand Down

0 comments on commit ed13228

Please sign in to comment.