scripts: csv.py: Fixed field defines hiding field renames

The issue here is quite nuanced, but becomes a problem when you want to
both:

1. Filter results by a given field: -Dmeas=write
2. Output a new value for that field: -bmeas='"write+amor"'

If you didn't guess from the example, this comes up often in scripts
dealing with bench results, where we often find ourselves wanting to
append/merge modified results based on the raw measurements.

Fortunately the fix is relatively easy: We already filter by defines
in our collect function, so we don't really need to filter by defines
again when folding.

Folding occurs after expr evaluation, but collect occurs before, so this
limits filtering to the input fields _before_ expr evaluation.

This does mean we no longer filter on the output of exprs, but I don't
know if such behavior was ever intentionally desired. Worst case it can
be emulated by stacking multiple csv.py calls, which may be annoying,
but is at least well-intentioned and well-defined.

---

Note that the other result scripts, code.py, stack.py, etc, are a bit
different in that they rely on fold-time filtering for filtering
generated results. This may deserve a refactor at some point, but since
these scripts don't also evaluate exprs, it's not an immediate problem.
This commit is contained in:
Christopher Haster
2024-11-13 15:21:35 -06:00
parent 2fa968dd3f
commit 8911d44073
+2 -2
View File
@@ -1600,7 +1600,7 @@ def main(csv_paths, *,
results = results_
# fold
results = fold(Result, results, by=by, defines=defines)
results = fold(Result, results, by=by)
# sort, note that python's sort is stable
results.sort()
@@ -1640,7 +1640,7 @@ def main(csv_paths, *,
diff_results = diff_results_
# fold
diff_results = fold(Result, diff_results, by=by, defines=defines)
diff_results = fold(Result, diff_results, by=by)
# print table
if not args.get('quiet'):