Mercurial > hg > cc > cirrus_work
comparison lib/python/deltas.py @ 120:1d1bd22124c0
moved from bin
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 28 Sep 2023 08:46:01 +0100 |
parents | bin/deltas.py@e8f89aaa07c1 |
children |
comparison
equal
deleted
inserted
replaced
119:1d12b51c4d59 | 120:1d1bd22124c0 |
---|---|
1 #!/usr/bin/python3 | |
2 '''Extract and tabulate runtimes per file from a slurm output log''' | |
3 import sys, re | |
4 from datetime import datetime | |
5 pending={} | |
6 first=None | |
7 SPAT=re.compile('... (.*) BST start ([0-9]+ [0-9]+)') | |
8 EPAT=re.compile('... (.*) BST end ([0-9]+ [0-9]+)') | |
9 with open(sys.argv[1],'r') as f: | |
10 for l in f: | |
11 if m:=SPAT.match(l): | |
12 b=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p") | |
13 id=m[2] | |
14 if id in pending: | |
15 print('%s started twice at %s, %s'%(id,pending[id],b),file=sys.stderr) | |
16 else: | |
17 pending[id]=b | |
18 if first is None: | |
19 first=b | |
20 elif m:=EPAT.match(l): | |
21 e=datetime.strptime(m[1],"%d %b %Y %I:%M:%S %p") | |
22 id=m[2] | |
23 if id in pending: | |
24 delta=(e-pending[id]).seconds | |
25 print(delta,"%2d:%02d"%(delta/60,delta%60),sep='\t') | |
26 del pending[id] | |
27 else: | |
28 print('%s ended w/o start at %s'%(id,e),file=sys.stderr) | |
29 w=(e-first).seconds | |
30 sys.stdout.flush() | |
31 print('From %s to %s:'%(first.strftime("%d %b %Y %I:%M:%S %p"), | |
32 e.strftime("%d %b %Y %I:%M:%S %p")),file=sys.stderr) | |
33 print(' %d:%02d:%02d'%(w/3600,(w/60)%60,w%60),(e-first).seconds,sep='\t',file=sys.stderr) |