diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/workload.py | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/bin/workload.py b/bin/workload.py index d4dff10..ee2df0d 100755 --- a/bin/workload.py +++ b/bin/workload.py @@ -2,6 +2,7 @@ import argparse import json +import logging import sys import dfatool.cli import dfatool.utils @@ -13,12 +14,21 @@ def main(): formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__ ) parser.add_argument("--aggregate", choices=["sum"], default="sum") + parser.add_argument("--aggregate-unit", choices=["s", "B/s"], default="s") parser.add_argument( "--aggregate-init", default=0, type=float, ) parser.add_argument( + "--log-level", + metavar="LEVEL", + choices=["debug", "info", "warning", "error"], + default="warning", + help="Set log level", + ) + parser.add_argument("--normalize-output", type=str) + parser.add_argument( "--info", action="store_true", help="Show benchmark information (number of measurements, parameter values, ...)", @@ -32,6 +42,17 @@ def main(): parser.add_argument("event", nargs="+", type=str) args = parser.parse_args() + if args.log_level: + numeric_level = getattr(logging, args.log_level.upper(), None) + if not isinstance(numeric_level, int): + print(f"Invalid log level: {args.log_level}", file=sys.stderr) + sys.exit(1) + logging.basicConfig( + level=numeric_level, + format="{asctime} {levelname}:{name}:{message}", + style="{", + ) + models = list() for model_file in args.models: with open(model_file, "r") as f: @@ -46,6 +67,19 @@ def main(): aggregate = args.aggregate_init for event in args.event: + + event_normalizer = lambda p: p + if "/" in event: + v1, v2 = event.split("/") + if dfatool.utils.is_numeric(v1): + event = v2.strip() + event_normalizer = lambda p: dfatool.utils.soft_cast_float(v1) / p + elif dfatool.utils.is_numeric(v2): + event = v1.strip() + event_normalizer = lambda p: p / dfatool.utils.soft_cast_float(v2) + else: + raise RuntimeError(f"Cannot parse '{event}'") + nn, param = event.split("(") name, action = nn.split(".") param_model = None @@ -61,14 +95,32 @@ def main(): param = dict() else: param = dfatool.utils.parse_conf_str(param) - if args.aggregate == "sum": - aggregate += param_model( + + param_list = dfatool.utils.param_dict_to_list(param, ref_model.parameters) + + if not param_info(name, action).is_predictable(param_list): + logging.warning( + f"Cannot predict {name}.{action}({param}), falling back to static model" + ) + + event_output = event_normalizer( + param_model( name, action, - param=dfatool.utils.param_dict_to_list(param, ref_model.parameters), + param=param_list, ) + ) + + if args.aggregate == "sum": + aggregate += event_output - print(aggregate) + if args.normalize_output: + sf = dfatool.cli.parse_shift_function( + "--normalize-output", args.normalize_output + ) + print(dfatool.utils.human_readable(sf(aggregate), args.aggregate_unit)) + else: + print(dfatool.utils.human_readable(aggregate, args.aggregate_unit)) if __name__ == "__main__": |