async_hooks: add getActiveResources (prototype)
Prototype of a new getActiveResources()
API for async_hooks
.
Returns an object map of { <id>: <resource> }
, and differs slightly from getActiveHandles()
. (The old API used to return the handle owner property for some reason.)
Currently, it works for all async_hooks resources except nextTick-s, which are probably not useful to expose in this way.
Reason being that nextTick-s almost always have no interesting information attached, and exist in async_hooks almost exclusively for continuation purposes. The same thing can pretty much be said for Immediate-s too, and I wouldn't be opposed to removing them from this.
As an alternative to not producing nextTicks, I think something along the lines of getActiveResources(async_type_mask)
could be acceptable.
There are two primary reasons for why this might be useful compared to async_hooks
, and why _getActiveHandles()
is still useful today.
- Handle access. This bypasses the tricky problem of somehow storing a weak reference to handles so that you can access them up to
destroy()
but also not prevent GC. - Performance. It is unnecessary to do tracking on each resource allocation, which requires boundary crossing for C++ resources on each call and also dealing with the way-too-plentiful nextTicks.
The root why of this is that some tools (such as N|Solid) like to have access to this kind of thing so we can inspect what kind of resources are active in a live application at any arbitrary point in time.
@nodejs/diagnostics @mike-kaufman @gpotter2
Supersedes https://github.com/nodejs/node/pull/21102 & probably also https://github.com/nodejs/node/pull/21313
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines