mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-07 08:02:46 +00:00
scripts: Added -l/--labels to csv.py
This gives csv.py access to a hidden feature in our table renderer used by some of the other scripts: fields that affect by-field grouping, but aren't actually printed. For example, this prevents summing same named functions in different files, but only shows the function name in the table render: $ ./scripts/csv.py lfs.code.csv -bfile -bfunction -lfunction function size lfs_alloc 398 lfs_alloc_discard 31 lfs_alloc_findfree 77 ... This is especially useful when enumerating results. For example, this prevents any summing without extra table noise: $ ./scripts/csv.py lfs.code.csv -i -bfunction -fsize -lfunction function size lfs_alloc 398 lfs_alloc_discard 31 lfs_alloc_findfree 77 ... I also tweaked -b/--by field defaults a bit to account to enumerate/label fields a bit better.
This commit is contained in:
@@ -945,6 +945,9 @@ def table(Result, results, diff_results=None, *,
|
||||
by=None,
|
||||
fields=None,
|
||||
sort=None,
|
||||
labels=None,
|
||||
depth=1,
|
||||
hot=None,
|
||||
diff=None,
|
||||
percent=None,
|
||||
all=False,
|
||||
@@ -954,8 +957,6 @@ def table(Result, results, diff_results=None, *,
|
||||
no_total=False,
|
||||
small_table=False,
|
||||
summary=False,
|
||||
depth=1,
|
||||
hot=None,
|
||||
**_):
|
||||
import builtins
|
||||
all_, all = all, builtins.all
|
||||
@@ -999,7 +1000,7 @@ def table(Result, results, diff_results=None, *,
|
||||
# header
|
||||
if not no_header:
|
||||
header = ['%s%s' % (
|
||||
','.join(by),
|
||||
','.join(labels if labels is not None else by),
|
||||
' (%d added, %d removed)' % (
|
||||
sum(1 for n in table if n not in diff_table),
|
||||
sum(1 for n in diff_table if n not in table))
|
||||
@@ -1025,7 +1026,9 @@ def table(Result, results, diff_results=None, *,
|
||||
|
||||
# entry helper
|
||||
def table_entry(name, r, diff_r=None):
|
||||
# prepend name
|
||||
entry = [name]
|
||||
|
||||
# normal entry?
|
||||
if ((compare is None or r == compare_r)
|
||||
and not percent
|
||||
@@ -1084,6 +1087,7 @@ def table(Result, results, diff_results=None, *,
|
||||
types[k].ratio(
|
||||
getattr(r, k, None),
|
||||
getattr(diff_r, k, None)))))
|
||||
|
||||
# append any notes
|
||||
if hasattr(Result, '_notes') and r is not None:
|
||||
notes = sorted(getattr(r, Result._notes))
|
||||
@@ -1155,13 +1159,22 @@ def table(Result, results, diff_results=None, *,
|
||||
# and finally by name (diffs may be missing results)
|
||||
n))
|
||||
|
||||
for i, n in enumerate(names_):
|
||||
for i, name in enumerate(names_):
|
||||
# find comparable results
|
||||
r = table_.get(n)
|
||||
diff_r = diff_table_.get(n)
|
||||
r = table_.get(name)
|
||||
diff_r = diff_table_.get(name)
|
||||
|
||||
# figure out a good label
|
||||
if labels is not None:
|
||||
label = ','.join(str(getattr(r, k)
|
||||
if getattr(r, k) is not None
|
||||
else '')
|
||||
for k in labels)
|
||||
else:
|
||||
label = name
|
||||
|
||||
# build line
|
||||
line = table_entry(n, r, diff_r)
|
||||
line = table_entry(label, r, diff_r)
|
||||
|
||||
# add prefixes
|
||||
line = [x if isinstance(x, tuple) else (x, []) for x in line]
|
||||
@@ -1169,7 +1182,7 @@ def table(Result, results, diff_results=None, *,
|
||||
lines.append(line)
|
||||
|
||||
# recurse?
|
||||
if n in table_ and depth_ > 1:
|
||||
if name in table_ and depth_ > 1:
|
||||
table_recurse(
|
||||
getattr(r, Result._children),
|
||||
getattr(diff_r, Result._children, None) or [],
|
||||
@@ -1503,8 +1516,7 @@ def report(perf_paths, *,
|
||||
depth=depth,
|
||||
**args)
|
||||
if args.get('output_json'):
|
||||
write_csv(args['output_json'], PerfResult, results,
|
||||
json=True,
|
||||
write_csv(args['output_json'], PerfResult, results, json=True,
|
||||
by=by,
|
||||
fields=fields,
|
||||
depth=depth,
|
||||
@@ -1539,12 +1551,13 @@ def report(perf_paths, *,
|
||||
else:
|
||||
# print table
|
||||
table(PerfResult, results, diff_results,
|
||||
by=by if by is not None else ['function'],
|
||||
by=by if by is not None else ['z', 'function'],
|
||||
fields=fields if fields is not None
|
||||
else ['cycles'] if not branches and not caches
|
||||
else ['bmisses', 'branches'] if branches
|
||||
else ['cmisses', 'caches'],
|
||||
sort=sort,
|
||||
labels=by if by is not None else ['function'],
|
||||
depth=depth,
|
||||
**args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user