From 1dedb2624bde92d35f4b33fdb25851e8706dbc1c Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Wed, 8 May 2024 14:06:33 +0200 Subject: [PATCH 1/2] profile-time: more result reporting, and learn to specify other backends --- scripts/profile-time.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/profile-time.py b/scripts/profile-time.py index cc60686cb..c791900d1 100644 --- a/scripts/profile-time.py +++ b/scripts/profile-time.py @@ -10,7 +10,7 @@ Use the --number and --repeat options to change the number of iterations. By default, the script will emit a markdown table with a label pulled from git. -Note: you can run this script against pre-generated .frz files to reduce the startup time. +This script requires the additional dependency `humanize`. usage: @@ -43,6 +43,7 @@ import subprocess import tqdm +import humanize import tabulate import capa.main @@ -74,7 +75,7 @@ def main(argv=None): label += " (dirty)" parser = argparse.ArgumentParser(description="Profile capa performance") - capa.main.install_common_args(parser, wanted={"format", "os", "input_file", "signatures", "rules"}) + capa.main.install_common_args(parser, wanted={"format", "backend", "os", "input_file", "signatures", "rules"}) parser.add_argument("--number", type=int, default=3, help="batch size of profile collection") parser.add_argument("--repeat", type=int, default=30, help="batch count of profile collection") parser.add_argument("--label", type=str, default=label, help="description of the profile collection") @@ -107,6 +108,18 @@ def do_iteration(): for counter, count in capa.perf.counters.most_common(): logger.debug("perf: counter: %s: %s", counter, count) + print( + tabulate.tabulate( + [ + (counter, humanize.intcomma(count)) + for counter, count in capa.perf.counters.most_common() + ], + headers=["feature class", "evaluation count"], + tablefmt="github", + ) + ) + print() + print( tabulate.tabulate( [ From f017d466c6f935503020190d5f407c0be1a20e7c Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Wed, 8 May 2024 14:14:17 +0200 Subject: [PATCH 2/2] pep8 --- scripts/profile-time.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/profile-time.py b/scripts/profile-time.py index c791900d1..34123a738 100644 --- a/scripts/profile-time.py +++ b/scripts/profile-time.py @@ -110,10 +110,7 @@ def do_iteration(): print( tabulate.tabulate( - [ - (counter, humanize.intcomma(count)) - for counter, count in capa.perf.counters.most_common() - ], + [(counter, humanize.intcomma(count)) for counter, count in capa.perf.counters.most_common()], headers=["feature class", "evaluation count"], tablefmt="github", )