active-handles

Prints out information about the process's active handles, including function source and location.

Usage no npm install needed!

<script type="module">
  import activeHandles from 'https://cdn.skypack.dev/active-handles';
</script>

README

active-handles build status

Prints out information about the process's active handles, including function source and location.

var activeHandles = require('active-handles');

// run your program, launch a server, call setTimeout or similar
// in order to create some handles and then call the below

activeHandles.print();

assets/mixed.png

Shows handles of multiple types created via examples/mixed.js

Installation

npm install active-handles

Caveats

For any version <= v1.6.2 the setInterval function has to be hooked in order for this to work for setInterval created handles.

In order to do that call activeHandles.hookSetInterval() before any calls to setInterval occurr. This is demonstrated in this example.

Handles of net and http modules log handles from inside core instead of your handle, leaving you to hunt down where you created these connections.

API

activeHandles(options) → {Array.<Object>}

Gathers information about all currently active handles. Active handles are obtained via process._getActiveHandles and location and name of each is resolved.

Parameters:
Name Type Argument Description
options Object
opts.handles Array.<Object>= <optional>

handles to get info for (default: process._getActiveHandles())

opts.source Boolean <optional>

include source (default: true), included either way if highlight=true

opts.highlight Boolean <optional>

include highlighted source (default: true)

opts.attachHandle Boolean <optional>

attaches inspected handle for further inspection (default: false)

Source:
Returns:
  • handles each with the following properties

    Type
    Array.<Object>
  • handle.msecs timeout specified for the handle

    Type
    Number
  • handle.fn the handle itself

    Type
    function
  • handle.name the name of the function, for anonymous functions this is the name it was assigned to

    Type
    String
  • handle.anonymous true if the function was anonymous

    Type
    Boolean
  • handle.source the raw function source

    Type
    String
  • handle.highlighted the highlighted source

    Type
    String
  • handle.location location information about the handle

    Type
    Object
  • handle.location.file full path to the file in which the handle was defined

    Type
    String
  • handle.location.line line where the handle was defined

    Type
    Number
  • handle.location.column column where the handle was defined

    Type
    Number
  • handle.location.inferredName name that is used when function declaration is anonymous

    Type
    String

activeHandles::hookSetInterval()

Hooks setInterval calls in order to expose the passed handle. NOTE: not needed in io.js >=v1.6.2 and will not hook for those versions.

The handle is wrapped. In older node versions it is not exposed. The hooked version of setInterval will expose the wrapped callback so its information can be retrieved later.

Source:

activeHandles::print(options)

Convenience function that first calls @see activeHandles and prints the information to stdout.

Parameters:
Name Type Argument Description
options Object
opts.highlight Boolean <optional>

print highlighted source (default: true)

Source:

generated with docme

core

A core module which depends only on function-origin can be used. It behaves exactly like the main module except that it doesn't merge opts with default options and provides no highlighting even if highlight is set in the options. Additionally it does not include the print feature.

You can use it as follows:

var activeHandles = require('active-handles/core');
activeHandles();

License

MIT