Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Bailly
Gepetto Utils
Commits
f3c17c82
Commit
f3c17c82
authored
Apr 09, 2018
by
Guilhem Saurel
Browse files
parse_muscod_logs.py for
@jcarpent
parent
3d25b2b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/parse_muscod_logs.py
0 → 100755
View file @
f3c17c82
#!/usr/bin/env python2
import
argparse
import
datetime
import
logging
import
re
args
=
argparse
.
ArgumentParser
()
args
.
add_argument
(
'filename'
,
type
=
argparse
.
FileType
(
'r'
))
args
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
)
logging
.
basicConfig
()
logger
=
logging
.
getLogger
(
'parse_muscod_logs'
)
def
parse_muscod_logs
(
filename
,
verbose
):
"""
Parse muscod's logs to get NDIS, the number of iterations & total computation time
"""
ndis
=
iterations
=
total
=
None
logger
.
setLevel
(
logging
.
INFO
if
verbose
else
logging
.
WARNING
)
for
number
,
line
in
enumerate
(
filename
):
if
'NDIS'
in
line
:
ndis
=
int
(
line
.
split
(
'='
)[
1
].
strip
())
logger
.
info
(
'found NDIS on line %i: %s'
%
(
number
,
ndis
))
elif
'**** SQP iteration'
in
line
:
# Only the last will be remembered
iterations
=
int
(
line
.
split
(
' '
)[
3
].
strip
())
logger
.
info
(
'found iterations on line %i: %s'
%
(
number
,
iterations
))
elif
' Total'
in
line
:
# double space to avoid 'Grand Total' line
total_dict
=
re
.
search
(
'(?P<minutes>\d{2}):(?P<seconds>\d{2}).(?P<milliseconds>\d{3})'
,
line
).
groupdict
()
total
=
datetime
.
timedelta
(
**
{
k
:
int
(
v
)
for
k
,
v
in
total_dict
.
items
()})
logger
.
info
(
'found total on line %i: %s'
%
(
number
,
total
))
if
ndis
is
None
:
logger
.
error
(
'NDIS not found'
)
if
iterations
is
None
:
logger
.
error
(
'iterations not found'
)
if
total
is
None
:
logger
.
error
(
'total not found'
)
return
{
'ndis'
:
ndis
,
'iterations'
:
iterations
,
'total'
:
total
}
if
__name__
==
'__main__'
:
ret
=
parse_muscod_logs
(
**
vars
(
args
.
parse_args
()))
print
(
ret
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment