2017-09-18 10:50:00 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import json
|
2018-02-12 01:44:40 +00:00
|
|
|
import os
|
2017-09-18 10:50:00 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
from systemd import journal
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-12 00:37:00 +00:00
|
|
|
json_file = sys.argv[1]
|
2018-02-28 02:57:35 +00:00
|
|
|
event_identifier = sys.argv[2]
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
scale_factor = float(os.environ.get('SUBIQUITY_REPLAY_TIMESCALE', "4"))
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
def time_for_entry(e):
|
|
|
|
return int(e['__MONOTONIC_TIMESTAMP'])/1e6
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
def report(e):
|
|
|
|
if e['SYSLOG_IDENTIFIER'].startswith("curtin_event"):
|
|
|
|
e['SYSLOG_IDENTIFIER'] = event_identifier
|
|
|
|
e['CODE_LINE'] = int(e['CODE_LINE'])
|
|
|
|
journal.send(**e)
|
2019-02-21 08:45:40 +00:00
|
|
|
elif e['SYSLOG_IDENTIFIER'].startswith("curtin_log") and scale_factor < 10:
|
2018-02-28 02:57:35 +00:00
|
|
|
print(e['MESSAGE'], flush=True)
|
2018-02-12 01:44:40 +00:00
|
|
|
|
2017-10-19 03:49:48 +00:00
|
|
|
prev_ev = None
|
2017-09-18 10:50:00 +00:00
|
|
|
for line in open(json_file):
|
2018-02-28 02:57:35 +00:00
|
|
|
ev = json.loads(line.strip())
|
2017-10-19 03:49:48 +00:00
|
|
|
if prev_ev is not None:
|
2018-02-28 02:57:35 +00:00
|
|
|
report(prev_ev)
|
|
|
|
time.sleep(min((time_for_entry(ev) - time_for_entry(prev_ev)), 8)/scale_factor)
|
2017-10-19 03:49:48 +00:00
|
|
|
prev_ev = ev
|
2018-02-28 02:57:35 +00:00
|
|
|
report(prev_ev)
|