Last active
March 1, 2024 05:24
-
-
Save alex-pat/fd6f2f9f311c639bb22cb7eaf6ec47bc to your computer and use it in GitHub Desktop.
Convert dmesg time offsets to real time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
USAGE = """ ./timesg.py TIMESTAMP [HOURS] <dmesg >dmesg-with-time """ | |
import sys | |
import re | |
import datetime | |
RE = re.compile(r'^\[\s*(\d+\.\d+)\]') | |
def main(starttime, hours=0., *_): | |
starttime = starttime + hours * 3600 | |
for line in sys.stdin: | |
parts = RE.split(line) | |
if len(parts) != 3: | |
print(line, end='') | |
continue | |
_, t_off, tail = parts | |
t_off = float(t_off) | |
time = datetime.datetime.fromtimestamp(starttime + t_off) | |
print('[' + time.strftime('%Y-%m-%d %H:%M:%S') + ']' + tail, end='') | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
main(*map(float, sys.argv[1:])) | |
else: | |
print(USAGE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment