diff options
author | Jeremy Bettis <jbettis@google.com> | 2022-08-29 12:04:45 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-29 19:37:40 +0000 |
commit | 94d768eb692f6cba94d8b79727f7d75c1205bf1d (patch) | |
tree | 35644fceb921cba7fc918a26c488c2f568e64bb5 | |
parent | 0e791f4cfd8e27b9c530f70cb99ee5e8e0ae8e6f (diff) | |
download | chrome-ec-94d768eb692f6cba94d8b79727f7d75c1205bf1d.tar.gz |
ec: Add util to sort lcov output by uncovered
Add new utility script to sort lcov output by uncovered lines of code.
When looking for an easy win, it is usually to look for files with a lot
of uncovered lines, rather than a low coverage percentage.
BRANCH=None
BUG=None
TEST=Ran it.
Signed-off-by: Jeremy Bettis <jbettis@google.com>
Change-Id: I9da9a54c22176bdaa06bad1eb394f8c09bed7c25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3858581
Commit-Queue: Al Semjonovs <asemjonovs@google.com>
Commit-Queue: Yuval Peress <peress@google.com>
Auto-Submit: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Tested-by: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Yuval Peress <peress@google.com>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
-rwxr-xr-x | util/sort_by_unconvered.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/util/sort_by_unconvered.py b/util/sort_by_unconvered.py new file mode 100755 index 0000000000..1f4e0808ae --- /dev/null +++ b/util/sort_by_unconvered.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# Copyright 2022 The ChromiumOS Authors. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Prints out the lines in an lcov info file in order by uncovered lines. + +For example to find the file with the most uncovered lines in herobrine (and +therefore the likest easy win) run the coverage commands in zephyr/README.md +and then run: + +util/sort_by_unconvered.py build/zephyr/herobrine_final.info | head +""" + +import argparse +import re +import subprocess + + +def main(): + """Main function""" + parser = argparse.ArgumentParser(allow_abbrev=False) + parser.add_argument( + "lcov_files", + nargs="+", + metavar="lcov_file", + help="Name(s) of the lcov files to analyze", + default=[], + ) + args = parser.parse_args() + + cmd = ["lcov", "--list-full-path", "--list"] + args.lcov_files + output = subprocess.run( + cmd, check=True, stdout=subprocess.PIPE, universal_newlines=True + ).stdout + + pattern = re.compile(r"^(/\S+)\s*\|\s*([0-9\.]*)%\s*(\d+)\s*\|") + results = [] + for line in output.splitlines(): + match = pattern.match(line) + if match: + results.append( + ( + match[1], # Filename + match[2], # Percent + int(match[3]), # Total lines + int( + float(match[2]) * int(match[3]) / 100.0 + ), # Covered Lines + ) + ) + + results.sort(key=lambda x: x[2] - x[3], reverse=True) + for res in results: + print(f"{res[0]}: {res[3]}/{res[2]} ({res[1]}%)") + + +if __name__ == "__main__": + main() |