-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathes_relval_stats.py
executable file
·94 lines (92 loc) · 2.8 KB
/
es_relval_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
93
94
#!/usr/bin/env python3
from __future__ import print_function
from sys import exit, argv
from _py2with3compatibility import run_cmd
from os.path import isdir, basename, exists, join
import json
from es_utils import es_send_resource_stats
from hashlib import sha1
import threading
from time import sleep
import re
partial_log_dirpath = argv[1]
jobs = 6
try:
jobs = int(argv[2])
except:
jobs = 6
items = partial_log_dirpath.split("/")
if items[-1] != "pyRelValPartialLogs":
exit(1)
release = items[-2]
arch = items[-6]
if not exists("%s/threads.txt" % partial_log_dirpath):
e, o = run_cmd(
"grep ' --nThreads ' %s/*/cmdLog | tail -1 | sed 's|.* *--nThreads *||;s| .*||'"
% partial_log_dirpath
)
if e:
print(o)
exit(1)
if not o:
o = "1"
run_cmd("echo %s > %s/threads.txt" % (o, partial_log_dirpath))
cmsThreads = open(join(partial_log_dirpath, "threads.txt")).read().split("\n")[0]
e, o = run_cmd("ls -d %s/*" % partial_log_dirpath)
threads = []
for wf in o.split("\n"):
if not isdir(wf):
continue
if exists(join(wf, "wf_stats.done")):
continue
wfnum = basename(wf).split("_", 1)[0]
hostname = ""
if exists(join(wf, "hostname")):
hostname = open(join(wf, "hostname")).read().split("\n")[0]
wf_thrds = cmsThreads
if exists(join(wf, "threads.txt")):
wf_thrds = open(join(wf, "threads.txt")).read().split("\n")[0]
exit_codes = {}
if exists(join(wf, "workflow.log")):
e, o = run_cmd(
"grep '^%s_' %s/workflow.log | head -1 | sed 's|.* exit: *||'" % (wfnum, wf)
)
if not o:
o = "256"
istep = 0
for e in [int(x) for x in o.strip().split(" ") if x]:
istep += 1
exit_codes["step%s" % istep] = e
e, o = run_cmd("ls %s/step*.log | sed 's|^.*/||'" % wf)
steps = {}
for log in o.split("\n"):
steps[log.split("_")[0]] = ""
e, o = run_cmd("ls %s/wf_stats-step*.json" % wf)
for s in o.split("\n"):
step = s.split("/wf_stats-")[1][:-5]
if step in steps:
steps[step] = s
for s in steps:
sfile = steps[s]
if sfile == "":
continue
exit_code = -1
if s in exit_codes:
exit_code = exit_codes[s]
while True:
threads = [t for t in threads if t.is_alive()]
if len(threads) >= jobs:
sleep(0.1)
else:
break
params = {"cmsthreads": wf_thrds}
t = threading.Thread(
target=es_send_resource_stats,
args=(release, arch, wfnum, s, sfile, hostname, exit_code, params),
)
t.start()
threads.append(t)
run_cmd("touch %s" % join(wf, "wf_stats.done"))
print("Active Threads:", len(threads))
for t in threads:
t.join()