Added coverage-sort to scripts/coverage.py

scripts/coverage.py was missed originally because it's not ran as often
as the others. Since it requires run-time info, it's usually only used
in CI.
This commit is contained in:
Christopher Haster
2022-02-19 15:09:49 -06:00
parent f5286abe7a
commit 20c58dcbaa
2 changed files with 33 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
ifdef VERBOSE ifdef VERBOSE
override TESTFLAGS += -v override TESTFLAGS += -v
override CALLSFLAGS += -v
override CODEFLAGS += -v override CODEFLAGS += -v
override DATAFLAGS += -v override DATAFLAGS += -v
override COVERAGEFLAGS += -v override COVERAGEFLAGS += -v
@@ -53,14 +54,18 @@ override TESTFLAGS += --exec="$(EXEC)"
endif endif
ifdef BUILDDIR ifdef BUILDDIR
override TESTFLAGS += --build-dir="$(BUILDDIR:/=)" override TESTFLAGS += --build-dir="$(BUILDDIR:/=)"
override CALLSFLAGS += --build-dir="$(BUILDDIR:/=)"
override CODEFLAGS += --build-dir="$(BUILDDIR:/=)" override CODEFLAGS += --build-dir="$(BUILDDIR:/=)"
override DATAFLAGS += --build-dir="$(BUILDDIR:/=)" override DATAFLAGS += --build-dir="$(BUILDDIR:/=)"
override CALLSFLAGS += --build-dir="$(BUILDDIR:/=)" override COVERAGEFLAGS += --build-dir="$(BUILDDIR:/=)"
endif endif
ifneq ($(NM),nm) ifneq ($(NM),nm)
override CODEFLAGS += --nm-tool="$(NM)" override CODEFLAGS += --nm-tool="$(NM)"
override DATAFLAGS += --nm-tool="$(NM)" override DATAFLAGS += --nm-tool="$(NM)"
endif endif
override CODEFLAGS += -S
override DATAFLAGS += -S
override COVERAGEFLAGS += -s
# commands # commands
@@ -80,11 +85,11 @@ tags:
.PHONY: code .PHONY: code
code: $(OBJ) code: $(OBJ)
./scripts/code.py -S $^ $(CODEFLAGS) ./scripts/code.py $^ $(CODEFLAGS)
.PHONY: data .PHONY: data
data: $(OBJ) data: $(OBJ)
./scripts/data.py -S $^ $(DATAFLAGS) ./scripts/data.py $^ $(DATAFLAGS)
.PHONY: calls .PHONY: calls
calls: $(CGI) calls: $(CGI)

View File

@@ -148,6 +148,22 @@ def main(**args):
- (old_hits/old_count if old_count else 1.0))) - (old_hits/old_count if old_count else 1.0)))
return diff return diff
def sorted_entries(entries):
if args.get('coverage_sort'):
return sorted(entries, key=lambda x: (-(x[1][0]/x[1][1] if x[1][1] else -1), x))
elif args.get('reverse_coverage_sort'):
return sorted(entries, key=lambda x: (+(x[1][0]/x[1][1] if x[1][1] else -1), x))
else:
return sorted(entries)
def sorted_diff_entries(entries):
if args.get('coverage_sort'):
return sorted(entries, key=lambda x: (-(x[1][2]/x[1][3] if x[1][3] else -1), x))
elif args.get('reverse_coverage_sort'):
return sorted(entries, key=lambda x: (+(x[1][2]/x[1][3] if x[1][3] else -1), x))
else:
return sorted(entries, key=lambda x: (-x[1][6], x))
def print_header(by=''): def print_header(by=''):
if not args.get('diff'): if not args.get('diff'):
print('%-36s %19s' % (by, 'hits/line')) print('%-36s %19s' % (by, 'hits/line'))
@@ -159,7 +175,7 @@ def main(**args):
if not args.get('diff'): if not args.get('diff'):
print_header(by=by) print_header(by=by)
for name, (hits, count) in sorted(entries.items()): for name, (hits, count) in sorted_entries(entries.items()):
print("%-36s %11s %7s" % (name, print("%-36s %11s %7s" % (name,
'%d/%d' % (hits, count) '%d/%d' % (hits, count)
if count else '-', if count else '-',
@@ -174,8 +190,7 @@ def main(**args):
for name, ( for name, (
old_hits, old_count, old_hits, old_count,
new_hits, new_count, new_hits, new_count,
diff_hits, diff_count, ratio) in sorted(diff.items(), diff_hits, diff_count, ratio) in sorted_diff_entries(diff.items()):
key=lambda x: (-x[1][6], x)):
if ratio or args.get('all'): if ratio or args.get('all'):
print("%-36s %11s %7s %11s %7s %11s%s" % (name, print("%-36s %11s %7s %11s %7s %11s%s" % (name,
'%d/%d' % (old_hits, old_count) '%d/%d' % (old_hits, old_count)
@@ -248,10 +263,17 @@ if __name__ == "__main__":
help="Show all functions, not just the ones that changed.") help="Show all functions, not just the ones that changed.")
parser.add_argument('-A', '--everything', action='store_true', parser.add_argument('-A', '--everything', action='store_true',
help="Include builtin and libc specific symbols.") help="Include builtin and libc specific symbols.")
parser.add_argument('-s', '--coverage-sort', action='store_true',
help="Sort by coverage.")
parser.add_argument('-S', '--reverse-coverage-sort', action='store_true',
help="Sort by coverage, but backwards.")
parser.add_argument('--files', action='store_true', parser.add_argument('--files', action='store_true',
help="Show file-level coverage.") help="Show file-level coverage.")
parser.add_argument('--summary', action='store_true', parser.add_argument('--summary', action='store_true',
help="Only show the total coverage.") help="Only show the total coverage.")
parser.add_argument('-q', '--quiet', action='store_true', parser.add_argument('-q', '--quiet', action='store_true',
help="Don't show anything, useful with -o.") help="Don't show anything, useful with -o.")
parser.add_argument('--build-dir',
help="Specify the relative build directory. Used to map object files \
to the correct source files.")
sys.exit(main(**vars(parser.parse_args()))) sys.exit(main(**vars(parser.parse_args())))