view bin/deltas.py @ 90:c1a70532444c

flip loops
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 31 Aug 2023 14:14:21 +0100
parents e8f89aaa07c1
children
line wrap: on
line source

#!/usr/bin/python3
'''Extract and tabulate runtimes per file from a slurm output log'''
import sys, re
from datetime import datetime
pending={}
first=None
SPAT=re.compile('... (.*) BST start ([0-9]+ [0-9]+)')
EPAT=re.compile('... (.*) BST end ([0-9]+ [0-9]+)')
with open(sys.argv[1],'r') as f:
  for l in f:
    if m:=SPAT.match(l):
      b=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p")
      id=m[2]
      if id in pending:
        print('%s started twice at %s, %s'%(id,pending[id],b),file=sys.stderr)
      else:
        pending[id]=b
        if first is None:
          first=b
    elif m:=EPAT.match(l):
      e=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p")
      id=m[2]
      if id in pending:
        delta=(e-pending[id]).seconds
        print(delta,"%2d:%02d"%(delta/60,delta%60),sep='\t')
        del pending[id]
      else:
        print('%s ended w/o start at %s'%(id,e),file=sys.stderr)
w=(e-first).seconds
sys.stdout.flush()
print('From %s to %s:'%(first.strftime("%d %b %Y %I:%M:%S %p"),
                        e.strftime("%d %b %Y %I:%M:%S %p")),file=sys.stderr)
print(' %d:%02d:%02d'%(w/3600,(w/60)%60,w%60),(e-first).seconds,sep='\t',file=sys.stderr)