inspector: add --cond to node inspect probe mode#64328
Open
joyeecheung wants to merge 1 commit into
Open
Conversation
On a hot path, the probe can record every hit and require
filtering afterwards. This patch adds a per-probe `--cond <expr>`
option that allows limiting the hit to only when the expression
is truthy at the probe location. V8 evaluates it as the breakpoint's
native condition, so the target is not paused when it does not hold,
and a condition that throws is treated as false. Since in CDP,
a location can only carry one breakpoint per URL pattern,
probes sharing a location must share one condition (or none).
Conflicting conditions are rejected.
Example:
```js
// app.js
let total = 0;
for (let i = 0; i < 10; i++) {
total += i; // line 4
}
```
```
$ out/Release/node inspect --probe app.js:4 --expr 'total' \
--cond 'i % 3 === 0' app.js
```
```
Hit 1 at file:///path/to/app.js:3:3
total = 0
Hit 2 at file:///path/to/app.js:3:3
total = 3
Hit 3 at file:///path/to/app.js:3:3
total = 15
Hit 4 at file:///path/to/app.js:3:3
total = 36
Completed
```
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
This comment was marked as outdated.
This comment was marked as outdated.
11 tasks
Collaborator
jasnell
reviewed
Jul 7, 2026
Comment on lines
+443
to
+444
| if (conditionByLocation.has(key)) { | ||
| if (conditionByLocation.get(key) !== condition) { |
Member
There was a problem hiding this comment.
I'm assuming this is structured into separate has/get checks because undefined is a legitimate value and differentiating between no-value and undefined is necessary? If so, a comment here would be helpful.
jasnell
reviewed
Jul 7, 2026
| @@ -321,6 +331,8 @@ $ node inspect --probe app.js:10 --expr "user" | |||
| --json --preview -- --no-warnings app.js --arg-for-app=foo | |||
| ``` | |||
|
|
|||
| <!-- TODO(joyeecheung): add more examples for different options --> | |||
Member
There was a problem hiding this comment.
An example that shows --cond being used would be good :-)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a hot path, the probe can record every hit and require filtering afterwards. This patch adds a per-probe
--cond <expr>option that allows limiting the hit to only when the expression is truthy at the probe location. V8 evaluates it as the breakpoint's native condition, so the target is not paused when it does not hold, and a condition that throws is treated as false. Since in CDP, a location can only carry one breakpoint per URL pattern, probes sharing a location must share one condition (or none). Conflicting conditions are rejected.Example:
Refs: #63646