mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-06 23:52:44 +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:
@@ -583,6 +583,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,
|
||||
@@ -592,8 +595,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
|
||||
@@ -637,7 +638,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))
|
||||
@@ -663,7 +664,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
|
||||
@@ -722,6 +725,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))
|
||||
@@ -793,13 +797,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]
|
||||
@@ -807,7 +820,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 [],
|
||||
@@ -1014,8 +1027,7 @@ def main(obj_paths, *,
|
||||
fields=fields,
|
||||
**args)
|
||||
if args.get('output_json'):
|
||||
write_csv(args['output_json'], CodeResult, results,
|
||||
json=True,
|
||||
write_csv(args['output_json'], CodeResult, results, json=True,
|
||||
by=by,
|
||||
fields=fields,
|
||||
**args)
|
||||
|
||||
Reference in New Issue
Block a user