Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Provide getReport API to return the contents of node-report. - #48

Closed
hhellyer wants to merge 2 commits into
nodejs:masterfrom
hhellyer:stream_output
Closed

Provide getReport API to return the contents of node-report.#48
hhellyer wants to merge 2 commits into
nodejs:masterfrom
hhellyer:stream_output

Conversation

@hhellyer

Copy link
Copy Markdown
Contributor

These changes add a new function to the node-report API - getReport() to address issue #39. The getReport() function returns the string contents of node report to the caller instead of writing it to a file and returning the file name. This makes it easier for other modules to build on node-report.

This is limited to non-fatal uses of node-report, there is no event listener API. A Node.js program can’t listen on a fatal event callback and get the contents of a node-report as at that point Node.js is broken. Similarly the output cannot be streamed, it is returned as one object representing a snapshot of a point in time, as processing the data via a callback while it was still being gathered would change the state of the process we are reporting on.

To implement this I switched from using fprintf for output to C++ streams. This makes it trivial to switch between using a file stream or a string stream for output and the getReport path just passing a different stream object to the triggerReport path. There were two places in node-report where we passed our file stream to internal functions for them to write to.

  • In one case in the stack walking code there is no other suitable API so we use a temporary file and read it back in.
  • In another location where were were walking the libuv event loop via uv_print_all_handles. I have switched API’s to uv_walk, which allows us to look directly at each handle.
    This loses the ability to see internal handles, however there only appear to be a couple of those and they are probably uninteresting. We gain the ability to get hold of the real uv_handle_t structures on the event loop and inspect them further which we can exploit in a future enhancement to give the user information about things like tcp connections and write queue sizes. (Anything publicly available via the libuv public API’s.) That would probably have been of sufficient benefit to switch API’s anyway.

This change also fixes a bug where when node-report always closed the handle it was writing to, even if it was using stderr/stdout.

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants