mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-10-30 16:15:40 +01:00
Added size-sort options to scripts/code.py
Now with -s/--sort and -S/--reverse-sort for sorting the functions by size. You may wonder why add reverse-sort, since its utility doesn't seem worth the cost to implement (these are just helper scripts after all), the reason is that reverse-sort is quite useful on the command-line, where scrollback may be truncated, and you only care about the larger entries. Outside of the command-line, normal sort is prefered. Fortunately the difference is just the sign in the sort key. Note this conflicts with the short --summary flag, so that has been removed.
This commit is contained in:
12
.github/workflows/release.yml
vendored
12
.github/workflows/release.yml
vendored
@@ -84,7 +84,7 @@ jobs:
|
||||
select(.context == "results / code").description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/code.py -u results/code-thumb.csv -s | awk '
|
||||
./scripts/code.py -u results/code-thumb.csv --summary | awk '
|
||||
NR==2 {printf "Code size,%d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
|
||||
@@ -95,7 +95,7 @@ jobs:
|
||||
select(.context == "results / code (readonly)").description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/code.py -u results/code-thumb-readonly.csv -s | awk '
|
||||
./scripts/code.py -u results/code-thumb-readonly.csv --summary | awk '
|
||||
NR==2 {printf "Code size<br/>(readonly),%d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
select(.context == "results / code (threadsafe)").description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/code.py -u results/code-thumb-threadsafe.csv -s | awk '
|
||||
./scripts/code.py -u results/code-thumb-threadsafe.csv --summary | awk '
|
||||
NR==2 {printf "Code size<br/>(threadsafe),%d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
|
||||
@@ -117,7 +117,7 @@ jobs:
|
||||
select(.context == "results / code (migrate)").description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/code.py -u results/code-thumb-migrate.csv -s | awk '
|
||||
./scripts/code.py -u results/code-thumb-migrate.csv --summary | awk '
|
||||
NR==2 {printf "Code size<br/>(migrate),%d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
|
||||
@@ -128,7 +128,7 @@ jobs:
|
||||
select(.context == "results / code (error-asserts)").description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/code.py -u results/code-thumb-error-asserts.csv -s | awk '
|
||||
./scripts/code.py -u results/code-thumb-error-asserts.csv --summary | awk '
|
||||
NR==2 {printf "Code size<br/>(error-asserts),%d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
|
||||
@@ -139,7 +139,7 @@ jobs:
|
||||
select(.context == "results / coverage").description
|
||||
| capture("Coverage is (?<result>[0-9\\.]+)").result' \
|
||||
prev-results.json || echo 0)"
|
||||
./scripts/coverage.py -u results/coverage.csv -s | awk -F '[ /%]+' '
|
||||
./scripts/coverage.py -u results/coverage.csv --summary | awk -F '[ /%]+' '
|
||||
NR==2 {printf "Coverage,%.1f%% of %d lines",$4,$3}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",$4-ENVIRON["PREV"]}
|
||||
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -229,7 +229,7 @@ jobs:
|
||||
| select(.context == env.CONTEXT).description
|
||||
| capture("Code size is (?<result>[0-9]+)").result' \
|
||||
|| echo 0)"
|
||||
export DESCRIPTION="$(./scripts/code.py -u $f -s | awk '
|
||||
export DESCRIPTION="$(./scripts/code.py -u $f --summary | awk '
|
||||
NR==2 {printf "Code size is %d B",$2}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}')"
|
||||
@@ -427,7 +427,7 @@ jobs:
|
||||
| capture("Coverage is (?<result>[0-9\\.]+)").result' \
|
||||
|| echo 0)"
|
||||
export DESCRIPTION="$(
|
||||
./scripts/coverage.py -u results/coverage.csv -s | awk -F '[ /%]+' '
|
||||
./scripts/coverage.py -u results/coverage.csv --summary | awk -F '[ /%]+' '
|
||||
NR==2 {printf "Coverage is %.1f%% of %d lines",$4,$3}
|
||||
NR==2 && ENVIRON["PREV"]+0 != 0 {
|
||||
printf " (%+.1f%%)",$4-ENVIRON["PREV"]}')"
|
||||
|
||||
2
Makefile
2
Makefile
@@ -75,7 +75,7 @@ tags:
|
||||
|
||||
.PHONY: code
|
||||
code: $(OBJ)
|
||||
./scripts/code.py $^ $(CODEFLAGS)
|
||||
./scripts/code.py -S $^ $(CODEFLAGS)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
||||
@@ -126,6 +126,22 @@ def main(**args):
|
||||
diff[name] = (old, new, new-old, (new-old)/old if old else 1.0)
|
||||
return diff
|
||||
|
||||
def sorted_entries(entries):
|
||||
if args.get('size_sort'):
|
||||
return sorted(entries.items(), key=lambda x: (-x[1], x))
|
||||
elif args.get('reverse_size_sort'):
|
||||
return sorted(entries.items(), key=lambda x: (+x[1], x))
|
||||
else:
|
||||
return sorted(entries.items())
|
||||
|
||||
def sorted_diff_entries(entries):
|
||||
if args.get('size_sort'):
|
||||
return sorted(entries.items(), key=lambda x: (-x[1][1], x))
|
||||
elif args.get('reverse_size_sort'):
|
||||
return sorted(entries.items(), key=lambda x: (+x[1][1], x))
|
||||
else:
|
||||
return sorted(entries.items(), key=lambda x: (-x[1][3], x))
|
||||
|
||||
def print_header(by=''):
|
||||
if not args.get('diff'):
|
||||
print('%-36s %7s' % (by, 'size'))
|
||||
@@ -137,7 +153,7 @@ def main(**args):
|
||||
|
||||
if not args.get('diff'):
|
||||
print_header(by=by)
|
||||
for name, size in sorted(entries.items()):
|
||||
for name, size in sorted_entries(entries):
|
||||
print("%-36s %7d" % (name, size))
|
||||
else:
|
||||
prev_entries = dedup_entries(prev_results, by=by)
|
||||
@@ -145,8 +161,7 @@ def main(**args):
|
||||
print_header(by='%s (%d added, %d removed)' % (by,
|
||||
sum(1 for old, _, _, _ in diff.values() if not old),
|
||||
sum(1 for _, new, _, _ in diff.values() if not new)))
|
||||
for name, (old, new, diff, ratio) in sorted(diff.items(),
|
||||
key=lambda x: (-x[1][3], x)):
|
||||
for name, (old, new, diff, ratio) in sorted_diff_entries(diff):
|
||||
if ratio or args.get('all'):
|
||||
print("%-36s %7s %7s %+7d%s" % (name,
|
||||
old or "-",
|
||||
@@ -196,10 +211,14 @@ if __name__ == "__main__":
|
||||
help="Specify CSV file to diff code size against.")
|
||||
parser.add_argument('-a', '--all', action='store_true',
|
||||
help="Show all functions, not just the ones that changed.")
|
||||
parser.add_argument('-s', '--size-sort', action='store_true',
|
||||
help="Sort by size.")
|
||||
parser.add_argument('-S', '--reverse-size-sort', action='store_true',
|
||||
help="Sort by size, but backwards.")
|
||||
parser.add_argument('--files', action='store_true',
|
||||
help="Show file-level code sizes. Note this does not include padding! "
|
||||
"So sizes may differ from other tools.")
|
||||
parser.add_argument('-s', '--summary', action='store_true',
|
||||
parser.add_argument('--summary', action='store_true',
|
||||
help="Only show the total code size.")
|
||||
parser.add_argument('-q', '--quiet', action='store_true',
|
||||
help="Don't show anything, useful with -o.")
|
||||
|
||||
@@ -247,7 +247,7 @@ if __name__ == "__main__":
|
||||
help="Show all functions, not just the ones that changed.")
|
||||
parser.add_argument('--files', action='store_true',
|
||||
help="Show file-level coverage.")
|
||||
parser.add_argument('-s', '--summary', action='store_true',
|
||||
parser.add_argument('--summary', action='store_true',
|
||||
help="Only show the total coverage.")
|
||||
parser.add_argument('-q', '--quiet', action='store_true',
|
||||
help="Don't show anything, useful with -o.")
|
||||
|
||||
Reference in New Issue
Block a user