Skip to content

fix: include parameter columns in CSV header when using --reference#869

Open
YoshKoz wants to merge 1 commit intosharkdp:masterfrom
YoshKoz:fix/csv-reference-parameter-columns
Open

fix: include parameter columns in CSV header when using --reference#869
YoshKoz wants to merge 1 commit intosharkdp:masterfrom
YoshKoz:fix/csv-reference-parameter-columns

Conversation

@YoshKoz
Copy link
Copy Markdown

@YoshKoz YoshKoz commented Apr 19, 2026

Fixes #852

Problem

When --reference and --parameter-scan are combined, the CSV export fails:

Error: CSV error: found record with 9 fields, but the previous record has 8 fields

The root cause: the CSV header was built from results.first(), which is the reference command. The reference has an empty parameters map, so no parameter_* columns were written to the header. The subsequent parameterised rows have one extra field per parameter, causing a field-count mismatch.

Fix

Two changes to src/export/csv.rs:

  1. Header: find the first result that actually has parameters (results.iter().find(|r| !r.parameters.is_empty())) instead of blindly using .first().

  2. Data rows: iterate over the collected parameter names in order and look up each value with a fallback to empty string, so the reference row emits empty strings for parameter columns rather than zero fields.

Expected CSV output with --reference "sleep 1" --parameter-scan secs 2 3:

command,mean,stddev,median,user,system,min,max,parameter_secs
sleep 1,1.003,...,         ← reference: empty parameter column
sleep 2,2.001,...,2
sleep 3,3.001,...,3

A regression test (test_csv_with_reference) is included.

When --reference and --parameter-scan are combined, the reference
command has no parameters. The CSV header was built from results.first(),
which is the reference run, so no parameter_* columns were written.
The subsequent parameterised rows contained more fields, causing:

  Error: CSV error: found record with 9 fields, but the previous record has 8 fields

Fix: build the header from the first result that actually has parameters.
Also fix the per-row serialisation to emit an empty string for each
parameter column when a result (the reference) has no parameters, so
every row has the same number of fields as the header.

Adds a regression test (test_csv_with_reference) that covers this case.

Fixes sharkdp#852

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSV error when using parameters with --reference

1 participant