diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-06-25 13:29:33 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-06-25 13:29:33 +0200 |
commit | 08b1449e27da52e186f951914290b56b18bc64b2 (patch) | |
tree | ec47586744a72808396d864a4ad3b19f20a63319 | |
parent | 0df48c75bf77abfc8c721d1045bc43c8da9f8989 (diff) |
analyze-archive: Add --info option
-rwxr-xr-x | bin/analyze-archive.py | 43 | ||||
-rw-r--r-- | lib/dfatool.py | 6 |
2 files changed, 41 insertions, 8 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index f582b0a..cfb832f 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -40,8 +40,8 @@ Options: WARNING: Several GB of RAM and disk space are required for complex measurements. (JSON files may grow very large -- we trade efficiency for easy handling) ---param-info - Show parameter names and values +--info + Show state duration and (for each state and transition) number of measurements and parameter values --show-models=<static|paramdetection|param|all|tex|html> static: show static model values as well as parameter detection heuristic @@ -292,7 +292,8 @@ if __name__ == "__main__": try: optspec = ( - "plot-unparam= plot-param= plot-traces= param-info show-models= show-quality= " + "info " + "plot-unparam= plot-param= plot-traces= show-models= show-quality= " "ignored-trace-indexes= discard-outliers= function-override= " "export-traces= " "filter-param= " @@ -351,8 +352,25 @@ if __name__ == "__main__": args, with_traces=("export-traces" in opt or "plot-traces" in opt) ) + if "info" in opt: + print(" ".join(raw_data.filenames) + ":") + if raw_data.version <= 1: + data_source = "MIMOSA" + elif raw_data.version == 2: + data_sourec = "MSP430 EnergyTrace" + print(f" Data source ID: {raw_data.version} ({data_source})") + preprocessed_data = raw_data.get_preprocessed_data() + if "info" in opt: + print( + f""" Valid Runs: {raw_data.preprocessing_stats["num_valid"]}/{raw_data.preprocessing_stats["num_runs"]}""" + ) + state_durations = map( + lambda x: str(x["state_duration"]), raw_data.setup_by_fileno + ) + print(f""" State Duration: {" / ".join(state_durations)} ms""") + if "export-traces" in opt: uw_per_sot = dict() for trace in preprocessed_data: @@ -422,20 +440,24 @@ if __name__ == "__main__": if xv_method: xv = CrossValidator(PTAModel, by_name, parameters, arg_count) - if "param-info" in opt: + if "info" in opt: for state in model.states(): print("{}:".format(state)) + print(f""" Number of Measurements: {len(by_name[state]["power"])}""") for param in model.parameters(): print( - " {} = {}".format( + " Parameter {} ∈ {}".format( param, model.stats.distinct_values[state][param] ) ) for transition in model.transitions(): print("{}:".format(transition)) + print( + f""" Number of Measurements: {len(by_name[transition]["duration"])}""" + ) for param in model.parameters(): print( - " {} = {}".format( + " Parameter {} ∈ {}".format( param, model.stats.distinct_values[transition][param] ) ) @@ -691,7 +713,14 @@ if __name__ == "__main__": if "plot-param" in opt: for kv in opt["plot-param"].split(";"): - state_or_trans, attribute, param_name, *function = kv.split(" ") + try: + state_or_trans, attribute, param_name, *function = kv.split(" ") + except ValueError: + print( + "Usage: --plot-param='state_or_trans attribute param_name [additional function spec]'", + file=sys.stderr, + ) + sys.exit(1) if len(function): function = gplearn_to_function(" ".join(function)) else: diff --git a/lib/dfatool.py b/lib/dfatool.py index e0eb0d4..63639d3 100644 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -626,10 +626,12 @@ class RawData: if os.path.exists(self.cache_file): with open(self.cache_file, "r") as f: cache_data = json.load(f) + self.filenames = cache_data["filenames"] self.traces = cache_data["traces"] self.preprocessing_stats = cache_data["preprocessing_stats"] if "pta" in cache_data: self.pta = cache_data["pta"] + self.setup_by_fileno = cache_data["setup_by_fileno"] self.preprocessed = True def save_cache(self): @@ -641,9 +643,11 @@ class RawData: pass with open(self.cache_file, "w") as f: cache_data = { + "filenames": self.filenames, "traces": self.traces, "preprocessing_stats": self.preprocessing_stats, "pta": self.pta, + "setup_by_fileno": self.setup_by_fileno, } json.dump(cache_data, f) @@ -2055,7 +2059,7 @@ class PTAModel: PTAModel.by_name and PTAModel.by_param. These provide measurements aggregated by state/transition name - and (in case of by_para) parameter values. Layout: + and (for by_param) parameter values. Layout: dictionary with one key per state/transition ('send', 'TX', ...) or one key per state/transition and parameter combination (('send', (1, 2)), ('send', (2, 3)), ('TX', (1, 2)), ('TX', (2, 3)), ...). |