summaryrefslogtreecommitdiff
path: root/lib/loader
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-04-22 12:42:48 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-04-22 12:42:48 +0200
commit06887bbbc0f7630986907871bd8365bdba1d2aec (patch)
tree941b5cdc31711384199c21deb2299d4eb49b67a2 /lib/loader
parentaf877114a3e4324e2de36008ccfd87c54dd6b32b (diff)
energytrace loader: handle unsigned overflows as well
Diffstat (limited to 'lib/loader')
-rw-r--r--lib/loader/energytrace.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/loader/energytrace.py b/lib/loader/energytrace.py
index 9d13819..daa5e63 100644
--- a/lib/loader/energytrace.py
+++ b/lib/loader/energytrace.py
@@ -34,6 +34,9 @@ def _load_energytrace(data_string):
data = np.empty((data_count, 4))
hardware_states = [None for i in range(data_count)]
+ energy_overflow_count = 0
+ prev_total_energy = 0
+
for i, line in enumerate(data_lines):
fields = line.split(" ")
if len(fields) == 4:
@@ -43,6 +46,15 @@ def _load_energytrace(data_string):
timestamp, current, voltage, total_energy = map(int, fields[1:])
else:
raise RuntimeError('cannot parse line "{}"'.format(line))
+
+ if (total_energy < 0 and prev_total_energy > 0) or (
+ total_energy >= 0 and total_energy < prev_total_energy
+ ):
+ energy_overflow_count += 1
+
+ prev_total_energy = total_energy
+ total_energy += energy_overflow_count * (2 ** 32)
+
data[i] = [timestamp, current, voltage, total_energy]
interval_start_timestamp = data[1:, 0] * 1e-6