schedstat: add --json flag#9
Merged
Merged
Conversation
Convert the previously streaming print* functions into collect* functions that populate a typed Report struct hierarchy. Each section type carries a String() method that reproduces the legacy plaintext output verbatim, so existing golden tests pass byte-identical. The Report struct is the single source of truth for both the plaintext view (today) and a future JSON view: section-level structs use JSON-friendly types (raw nanoseconds, slices) and json struct tags so encoding/json can serialize the whole report directly. analyze() still streams text section-by-section as each collect* returns, preserving intra-trace progress on early termination. No user-visible behavior change. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
--json emits the same analysis as a JSON object, with all durations as raw nanoseconds and disabled sections omitted. Multiple trace files produce NDJSON (one object per line), so the output streams cleanly through `jq`. The flag is rejected with --sql (interactive shell). With --keep-db the "DuckDB file: ..." footer is redirected to stderr so stdout stays valid NDJSON. Golden test coverage extended: each .bin trace now has both a .txt and .json golden file, regenerated together via `go test -rewrite`. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Multi-trace runs now fan out across GOMAXPROCS/4 workers. Each file's output is buffered in its own slot and emitted in input order via a per-slot done channel: as soon as the next-in-line file finishes, its output streams to stdout — no waiting for the whole batch. --sql is incompatible with the buffered/parallel path (it ends in syscall.Exec). Reject when combined with multiple files; single-file --sql still runs sequentially through runOne. printSchemaInfo replaced with schemaInfo (returns string) so footer text goes through the per-file writer instead of os.Stdout directly. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
The previous parallel implementation ran the dispatcher and emitter on the same goroutine: dispatcher first, emitter second. With a long file list the dispatcher's `sem <-` blocks every time the in-flight count hits the concurrency cap, so the emitter never starts until near the end of the run — even file 0's output stays buffered for minutes. Move the dispatch loop to its own goroutine so the emitter can begin draining results[0] immediately, streaming each file in input order as soon as it is ready. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
GOMAXPROCS/4 left CPU idle (~70%) on multi-trace runs. Default to full GOMAXPROCS, and expose --concurrency for tuning (0 = GOMAXPROCS). Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
CI on linux produced golden mismatches against the darwin-generated JSON because float64 results from DuckDB aggregates differ at the ULP level across platforms (e.g. p99_ns 1760564.48 vs 1760564.4800000002). Fix: - Store all duration-ns fields as int64. Truncation is invisible in the text output (fmtDuration formats microsecond+ values), and removes the cross-platform precision noise from JSON. - Round GC latency comparison ratios to 6 decimals; the text view shows one decimal so the rounding is invisible there too. Goldens regenerated; text output is unchanged. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
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.
Summary
analyze()to populate typedReportstruct hierarchy. Each section gets aString()that reproduces legacy plaintext output verbatim. Existing golden tests pass byte-identical.--jsonflag. Emits one JSON object per trace, NDJSON across multiple traces. Durations as raw nanoseconds. Disabled sections omitted.--json+--sqlrejected. With--keep-db, footer goes to stderr so stdout stays valid NDJSON..bintrace now has both.txtand.jsongolden, regenerated together viago test -rewrite.Two commits, reviewable independently:
Test plan