Fix imported PCAP session duration for relative timestamps

SIGROK-derived PCAPs have relative timestamps (0, 1.37, 15.02) rather
than epoch time. The _REAL_TS_MIN check failed, so close_session() set
ended to wall-clock (same as started → duration 0s). Now close_session
accepts an optional duration_secs param; the import handler passes
last_ts - first_ts so the session gets the correct capture duration.
This commit is contained in:
catarrh committed 2026-09-06 13:01:46 +03:00
1 parent 05d7a26f2e
commit f9e399183c
2 files changed
+11 -3

No files matched your search

+9 -2
View File
@@ -4,6 +4,7 @@ import os
import sqlite3 import sqlite3
import time import time
from contextlib import contextmanager from contextlib import contextmanager
from datetime import datetime, timedelta
DEFAULT_DB_DIR = os.path.expanduser('~/.simtrace-analyser') DEFAULT_DB_DIR = os.path.expanduser('~/.simtrace-analyser')
DEFAULT_DB_PATH = os.path.join(DEFAULT_DB_DIR, 'sessions.db') DEFAULT_DB_PATH = os.path.join(DEFAULT_DB_DIR, 'sessions.db')
@@ -68,10 +69,16 @@ class Database:
self._conn.commit() self._conn.commit()
return cur.lastrowid return cur.lastrowid
def close_session(self, session_id): def close_session(self, session_id, duration_secs=None):
if duration_secs is not None and duration_secs > 0:
started = self._conn.execute(
'SELECT started FROM sessions WHERE id=?', (session_id,)).fetchone()[0]
ended = (datetime.fromisoformat(started) + timedelta(seconds=duration_secs)).isoformat()
else:
ended = _iso_now()
self._conn.execute( self._conn.execute(
'UPDATE sessions SET ended=? WHERE id=? AND ended IS NULL', 'UPDATE sessions SET ended=? WHERE id=? AND ended IS NULL',
(_iso_now(), session_id)) (ended, session_id))
self._conn.commit() self._conn.commit()
def set_session_times_from_ts(self, session_id, first_ts, last_ts): def set_session_times_from_ts(self, session_id, first_ts, last_ts):
+2 -1
View File
@@ -346,7 +346,8 @@ class RequestHandler(BaseHTTPRequestHandler):
if first_ts is not None and first_ts > _REAL_TS_MIN: if first_ts is not None and first_ts > _REAL_TS_MIN:
self.db.set_session_times_from_ts(session_id, first_ts, last_ts) self.db.set_session_times_from_ts(session_id, first_ts, last_ts)
else: else:
self.db.close_session(session_id) duration = (last_ts - first_ts) if last_ts is not None and first_ts is not None else 0
self.db.close_session(session_id, duration)
_log(f'Session imported: session={session_id} ' _log(f'Session imported: session={session_id} '
f'name={name or "(untitled)"} messages={len(packets)} ' f'name={name or "(untitled)"} messages={len(packets)} '