Skip to content

Commit

Permalink
Merge pull request datalad#7598 from yarikoptic/bf-dtime
Browse files Browse the repository at this point in the history
BF: tools/dtime to handle log line having non-increment timestamp
  • Loading branch information
yarikoptic authored May 20, 2024
2 parents ffe92b7 + c9beb93 commit 06d64fb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/dtime
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reg = re.compile('^\d{4}-\d{2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2},\d{1,3}')
prevt = None
maxl = 0
prevl = None
warned_negative = False

if len(sys.argv) <= 1:
in_ = sys.stdin
Expand All @@ -30,7 +31,14 @@ for l in in_:
t = datetime.strptime(l[:end], '%Y-%m-%d %H:%M:%S,%f')
if prevt is not None:
dt = t - prevt
ms = dt.microseconds // 1000 + dt.seconds*1000
secs = dt.total_seconds()
# negative dt has very weird form of -1 day + huge number of seconds
if secs < 0:
if not warned_negative:
sys.stderr.write(f"Negative delta of {secs} seconds detected. Might be due to threading etc\n")
warned_negative = True

ms = secs * 1000
dtstr = ("%5d" % ms if ms else ' 0')

maxl = max(maxl, len(dtstr))
Expand Down

0 comments on commit 06d64fb

Please sign in to comment.