diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-30 11:15:45 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-10-30 11:15:45 +0100 |
commit | df04f15d9132ec6b2781edfccc5ad8d33dd3cdd9 (patch) | |
tree | 2fa0093fc60bac124cf83ba4d01acf6e2b5706b1 /lib | |
parent | c2858f6c1070d7baa87d2f433746adec5042531e (diff) |
Add DFATOOL_EXPORT_LASYNC variable for ET+LA / ET+Timer sync eval
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lennart/DataProcessor.py | 17 | ||||
-rw-r--r-- | lib/loader.py | 7 | ||||
-rw-r--r-- | lib/utils.py | 13 |
3 files changed, 36 insertions, 1 deletions
diff --git a/lib/lennart/DataProcessor.py b/lib/lennart/DataProcessor.py index 07d2a2b..b46315a 100644 --- a/lib/lennart/DataProcessor.py +++ b/lib/lennart/DataProcessor.py @@ -171,6 +171,23 @@ class DataProcessor: ) * endFactor + start_timestamp return modified_timestamps_with_drift + def export_sync(self): + # [1st trans start, 1st trans stop, 2nd trans start, 2nd trans stop, ...] + sync_timestamps = list() + + for i in range(4, len(self.modified_timestamps) - 8, 2): + sync_timestamps.append( + (self.modified_timestamps[i], self.modified_timestamps[i + 1]) + ) + + # EnergyTrace timestamps + timestamps = self.plot_data_x + + # EnergyTrace power values + power = self.plot_data_y + + return {"sync": sync_timestamps, "timestamps": timestamps, "power": power} + def plot(self, annotateData=None): """ Plots the power usage and the timestamps by logic analyzer diff --git a/lib/loader.py b/lib/loader.py index 0e1e8c9..0c7ad91 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -12,7 +12,7 @@ import tarfile import hashlib from multiprocessing import Pool -from .utils import running_mean, soft_cast_int +from .utils import NpEncoder, running_mean, soft_cast_int logger = logging.getLogger(__name__) @@ -1714,6 +1714,11 @@ class EnergyTraceWithLogicAnalyzer: dp.plot() # <- plot traces with sync annotatons # dp.plot(names) # <- plot annotated traces (with state/transition names) pass + if os.getenv("DFATOOL_EXPORT_LASYNC") is not None: + filename = os.getenv("DFATOOL_EXPORT_LASYNC") + f"_{offline_index}.json" + with open(filename, "w") as f: + json.dump(dp.export_sync(), f, cls=NpEncoder) + logger.info("Exported data and LA sync timestamps to {filename}") energy_trace_new = energy_trace_new[4:] energy_trace = list() diff --git a/lib/utils.py b/lib/utils.py index d28ecda..adcb534 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,3 +1,4 @@ +import json import numpy as np import re import logging @@ -6,6 +7,18 @@ arg_support_enabled = True logger = logging.getLogger(__name__) +class NpEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, np.integer): + return int(obj) + elif isinstance(obj, np.floating): + return float(obj) + elif isinstance(obj, np.ndarray): + return obj.tolist() + else: + return super(NpEncoder, self).default(obj) + + def running_mean(x: np.ndarray, N: int) -> np.ndarray: """ Compute `N` elements wide running average over `x`. |