Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F74692311
getRunInfo.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 29, 04:20
Size
5 KB
Mime Type
text/x-python
Expires
Wed, Jul 31, 04:20 (2 d)
Engine
blob
Format
Raw Data
Handle
19425799
Attached To
R3127 blackdynamite
getRunInfo.py
View Options
#!/usr/bin/env python
import
base
import
job
import
run
import
os
,
sys
,
stat
import
runconfig
import
subprocess
import
conffile
import
getopt
import
socket
import
bdparser
import
runselector
import
run
import
datetime
################################################################
def
printSummary
(
mybase
,
params
):
runSelector
=
runselector
.
RunSelector
(
mybase
)
run_list
=
runSelector
.
selectRuns
(
params
,
params
,
quiet
=
True
)
print
(
"************************ run summary => study {0} *********************************"
.
format
(
mybase
.
schema
))
if
(
len
(
run_list
)
==
0
):
print
(
"no runs found"
)
sys
.
exit
(
0
)
request
=
"SELECT run_name,state,count(state) from {0}.runs "
.
format
(
mybase
.
schema
)
if
(
len
(
run_list
)
>
0
):
request
+=
"where id in ("
+
","
.
join
([
str
(
r
.
id
)
for
r
,
j
in
run_list
])
+
")"
request
+=
" group by state,run_name order by run_name,state"
# print (request)
curs
=
mybase
.
performRequest
(
request
,[])
stats
=
{}
for
i
in
curs
:
if
i
[
0
]
not
in
stats
:
stats
[
i
[
0
]]
=
[]
stats
[
i
[
0
]]
.
append
([
i
[
1
]
,
int
(
i
[
2
])
])
for
run_name
,
st
in
stats
.
iteritems
():
tot
=
0
for
n
,
count
in
st
:
tot
+=
count
for
n
,
count
in
st
:
print
(
"{:20} {:>20} => {:5} ({:>5.1f}%)"
.
format
(
run_name
,
n
,
count
,
100.
*
count
/
tot
))
print
(
""
)
sys
.
exit
(
0
)
################################################################
def
getRunInfo
(
runid
,
mybase
):
myrun
=
run
.
Run
(
mybase
)
myrun
[
"id"
]
=
runid
myrun
.
id
=
runid
run_list
=
myrun
.
getMatchedObjectList
()
if
(
len
(
run_list
)
==
0
):
print
(
"no run found with id "
+
runid
)
sys
.
exit
(
1
)
myrun
=
run_list
[
0
]
myjob
=
job
.
Job
(
mybase
)
myjob
.
id
=
myrun
[
"job_id"
]
myjob
[
"id"
]
=
myrun
[
"job_id"
]
job_list
=
myjob
.
getMatchedObjectList
()
if
(
len
(
job_list
)
==
0
):
print
(
"no job found with id "
+
myjob
.
id
)
sys
.
exit
(
1
)
myjob
=
job_list
[
0
]
list_entries
=
myjob
.
entries
.
keys
()
print
(
"************************ job info *********************************"
)
for
entry
in
list_entries
:
if
(
myjob
[
entry
]):
print
(
entry
+
": "
+
str
(
myjob
[
entry
]))
print
(
"************************ run info *********************************"
)
list_entries
=
myrun
.
entries
.
keys
()
regular_run_entries
=
(
"run_name"
,
\
"job_id"
,
\
"state"
,
\
"start_time"
,
\
"machine_name"
,
\
"exec"
,
\
"nproc"
,
\
"wait_id"
\
)
for
entry
in
regular_run_entries
:
if
(
myrun
[
entry
]):
print
(
entry
+
": "
+
str
(
myrun
[
entry
]))
list_entries
.
remove
(
entry
)
for
entry
in
list_entries
:
if
(
myrun
[
entry
]):
print
(
entry
+
": "
+
str
(
myrun
[
entry
]))
conffiles
=
myrun
.
getConfigFiles
()
for
conf
in
conffiles
:
print
(
"****************************************************************"
)
print
(
"file #"
+
str
(
conf
.
id
)
+
": "
+
conf
[
"filename"
])
print
(
"****************************************************************"
)
print
(
conf
[
"file"
])
################################################################
parser
=
bdparser
.
BDParser
()
parser
.
register_params
(
group
=
"getRunInfo"
,
params
=
{
"runid"
:
int
,
"order"
:
str
,
"summary"
:
None
},
defaults
=
{
"order"
:
"id"
})
params
=
parser
.
parseBDParameters
()
mybase
=
base
.
Base
(
**
params
)
if
(
"summary"
in
params
):
printSummary
(
mybase
,
params
)
if
(
"runid"
in
params
):
getRunInfo
(
params
[
"runid"
],
mybase
)
else
:
infos
=
[]
infos
.
append
(
"run_name"
)
infos
.
append
(
"id"
)
infos
.
append
(
"job_id"
)
infos
.
append
(
"state"
)
infos
.
append
(
"nproc"
)
infos
.
append
(
"machine_name"
)
infos
.
append
(
"start_time"
)
format_string
=
" {:<20} | {:^4} | {:^6} | {:<15} | {:^5} | {:<20} | {:26}"
line
=
format_string
.
format
(
*
infos
)
line
+=
" | {:10} |"
.
format
(
"last step"
)
line
+=
" {:26} |"
.
format
(
"last update"
)
line
+=
" {:26} |"
.
format
(
"elapsed time/step"
)
separator
=
"-"
*
len
(
line
)
print
(
separator
)
print
(
line
)
print
(
separator
)
run_constraints
=
[]
job_constraints
=
[]
if
(
"run_constraints"
in
params
):
run_constraints
=
params
[
"run_constraints"
]
if
(
"job_constraints"
in
params
):
job_constraints
=
params
[
"job_constraints"
]
runSelector
=
runselector
.
RunSelector
(
mybase
)
run_list
=
runSelector
.
selectRuns
(
run_constraints
,
job_constraints
,
sort_by
=
"runs."
+
params
[
"order"
],
quiet
=
True
)
for
r
,
j
in
run_list
:
run_infos
=
[
r
[
col
]
for
col
in
infos
]
step
,
steptime
=
r
.
getLastStep
()
run_infos
.
append
(
step
)
run_infos
.
append
(
steptime
)
if
(
step
):
run_infos
.
append
((
steptime
-
run_infos
[
6
])
/
step
)
else
:
run_infos
.
append
(
"0"
)
for
i
in
range
(
0
,
len
(
run_infos
)):
if
type
(
run_infos
[
i
])
==
datetime
.
datetime
:
run_infos
[
i
]
=
str
(
run_infos
[
i
]
.
isoformat
(
" "
))
# print (run_infos)
# print ([type(i) for i in run_infos])
line
=
(
format_string
+
" | {:10} |"
+
" {:26} |"
+
" {:26} |"
)
.
format
(
*
run_infos
)
print
(
line
)
Event Timeline
Log In to Comment