Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
oar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Jeremy Auguste
oar
Commits
0983efc3
Commit
0983efc3
authored
6 years ago
by
Jeremy Auguste
Browse files
Options
Downloads
Patches
Plain Diff
New usage statistics script
parent
4f165a4a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
oarstats.py
+99
-0
99 additions, 0 deletions
oarstats.py
with
99 additions
and
0 deletions
oarstats.py
0 → 100644
+
99
−
0
View file @
0983efc3
#!/usr/bin/env python
# coding: utf-8
import
argparse
import
logging
import
yaml
import
subprocess
import
defaultdict
import
re
import
time
class
Owner
:
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
queues
=
defaultdict
(
list
)
self
.
karma
=
0.0
self
.
timeleft
=
0
self
.
running
=
defaultdict
(
int
)
self
.
resources
=
defaultdict
(
int
)
self
.
gpu
=
defaultdict
(
int
)
def
add_job
(
self
,
job
):
self
.
queues
[
job
.
queue
].
append
(
job
)
if
job
.
karma
>
self
.
karma
:
self
.
karma
=
job
.
karma
self
.
timeleft
+=
job
.
duration
-
job
.
exec_time
self
.
resources
[
job
.
queue
]
+=
job
.
resources
if
job
.
start_time
!=
0
:
self
.
running
[
job
.
queue
]
+=
1
if
job
.
gpu
:
self
.
gpu
[
job
.
queue
]
+=
job
.
resources
def
print_info
(
self
):
print
(
f
"
User
{
self
.
name
}
:: Timeleft:
{
self
.
timeleft
}
, Karma:
{
self
.
karma
}
"
)
for
queue
in
self
.
queues
.
keys
():
print
(
f
"
\t
{
queue
}
- Running
{
self
.
running
[
queue
]
}
, Resources:
{
self
.
resources
[
queue
]
}
, GPUs:
{
self
.
gpu
[
queue
]
}
"
)
class
Job
:
def
__init__
(
self
,
job_id
,
start_time
,
wall_time
,
resources
,
devices
,
gpu
,
queue
,
karma
):
self
.
job_id
=
job_id
self
.
start_time
=
start_time
self
.
wall_time
=
wall_time
self
.
resources
=
resources
self
.
devices
=
devices
self
.
gpu
=
gpu
self
.
queue
=
queue
self
.
karma
def
argparser
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
-l
'
,
'
--logger
'
,
default
=
'
INFO
'
,
choices
=
[
'
DEBUG
'
,
'
INFO
'
,
'
WARNING
'
,
'
ERROR
'
,
'
CRITICAL
'
],
help
=
"
Logging level: DEBUG, INFO (default), WARNING, ERROR
"
)
args
=
parser
.
parse_args
()
numeric_level
=
getattr
(
logging
,
args
.
logger
.
upper
(),
None
)
if
not
isinstance
(
numeric_level
,
int
):
raise
ValueError
(
"
Invalid log level: {}
"
.
format
(
args
.
logger
))
logging
.
basicConfig
(
level
=
numeric_level
)
return
args
def
main
():
args
=
argparser
()
stats_output
=
subprocess
.
check_output
([
"
oarstat
"
,
"
--yaml
"
]).
decode
(
'
utf-8
'
)
stats_yaml
=
yaml
.
load
(
stats_output
)
owners
=
{}
resources_pattern
=
re
.
compile
(
'
R=([0-9]+)
'
)
walltime_pattern
=
re
.
compile
(
'
W=([0-9]+:[0-9]+:[0-9]+)
'
)
queue_pattern
=
re
.
compile
(
'
Q=(\S+)
'
)
karma_pattern
=
re
.
compile
(
'
Karma=([0-9]+\.[0-9]+)
'
)
gpu_pattern
=
re
.
compile
(
'
gpu is not null
'
,
flags
=
re
.
IGNORECASE
)
for
job_id
,
job_info
in
stats_yaml
.
items
():
if
job_info
[
"
owner
"
]
not
in
owners
:
owners
[
job_info
[
"
owner
"
]]
=
Owner
(
job_info
[
"
owner
"
])
start_time
=
0
if
job_info
[
"
startTime
"
]
==
0
else
time
.
time
()
-
job_info
[
"
startTime
"
]
tokens
=
re
.
search
(
walltime_pattern
,
job_info
[
"
message
"
]).
group
(
1
).
split
(
'
:
'
)
wall_time
=
int
(
tokens
[
0
])
*
3600
+
int
(
tokens
[
1
])
*
60
+
int
(
tokens
[
2
])
resources
=
int
(
re
.
search
(
resources_pattern
,
job_info
[
"
message
"
]).
group
(
1
))
queue
=
re
.
search
(
queue_pattern
,
job_info
[
"
message
"
]).
group
(
1
)
karma
=
float
(
re
.
search
(
karma_pattern
,
job_info
[
"
message
"
]).
group
(
1
))
devices
=
job_info
[
"
assigned_network_address
"
]
gpu
=
re
.
search
(
gpu_pattern
,
job_info
[
"
properties
"
])
is
not
None
job
=
Job
(
job_id
,
start_time
,
wall_time
,
resources
,
devices
,
gpu
,
queue
,
karma
)
owners
[
job_info
[
"
owner
"
]].
add_job
(
job
)
for
owner
in
owners
.
values
():
owner
.
print_info
()
print
()
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment