changeset 70:e8f89aaa07c1

for warc_lmh slurm logs
author Henry Thompson <ht@markup.co.uk>
date Fri, 28 Jul 2023 00:50:13 +0100
parents 0d2701901fed
children 432915a28952 db3c689175fe
files bin/deltas.py
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/deltas.py	Fri Jul 28 00:50:13 2023 +0100
@@ -0,0 +1,33 @@
+#!/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)