annotate lib/python/deltas.py @ 179:16d603447fbc

move to class with local vars instead of many globals
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 24 Nov 2023 20:41:03 +0000
parents 1d1bd22124c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
1 #!/usr/bin/python3
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
2 '''Extract and tabulate runtimes per file from a slurm output log'''
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
3 import sys, re
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
4 from datetime import datetime
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
5 pending={}
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
6 first=None
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
7 SPAT=re.compile('... (.*) BST start ([0-9]+ [0-9]+)')
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
8 EPAT=re.compile('... (.*) BST end ([0-9]+ [0-9]+)')
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
9 with open(sys.argv[1],'r') as f:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
10 for l in f:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
11 if m:=SPAT.match(l):
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
12 b=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p")
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
13 id=m[2]
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
14 if id in pending:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
15 print('%s started twice at %s, %s'%(id,pending[id],b),file=sys.stderr)
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
16 else:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
17 pending[id]=b
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
18 if first is None:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
19 first=b
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
20 elif m:=EPAT.match(l):
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
21 e=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p")
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
22 id=m[2]
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
23 if id in pending:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
24 delta=(e-pending[id]).seconds
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
25 print(delta,"%2d:%02d"%(delta/60,delta%60),sep='\t')
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
26 del pending[id]
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
27 else:
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
28 print('%s ended w/o start at %s'%(id,e),file=sys.stderr)
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
29 w=(e-first).seconds
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
30 sys.stdout.flush()
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
31 print('From %s to %s:'%(first.strftime("%d %b %Y %I:%M:%S %p"),
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
32 e.strftime("%d %b %Y %I:%M:%S %p")),file=sys.stderr)
e8f89aaa07c1 for warc_lmh slurm logs
Henry Thompson <ht@markup.co.uk>
parents:
diff changeset
33 print(' %d:%02d:%02d'%(w/3600,(w/60)%60,w%60),(e-first).seconds,sep='\t',file=sys.stderr)