-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_plot
More file actions
executable file
·82 lines (67 loc) · 2.92 KB
/
Copy pathprofile_plot
File metadata and controls
executable file
·82 lines (67 loc) · 2.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/python
"""
Writes a 3-panel plot of a Slurm job profile (per-task CPU, Memory, & I/O) into an image file.
Usage:
profile_plot [options] JOBID
JOBID can be a Slurm job ID or job step ID.
Options:
-c, --colour=<task|node|step> Which field to colour by. Defaults to "step" for jobs, "task" for steps.
-r, --iorate Show I/O rates rather than cumulative I/O.
-e, --elapsed Zero time at start of the job.
-x, --width=NUM Width of each chart [default: 400].
-y, --height=NUM Height of each chart [default: 150].
-m, --max_timepoints=NUM Downsample to no more than this many timestamps [default: 600].
-n, --max_tasks=NUM Downsample to no more than this many tasks [default: 16].
-f, --format=<PNG|SVG|PDF|HTML|JSON> Output file format [default: PNG].
-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):
colour_field = args['--colour']
if colour_field not in {None, 'task', 'step', 'node'}:
raise ValueError(colour_field)
accumulate_io = not args['--iorate']
relative_time = args['--elapsed']
height = int(args['--height'])
width = int(args['--width'])
max_timepoints = int(args['--max_timepoints'])
max_tasks = int(args['--max_tasks'])
file_format = args['--format'].lower()
if file_format not in {'png', 'svg', 'pdf', 'json', 'html'}:
raise ValueError(file_format)
sacct_id = args['JOBID']
if "." in sacct_id:
(job_id, step_id) = sacct_id.split('.')
colour_field = colour_field or 'task'
else:
(job_id, step_id) = (sacct_id, None)
colour_field = colour_field or 'step'
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 ['height', 'width', 'file_format', 'job_id', 'step_id', 'relative_time', 'colour_field', 'accumulate_io', 'max_timepoints', 'max_tasks']:
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_chart', params=params)
mime_type = reply.headers['content-type'].split(';')[0]
(mime_kind, mime_format) = mime_type.split('/')
if reply.status_code != 200:
msg = reply.content.decode() if mime_kind == 'text' else 'Failed'
sys.stderr.write(msg + '\n')
sys.exit(1)
else:
assert mime_kind == 'image'
sacct_id = args['JOBID']
fn = args['--output']
if fn is None:
fn = f'{sacct_id}_profile.{mime_format}'
sys.stderr.write(f'Writing {fn}\n')
(sys.stdout.buffer if fn=='-' else open(fn, 'wb')).write(reply.content)