-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_data
More file actions
60 lines (47 loc) · 1.84 KB
/
Copy pathprofile_data
File metadata and controls
60 lines (47 loc) · 1.84 KB
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
#!/bin/python
"""
Extract raw Slurm job profile data (per-task CPU, Memory, & I/O) into a dataframe file.
Usage:
profile_data [options] JOBID
JOBID can be a Slurm job ID or job step ID.
Options:
-f, --format=<csv|parquet|feather|pickle> Output image format [default: csv].
-d, --date_format=<epoch|iso> For text formats such as csv [default: iso].
-m, --max_timepoints=NUM Downsample to no more than this many timestamps [default: 1000].
-o, --output=FILE Output file name. stdout if "-".
If there are too many tasks then only a sample of them will be shown.
"""
import sys
import requests
from subprocess import check_output
from docopt import docopt
sys.tracebacklimit = 0
def process_options(args):
file_format = args['--format'].lower()
if file_format not in {'csv', 'pickle', 'feather', 'parquet'}:
raise ValueError(file_format)
date_format = args['--date_format'].lower()
max_timepoints = args['--max_timepoints']
sacct_id = args['JOBID']
if "." in sacct_id:
(job_id, step_id) = sacct_id.split('.')
else:
(job_id, step_id) = (sacct_id, None)
if '_' in job_id:
job_id = check_output(['sacct', '-X', '-n', '-j', sacct_id, '--format', 'jobidraw'], text=True).strip()
V = vars()
R = {}
for k in ['file_format', 'job_id', 'step_id', 'date_format', 'max_timepoints']:
if V[k] is not False: R[k] = V[k]
return R
args = docopt(__doc__)
params = process_options(args)
reply = requests.get('http://admin01:8000/profile_data', params=params)
reply.raise_for_status()
file_format = params['file_format']
sacct_id = args['JOBID']
fn = args['--output']
if fn is None:
fn = f'{sacct_id}_profile.{file_format}'
sys.stderr.write(f'Writing {fn}\n')
(sys.stdout.buffer if fn=='-' else open(fn, 'wb')).write(reply.content)