Skip to content

Commit 71f47ee

Browse files
committed
Fix handling truncated events
1 parent 2433dcd commit 71f47ee

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

preciceprofiling/merge.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ def insertEvent(cur, pid, rank, name, ts, dur, data):
152152
)
153153

154154

155+
def getTSofLastEvent(cur, pid, rank):
156+
cur.execute(
157+
"SELECT max(ts + dur) FROM events WHERE pid == ? AND rank == ?", (pid, rank)
158+
)
159+
end = cur.fetchone()[0]
160+
assert isinstance(end, int)
161+
return end
162+
163+
155164
def alignEvents(con: sqlite3.Connection):
156165
"""Aligns passed events of multiple ranks and or participants.
157166
All ranks of a participant align at initialization, ensured by a barrier in preCICE.
@@ -285,14 +294,13 @@ def namedEvents():
285294

286295
# Handle leftover events in case of a truncated input file
287296
if active:
288-
lastTS = min(map(lambda e: e["ts"] + e["dur"], completed))
297+
lastTS = getTSofLastEvent(cur, pid, rank)
289298
for event in active.values():
290-
name = event["eid"] # This is a global id
299+
name = event["eid"]
291300
print(f"Truncating event without end {name}")
292-
begin = active[name]
293-
ts = int(begin["ts"]) + initTime
294-
dur = lastTS - begin["ts"]
295-
data = begin.get("data")
301+
ts = int(event["ts"]) + initTime
302+
dur = lastTS - event["ts"]
303+
data = event.get("data")
296304
insertEvent(cur, pid, rank, name, ts, dur, data)
297305

298306

0 commit comments

Comments
 (0)