scripts: csv.py: Added explicit z field, reusing -Z/--children

In an effort to move away from magic usage of -i/--enumerate, this adds
an explicit z field for differentiating -r/--hot results (and for normal
recursive results).

Instead of trying to think of a new flag to control this, this just
piggybacks on -Z/--children, which now accepts a tuple:

- ./scripts/csv.py -z3 -Z
- ./scripts/csv.py -z3 -Zchildren
- ./scripts/csv.py -z3 -Zz,children

The only tricky bit was needing to insert z in front of the by fields,
otherwise it was mostly a simplification from the enumerate mess.

Another positive side-effect: -r/--hot (and -z/--depth) now implies
-Zz,children, removing the annoying/confusing behavior of hotify folding
results by default.
This commit is contained in:
Christopher Haster
2026-01-23 01:00:22 -06:00
parent 078a1fb4c6
commit ac338e66f0
6 changed files with 71 additions and 65 deletions
+6 -9
View File
@@ -167,6 +167,7 @@ class PerfResult(co.namedtuple('PerfResult', [
'cycles': CsvInt,
'bmisses': CsvInt, 'branches': CsvInt,
'cmisses': CsvInt, 'caches': CsvInt}
_z = 'z'
_children = 'children'
__slots__ = ()
@@ -913,14 +914,14 @@ def fold(Result, results, *,
return folded
def hotify(Result, results, *,
enumerates=None,
depth=1,
hot=None,
**_):
# note! hotifying risks confusion if you don't enumerate/have a
# z field, since it will allow folding across recursive boundaries
# note! hotifying risks confusion if you don't have a z field, since
# it will allow folding across recursive boundaries
# hotify only makes sense for recursive results
assert hasattr(Result, '_z')
assert hasattr(Result, '_children')
results_ = []
@@ -942,12 +943,8 @@ def hotify(Result, results, *,
for k_ in ([k] if k else Result._sort)))
for k, reverse in it.chain(hot, [(None, False)])))
hot_.append(r._replace(**(
# enumerate?
({e: len(hot_) for e in enumerates}
if enumerates is not None
else {})
| {Result._children: []})))
# flatten, dropping children
hot_.append(r._replace(**{Result._children: []}))
# recurse?
if depth_ > 1: