-
Notifications
You must be signed in to change notification settings - Fork 1
/
cluster_profiler.py
66 lines (58 loc) · 1.54 KB
/
cluster_profiler.py
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
import os
from multiprocessing import Process
import argparse
HOSTs = [
'g4001',
'g4002',
'g4003',
'g4004',
'g4005',
'g4006',
'g4007',
'g4008',
'g3021',
'g3022',
'g3023',
'g3024',
'g3025',
'g3026',
'g3027',
'g3028',
'g3029',
'g1004',
'g1006',
]
LOG_DIR=f'{os.getcwd()}/results'
class Cluster_Profiler(Process):
def __init__(self, host, cmd):
super(Cluster_Profiler, self).__init__()
self.host = host
self.cmd = cmd
def run(self):
os.system(f'ssh {self.host} "{self.cmd} > {LOG_DIR}/{self.host}.log"')
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--cmd", type=str, default="nvidia-smi")
args = parser.parse_args()
return args
def main(args):
print(f'cmd: {args.cmd}')
ps = []
for HOST in HOSTs:
p = Cluster_Profiler(HOST, args.cmd) #实例化进程对象
p.start()
ps.append(p)
for p in ps:
p.join()
# combine all logs
OUTPUT_FILE = f'{LOG_DIR}/cluster_profiler_{"".join(args.cmd.split())}.log'
print(f'output file: {OUTPUT_FILE}')
os.system(f'rm -f {OUTPUT_FILE}')
os.system(f'touch {OUTPUT_FILE}')
for HOST in HOSTs:
os.system(f'echo "================== {HOST} ==================" >> {OUTPUT_FILE}')
os.system(f'cat {LOG_DIR}/{HOST}.log >> {OUTPUT_FILE}')
os.system(f'echo "\n\n" >> {OUTPUT_FILE}')
os.system(f'rm -f {LOG_DIR}/{HOST}.log')
if __name__ == '__main__':
main(parse_args())