summaryrefslogtreecommitdiff
path: root/lib/loader.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-09-10 16:02:32 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-09-10 16:02:32 +0200
commit2546a93b8b2a3ecdea77bbf38332c4dd77d83239 (patch)
tree86006a0e64215789b2fb97cf3c5470e5749b03f1 /lib/loader.py
parentd8bc1ccd39986f9b8af066636921f91667dc2492 (diff)
add kconfig benchmark loader and model generation
Diffstat (limited to 'lib/loader.py')
-rw-r--r--lib/loader.py58
1 files changed, 48 insertions, 10 deletions
diff --git a/lib/loader.py b/lib/loader.py
index 57b3d30..3f0662e 100644
--- a/lib/loader.py
+++ b/lib/loader.py
@@ -10,6 +10,7 @@ import re
import struct
import tarfile
import hashlib
+import kconfiglib
from multiprocessing import Pool
from .utils import running_mean, soft_cast_int
@@ -1090,7 +1091,7 @@ def _add_trace_data_to_aggregate(aggregate, key, element):
def pta_trace_to_aggregate(traces, ignore_trace_indexes=[]):
- u"""
+ """
Convert preprocessed DFA traces from peripherals/drivers to by_name aggregate for PTAModel.
arguments:
@@ -1296,7 +1297,7 @@ class EnergyTraceLog:
return self._ts_to_index(timestamp, mid_index, right_index)
def analyze_states(self, traces, offline_index: int):
- u"""
+ """
Split log data into states and transitions and return duration, energy, and mean power for each element.
:param traces: expected traces, needed to synchronize with the measurement.
@@ -1630,7 +1631,7 @@ class MIMOSA:
self.errors = list()
def charge_to_current_nocal(self, charge):
- u"""
+ """
Convert charge per 10µs (in pJ) to mean currents (in µA) without accounting for calibration.
:param charge: numpy array of charges (pJ per 10µs) as returned by `load_data` or `load_file`
@@ -1642,7 +1643,7 @@ class MIMOSA:
return charge * ua_step
def _load_tf(self, tf):
- u"""
+ """
Load MIMOSA log data from an open `tarfile` instance.
:param tf: `tarfile` instance
@@ -1663,7 +1664,7 @@ class MIMOSA:
return charges, triggers
def load_data(self, raw_data):
- u"""
+ """
Load MIMOSA log data from a MIMOSA log file passed as raw byte string
:param raw_data: MIMOSA log file, passed as raw byte string
@@ -1675,7 +1676,7 @@ class MIMOSA:
return self._load_tf(tf)
def load_file(self, filename):
- u"""
+ """
Load MIMOSA log data from a MIMOSA log file
:param filename: MIMOSA log file
@@ -1686,7 +1687,7 @@ class MIMOSA:
return self._load_tf(tf)
def currents_nocal(self, charges):
- u"""
+ """
Convert charges (pJ per 10µs) to mean currents without accounting for calibration.
:param charges: numpy array of charges (pJ per 10µs)
@@ -1743,7 +1744,7 @@ class MIMOSA:
return trigidx
def calibration_edges(self, currents):
- u"""
+ """
Return start/stop indexes of calibration measurements.
:param currents: uncalibrated currents as reported by MIMOSA. For best results,
@@ -1780,7 +1781,7 @@ class MIMOSA:
)
def calibration_function(self, charges, cal_edges):
- u"""
+ """
Calculate calibration function from previously determined calibration edges.
:param charges: raw charges from MIMOSA
@@ -1870,7 +1871,7 @@ class MIMOSA:
return calfunc, caldata
def analyze_states(self, charges, trigidx, ua_func):
- u"""
+ """
Split log data into states and transitions and return duration, energy, and mean power for each element.
:param charges: raw charges (each element describes the charge in pJ transferred during 10 µs)
@@ -1940,3 +1941,40 @@ class MIMOSA:
previdx = idx
is_state = not is_state
return iterdata
+
+
+class KConfigAttributes:
+ def __init__(self, kconfig_path, datadir):
+ experiments = list()
+ for direntry in os.listdir(datadir):
+ config_path = f"{datadir}/{direntry}/.config"
+ attr_path = f"{datadir}/{direntry}/attributes.json"
+ if os.path.exists(attr_path):
+ experiments.append((config_path, attr_path))
+
+ kconf = kconfiglib.Kconfig(kconfig_path)
+
+ self.symbols = sorted(
+ map(
+ lambda sym: sym.name,
+ filter(
+ lambda sym: kconfiglib.TYPE_TO_STR[sym.type] == "bool",
+ kconf.syms.values(),
+ ),
+ )
+ )
+
+ self.data = list()
+
+ config_vectors = set()
+
+ for config_path, attr_path in experiments:
+ kconf.load_config(config_path)
+ with open(attr_path, "r") as f:
+ attr = json.load(f)
+
+ config_vector = tuple(
+ map(lambda sym: kconf.syms[sym].tri_value == 2, self.symbols)
+ )
+ config_vectors.add(config_vector)
+ self.data.append((config_vector, attr))