diff options
Diffstat (limited to 'lib/model.py')
-rw-r--r-- | lib/model.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/model.py b/lib/model.py index a953c46..f7f8e5c 100644 --- a/lib/model.py +++ b/lib/model.py @@ -1158,6 +1158,8 @@ class PTAModel: class KConfigModel: + """Model for a specific system attribute such as ROM or RAM usage""" + class Leaf: def __init__(self, value, stddev): self.value = value @@ -1206,20 +1208,36 @@ class KConfigModel: ret["y"] = None return ret - def __init__(self, kconfig_benchmark): + def __init__(self, kconfig_benchmark, attribute): self.data = kconfig_benchmark.data self.symbols = kconfig_benchmark.symbols - model = self.get_min(self.symbols, self.data, 0) - - output = {"model": model.to_json(), "symbols": self.symbols} - print(output) + if callable(attribute): + self.attribute = "custom" + self.attr_function = lambda x: attribute(x[1]) + elif attribute == "rom": + self.attribute = "rom" + self.attr_function = lambda x: x[1]["total"]["ROM"] + elif attribute == "ram": + self.attribute = "ram" + self.attr_function = lambda x: x[1]["total"]["RAM"] + else: + raise ValueError("attribute must be a a function, 'rom', or 'ram'") + self.model = self.build_tree(self.symbols, self.data, 0) + + def value_for_config(self, kconf): + return self.model.model(kconf) - # with open("kconfigmodel.json", "w") as f: - # json.dump(output, f) + def to_json(self): + output = { + "model": model.to_json(), + "symbols": self.symbols, + "attribute": self.attribute, + } + return output - def get_min(self, this_symbols, this_data, level): + def build_tree(self, this_symbols, this_data, level): - rom_sizes = list(map(lambda x: x[1]["total"]["ROM"], this_data)) + rom_sizes = list(map(self.attr_function, this_data)) if np.std(rom_sizes) < 100 or len(this_symbols) == 0: return self.Leaf(np.mean(rom_sizes), np.std(rom_sizes)) @@ -1229,10 +1247,8 @@ class KConfigModel: enabled = list(filter(lambda vrr: vrr[0][i] == True, this_data)) disabled = list(filter(lambda vrr: vrr[0][i] == False, this_data)) - enabled_std_rom = np.std(list(map(lambda x: x[1]["total"]["ROM"], enabled))) - disabled_std_rom = np.std( - list(map(lambda x: x[1]["total"]["ROM"], disabled)) - ) + enabled_std_rom = np.std(list(map(self.attr_function, enabled))) + disabled_std_rom = np.std(list(map(self.attr_function, disabled))) children = [enabled_std_rom, disabled_std_rom] if np.any(np.isnan(children)): @@ -1260,12 +1276,12 @@ class KConfigModel: disabled, ) ) - print( + logger.debug( f"Level {level} split on {symbol} has {len(enabled)} children when enabled and {len(disabled)} children when disabled" ) if len(enabled): - node.set_child_y(self.get_min(new_symbols, enabled, level + 1)) + node.set_child_y(self.build_tree(new_symbols, enabled, level + 1)) if len(disabled): - node.set_child_n(self.get_min(new_symbols, disabled, level + 1)) + node.set_child_n(self.build_tree(new_symbols, disabled, level + 1)) return node |