debugger: add edit-free runtime expression probes to node inspect#62713
debugger: add edit-free runtime expression probes to node inspect#62713nodejs-github-bot merged 6 commits intonodejs:mainfrom
node inspect#62713Conversation
|
cc @nodejs/inspector @nodejs/diagnostics |
3608c5d to
b0ec4b2
Compare
Add a non-interactive probe mode to `node inspect` for inspecting
runtime values in a run-to-completion application. This allows
users to perform printf-style debugging without having to modify
the application code and clean up afterwards, it also supports
structured output to be consumed by tools.
Probe mode launches the application, sets one or more source
breakpoints, evaluates one expression at each hit, and prints a
single text or JSON report when execution ends.
Interface:
node inspect [--json] [--preview] [--timeout=<ms>] [--port=<port>]
--probe <file>:<line>[:<col>] --expr <expr> ...
[--] <script> [args...]
Example:
```js
// cli.js
let maxRSS = 0;
for (let i = 0; i < 2; i++) {
const { rss } = process.memoryUsage();
maxRSS = Math.max(maxRSS, rss);
}
```
```
$ node inspect --probe cli.js:5 --expr 'rss' cli.js
Hit 1 at cli.js:5
rss = 54935552
Hit 2 at cli.js:5
rss = 55083008
Completed
```
(Prettified JSON to fit in commit message restrictions).
```js
$ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
{"v":1,"probes":[{"expr":"rss","target":["cli.js",5]}],
"results":[
{"probe":0,"event":"hit","hit":1,
"result":{"type":"number","value":55443456,
"description":"55443456"}},
{"probe":0,"event":"hit","hit":2,
"result":{"type":"number","value":55574528,
"description":"55574528"}},
{"event":"completed"}]}
```
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62713 +/- ##
==========================================
- Coverage 89.81% 89.65% -0.17%
==========================================
Files 699 706 +7
Lines 216379 219072 +2693
Branches 41366 41960 +594
==========================================
+ Hits 194340 196407 +2067
- Misses 14139 14573 +434
- Partials 7900 8092 +192
🚀 New features to boost your workflow:
|
|
This is really cool! Have we considered to use new line delimited JSON instead of a big JSON array as the primary output format? |
I feel that since we already have the text format for more readable output, the JSON format can be a bit more condensed since it's meant to be consumed by tools anyway? Using new-line delimited JSON would kind of force tools to be able to deal with that instead of just parsing it directly, and also not sure where the version field should go in that case, if we want to reuse the probes (because many hits can come from the same probe) they have to maintain some states to collect the probes first then collect the events, which means the tools all have to add specialized state management to parse it instead of just using whatever JSON parser they have. |
I was thinking about this less from a human readable perspective and more from an "incremental parsing by tools". But that can also be done by a (slightly more complicated) parser in the consuming tool. Starting with one big JSON blob is perfectly reasonable I think. The format flag is open to extension if anybody ever asks for something more incremental. 👍 |
|
@hybrist Thanks for the review, yeah I think we can leave an incremental output (or technically streaming output?) as a follow-up if it turns out to be useful. I fixed the linter issue, can you re-approve again? Thanks! |
…s to `node inspect`
…n probes to `node inspect`
|
@legendecas I added a TODO to defer the error tests to avoid bloating the diff here and moved the probe code to a new file (+ a new file for shared helpers). Can you take a look again? Thanks! |
…n probes to `node inspect`
|
Yikes. Moving the class to a separate file somehow triggers a pre-existing V8 bug that breaks the snapshot reproducibility test with x64 Linux shared library build (I suspect it's caused by the transition array search bug in my backlog, or some padding mismatches lurking in V8, but I can't reproduce it locally). It seems to be an overkill to block this PR on a pre-existing unrelated bug just for a style preference, so I reverted the split and added a TODO instead. |
|
The CI was a bit flaky with no obvious patterns. Some flakes are unrelated, the related ones appear to point to the pre-existing issue that the inspector can crash in some edge cases when the debugee terminates too quickly (e.g. see #62765 and #57606). On the bright side this might mean that we may now have a few more reliable reproductions for these issues. I am going to land it for now and see how it goes - if they end up being problematic we can mark the flaky ones as flaky for now until we fix the root cause in V8. On a side note I realized that we don't yet have https://chromium-review.googlesource.com/c/v8/v8/+/7723678 on the main branch, which might've fixed the snapshot reliability issue exposed earlier by the class split (this was being marked as skipped in #62808 as it also reproduced in other PRs). The patch would come in with the V8 14.6 update, so we might be able to address the class split TODO after the V8 upgrade is in. |
|
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
|
Landed in a79e224 |
Add a non-interactive probe mode to
node inspectfor inspecting runtime values in a run-to-completion application. This allows users to perform printf-style debugging without having to modify the application code and clean up afterwards, it also supports structured output to be consumed by tools.This is proposed to be experimental first, so that we can iterate on the interface. There are a few features that would be nice to have but better left for follow-ups to avoid bloating the diff:
In this patch, probe mode launches the application, sets one or more source breakpoints, evaluates one expression at each hit, and prints a single text or JSON report containing all the evaluated values when execution ends.
Interface:
For example, to inspect a string in an application without modifying the source:
(Prettified JSON to fit in commit message restrictions).