feat: add CSV/JSON structured output to nvlink_monitor - #4
Merged
Conversation
Add `-f, --format text|csv|json` to nvlink_monitor so its output can be consumed by scripts for post-analysis (e.g. diffing against nvlink_bw_test throughput, computing steady-state averages, plotting). Formats: - text (default, unchanged): human-readable per-GPU / per-link lines. - csv: header `timestamp,interval_s,gpu_id,link_id,tx_gibps,rx_gibps`, one row per (gpu, link) per sample, plus a per-GPU "total" row (link_id=total) so a GPU with no active links still appears. Header is emitted once and reused for subsequent samples. - json: JSONL -- one self-contained JSON object per sample with per-GPU totals and per-link arrays. Streaming-friendly for continuous mode. Status/diagnostic messages (GPU discovery, "Starting continuous monitoring", SCHED_FIFO notice, "Received stop signal", warnings) are now written to stderr instead of stdout, so stdout contains only data. This follows Unix convention and keeps CSV/JSON output clean when piping or redirecting stdout (e.g. `nvlink_monitor -f csv 2>/dev/null | ...`). In text mode the terminal UX is unchanged (stdout and stderr both reach the terminal). --verbose only affects the text path; CSV/JSON always emit per-link data since structured output is already "detailed". Tests: 66 pass (was 59; +7 for --format parsing: default text, explicit text, -f csv, --format csv, --format json, invalid rejected, missing value rejected; extended CombinedOptions to cover --format). make check-format clean. make monitor builds with -Wall -Wextra, no warnings. Verified end-to-end on an 8x H20 system that both CSV and JSON single-mode samples produce well-formed output with status on stderr. Signed-off-by: staryxchen <staryxchen@tencent.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
First of the feature-enhancement batch. Adds machine-readable output to
nvlink_monitorvia-f, --format text|csv|json, so its output can be consumed by scripts for post-analysis (diffing againstnvlink_bw_testthroughput, computing steady-state averages, plotting). This was the highest-value item in the earlier optimization review.Changes
New
--formatflag (monitor/arg_parser.{h,cpp})OutputFormatenum (Text/CSV/JSON), defaultText.-f/--format text|csv|json; invalid values and missing values rejected withok=false.Formatters (
monitor/nvlink_monitor.{h,cpp})formatCsvResult): headertimestamp,interval_s,gpu_id,link_id,tx_gibps,rx_gibpsemitted once, then one row per (gpu, link) per sample, plus a per-GPUtotalrow (link_id=total) so a GPU with no active links still appears. ISO 8601 timestamps (no spaces, no quoting needed).formatJsonResult): JSONL — one self-contained JSON object per sample with per-GPU totals and per-link arrays. Streaming-friendly for continuous mode (no array wrapper, each line parseable independently).runContinuousMonitoring/runSingleMonitoringswitches onoutputFormat.--verboseonly affects the text path; CSV/JSON always emit per-link data.OutputFormat;printHelpupdated with the new flag and examples.Status messages → stderr
All diagnostic/status output (GPU discovery, "Starting continuous monitoring", SCHED_FIFO notice, "Received stop signal", warnings) is now written to stderr instead of stdout. This follows Unix convention and keeps CSV/JSON on stdout clean when piping/redirecting:
In text mode the terminal UX is unchanged (stdout + stderr both reach the terminal).
Tests (
test/test_arg_parser.cpp)+7 tests (66 total, was 59): default text, explicit text,
-f csv,--format csv,--format json, invalid rejected, missing value rejected;CombinedOptionsextended to cover--format csv.Docs (
README.md)Documented
--formatwith CSV/JSON examples and the stderr-for-status convention.Verification
make check-format— cleanmake test— 66/66 passmake monitor— builds with-Wall -Wextra, no warningsFiles changed