forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es_ib_build_stats.py
executable file
·92 lines (89 loc) · 2.77 KB
/
es_ib_build_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
import re, json
from datetime import datetime
from os.path import getmtime, exists
from commands import getstatusoutput
from es_utils import send_payload
from hashlib import sha1
ReDate = re.compile("DATE=[A-Z][a-z]{2}\s+([A-Z][a-z]{2}\s+[0-9]{1,2}\s+\d\d:\d\d:\d\d\s+)[A-Z]{3,4}\s+(\d\d\d\d)")
ReUpload = re.compile("^[+]{2}\s+type=upload")
ReRel = re.compile("^[+]\s+RELEASE_FORMAT=(CMSSW_.+)")
ReArch = re.compile("^[+]\s+ARCHITECTURE=(.+)")
ReType = re.compile(".+specs-only\s+build\s+(cmssw-patch).*")
ReFinish = re.compile("Finished:\s[A-Z]+")
def process_build_any_ib(logFile):
rel = ""
arch = ""
uploadTime=0
stime=0
upload=False
jstart = 0
jend=0
patch = 0
finished = False
with open(logFile) as f:
for line in f:
line = line.strip()
if not jstart:
m=ReDate.match(line)
if m:
jstart = datetime.strptime(m.group(1)+m.group(2), "%b %d %H:%M:%S %Y")
continue
if not arch:
m=ReArch.match(line)
if m: arch=m.group(1)
continue
if not rel:
m=ReRel.match(line)
if m: rel=m.group(1)
continue
if ReFinish.match(line):
finished = True
if "ABORTED" in line: return True
break
if ReUpload.match(line):
upload=True
continue
if ReType.match(line): patch=1
m=ReDate.match(line)
if not m: continue
xtime = datetime.strptime(m.group(1)+m.group(2), "%b %d %H:%M:%S %Y")
jend = xtime
if not upload:
stime = xtime
else:
upload=False
dtime = xtime - stime
uploadTime += dtime.seconds
print "FINISHED: ",finished,rel, arch,uploadTime
if not rel or not arch or not finished: return finished
urlx = logFile.split("/")
url = "https://cmssdt.cern.ch/jenkins/job/build-any-ib/"+logFile.split("/")[-2]+"/console"
timestp = getmtime(logFile)
ttime=0
if jend and jstart:
dtime = jend - jstart
ttime = dtime.seconds
print ttime, uploadTime, rel, arch, patch, url
payload = {}
payload["release"] = rel
payload["architecture"] = arch
payload["total_time"] = ttime
payload["upload_time"] = uploadTime
payload["patch"] = patch
payload["@timestamp"] = int(timestp*1000)
payload["url"]=url
print payload
id = sha1(rel + arch).hexdigest()
send_payload("jenkins-ibs","timings",id,json.dumps(payload))
return finished
err, logs = getstatusoutput("find /build/jobs/build-any-ib/builds -maxdepth 2 -mindepth 2 -name log -type f")
logs = logs.split('\n')
for logFile in logs:
flagFile = logFile + '.ib-build'
if not exists(flagFile):
print "Processing ",logFile
done = True
if re.match("^.+/builds/\d+/log$",logFile):
done = process_build_any_ib(logFile)
if done: getstatusoutput('touch "' + flagFile + '"')