Repository navigation
Scope time range options per command and bound profile bucket count - #12
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
Scoping the time-range options per command and rejecting them elsewhere will be a lot clearer for agents than silently ignoring them. The extracted loadTraceWithTimeRange helper also cuts down a lot of repetition.
| function positiveDuration(flag: string): (value: unknown) => number { | ||
| return (value) => { | ||
| const ms = parseTimeValue(String(value)); | ||
| if (ms <= 0) { | ||
| throw new Error(`--${flag} must be a duration > 0. Received: ${value}`); | ||
| } | ||
| return ms; | ||
| }; |
There was a problem hiding this comment.
> 0 still lets through durations that give an empty result, which is the case this PR is trying to remove. extractProfile advances with currentEnd = Math.min(endMs, round(currentStart + bucketSizeMs)), and round defaults to 2 decimals. So --bucket 1us (0.001 ms) or --bucket 0.004 makes currentEnd === currentStart on the first iteration. It breaks out and returns buckets: [] with exit 0.
At the other end, --bucket 10us is accepted and on a 10 s trace that means ~1M BottomUpRootNode builds. Rejecting anything below 0.01 ms (or whatever resolution round uses) would close the empty-result case. A cap on totalRangeMs / bucket with a clear error might be worth adding too. I worked this out from reading profile.ts and haven't run it.
There was a problem hiding this comment.
Confirmed by running it: --bucket 1us and --bucket 0.004 returned buckets: [] with exit 0, and --bucket 10us returned 16000 buckets on the 160 ms test fixture. Fixed in 2e829a0:
--bucketbelow0.01msfails with--bucket must be a duration >= 0.01ms. Received: 1us.profilefails when the range needs more than 1000 buckets and suggests the smallest valid size, for exampleBucket size 0.01ms creates 16000 buckets over 160ms. The maximum is 1000. Use a bucket size of at least 0.16ms.
|
Thanks for putting this together! Scoping A few small things I noticed while reviewing:
|
2e829a0 to
651ed0f
Compare
|
Thanks for the review! All three points are addressed, and the branch is rebased on main (conflicts with #20 resolved).
|
651ed0f to
0386d50
Compare
|
I rebuilt this PR on top of main after #16 and #17 landed. Those PRs already validate result limits and the minimum bucket size, and What remains is the per-command scoping of |
`--time-range` and `--absolute-timestamps` are declared only on the commands that use them, so `threads` and `scan` reject both and `diff` rejects `--time-range` instead of ignoring them. `diff` keeps `--absolute-timestamps` for `--window-a` and `--window-b`, and command help only lists the options each command supports. `tasks --min-duration` rejects negative and non-numeric values. `extractProfile()` enforces a 0.01ms minimum and a maximum of 1000 buckets, and rounds the bucket size before the check so it matches the loop step. Before, `--bucket 0.01ms` created 16,000 buckets on a 160ms trace.
0386d50 to
11e7f21
Compare
--time-rangeand--absolute-timestampsare declared only on the commands that use them.threadsandscanreject both, anddiffrejects--time-rangeinstead of ignoring it.diffkeeps--absolute-timestampsfor its--window-aand--window-bvalues. Command help only lists the options each command supports.tasks --min-durationrejects negative and non-numeric values. An empty value (--min-duration=) still becomes 0, because yargs converts it beforecoerceruns, like the other number options.extractProfile()rejects bucket sizes below 0.01ms and more than 1000 buckets, and the error shows the smallest valid bucket size. The bucket size is rounded before the check, so the check matches the rounded loop step. Before,--bucket 0.01mscreated 16,000 buckets on the 160ms fixture, and a 10s trace would create 1,000,000.Tests cover each rejected option, the bucket limits, the rounded bucket size and the exact 1000-bucket boundary. Verified with
npm run check,npm run build,npm testand the built CLI, including--time-rangeand--absolute-timestampson every command that declares them.