diff options
Diffstat (limited to 'bin/analyze-kconfig.py')
-rwxr-xr-x | bin/analyze-kconfig.py | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py index f532a5b..87c05f7 100755 --- a/bin/analyze-kconfig.py +++ b/bin/analyze-kconfig.py @@ -11,6 +11,7 @@ import argparse import json import kconfiglib import logging +import os from dfatool.loader import KConfigAttributes from dfatool.model import KConfigModel @@ -48,7 +49,11 @@ def main(): help="Set log level", ) parser.add_argument("kconfig_path", type=str, help="Path to Kconfig file") - parser.add_argument("experiment_root", type=str, help="Path to experiment results") + parser.add_argument( + "model", + type=str, + help="Path to experiment results directory or model.json file", + ) args = parser.parse_args() @@ -57,13 +62,16 @@ def main(): else: print(f"Invalid log level. Setting log level to INFO.", file=sys.stderr) - data = KConfigAttributes(args.kconfig_path, args.experiment_root) - model = KConfigModel(data, args.attribute) + if os.path.isdir(args.model): + data = KConfigAttributes(args.kconfig_path, args.model) + model = KConfigModel.from_benchmark(data, args.attribute) + if args.max_stddev: + model.max_stddev = args.max_stddev + model.build_tree() - if args.max_stddev: - model.max_stddev = args.max_stddev - - model.build_tree() + else: + with open(args.model, "r") as f: + model = KConfigModel.from_json(json.load(f)) if args.export_tree: with open(args.export_tree, "w") as f: @@ -104,15 +112,27 @@ def main(): if skip: continue - model_diff = model.value_for_config(kconf2) - model.value_for_config(kconf) - if kconf_sym.choice: - print( - f"Setting {kconf_sym.choice.name} to {kconf_sym.name} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" - ) - else: - print( - f"Setting {symbol} to {kconf_sym.str_value} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" + try: + model_diff = model.value_for_config(kconf2) - model.value_for_config( + kconf ) + if kconf_sym.choice: + print( + f"Setting {kconf_sym.choice.name} to {kconf_sym.name} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" + ) + else: + print( + f"Setting {symbol} to {kconf_sym.str_value} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" + ) + except TypeError: + if kconf_sym.choice: + print( + f"Setting {kconf_sym.choice.name} to {kconf_sym.name} changes {num_changes:2d} symbols, model is undefined" + ) + else: + print( + f"Setting {symbol} to {kconf_sym.str_value} changes {num_changes:2d} symbols, model is undefined" + ) for changed_symbol in changed_symbols: print( f" {changed_symbol:30s} -> {kconf2.syms[changed_symbol].str_value}" |