forked from ekfriis/farmout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_condor_userlogs
executable file
·94 lines (77 loc) · 2.25 KB
/
analyze_condor_userlogs
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 python
import CondorUserLog as ULog
import sys
import getopt
import os
import re
def FindLogs(paths,match_logs,exclude_logs,ended_after=None,logs=None):
if logs == None:
logs = []
for path in paths:
basename = os.path.basename(path)
if os.path.isfile(path):
if match_logs.match(basename) and not exclude_logs.match(basename):
if ended_after is None or ended_after < os.path.getmtime(path):
logs.append(path)
elif os.path.islink(path):
# avoid possibility of link loops by not following links to dirs
pass
elif os.path.isdir(path):
contents = [ os.path.join(path,x) for x in os.listdir(path) ]
FindLogs(contents,match_logs,exclude_logs,ended_after,logs)
return logs
def AnalyzeLogs(logs):
ulog_stats = ULog.CondorUserLogStats()
for log in logs:
ulog = ULog.ReadCondorUserLog(log)
ulog_stats.add(ulog)
print ulog_stats
def JobIdToLog(job_id,logs):
for log in logs:
if os.system("grep -q '" + job_id + "' " + log) != 0:
continue
ulog = ULog.ReadCondorUserLog(log)
for event in ulog.events:
if event.job_id == job_id:
print log
return
def PrintUsage():
sys.stderr.write("""
USAGE: analyze_condor_userlogs [OPTIONS] <user_log_dir>
OPTIONS:
--match-logs=.*\\.log
(regular expression matching log files)
--exclude-logs=((report)|(farmoutRandomSeedJobs)|(farmoutAnalysisJobs)).log
(regular expression of matched files to ignore)
--jobid-to-log=jobid
""")
long_options = [
"help",
"match-logs=",
"exclude-logs=",
"ended-after=",
"jobid-to-log="
]
options,args = getopt.getopt(sys.argv[1:],"h",long_options)
# these defaults work well for farmout logs
match_logs = re.compile(".*\\.log")
exclude_logs = re.compile("((report)|(farmoutRandomSeedJobs)|(farmoutAnalysisJobs)).log")
ended_after = None
jobid_to_log = None
for option,value in options:
if option == "-h" or option == "--help":
PrintUsage()
sys.exit(0)
if option == "--match-logs":
match_logs=re.compile(value)
if option == "--exclude-logs":
exclude_logs=re.compile(value)
if option == "--ended-after":
ended_after=long(value)
if option == "--jobid-to-log":
jobid_to_log = value
logs = FindLogs(args,match_logs,exclude_logs,ended_after=ended_after)
if jobid_to_log:
JobIdToLog(jobid_to_log,logs)
else:
AnalyzeLogs(logs)