-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmutilate_merge_logs.py
executable file
·80 lines (66 loc) · 1.91 KB
/
mutilate_merge_logs.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python3
import argparse
import os
from pprint import pprint
import subprocess
import sys
from time import sleep
def shell(cmd):
print('cmd:', cmd)
subprocess.check_output(cmd, shell=True)
def main():
notice()
argv = sys.argv
script_dir = os.path.basedir(argv[0])
save_path = ''
agents = []
base = './tmp/'
for i, arg in enumerate(argv):
if arg.startswith('--save='):
_,save_path = arg.split('=')
break
elif arg == '-a':
agents.append(argv[i+1])
elif arg.startswith('--agent='):
agent = arg.split('=')
agents.append(agent)
print('Agents:')
pprint(agents)
print('Log file location:', save_path)
cmd = [os.path.join(script_dir, 'mutilate')]
cmd += argv[1:]
print ('CMD:', cmd)
p = subprocess.run(cmd)
if p.returncode != 0:
print('mutilate failed!')
sys.exit(1)
# Should I wait?
sleep(1)
if not os.path.isdir(base):
os.mkdir(base)
ssh_user = os.environ.get('MUTILATE_SSH_USR')
if ssh_user is None:
print('MUTILATE_SSH_USR is not defined')
sys.exit(1)
# First copy local file
k = 0
cmd = 'cp {path} {base}/_{k}.txt'.format(path=save_path, base=base, k=k)
shell(cmd)
k += 1
# Then fetch other agents files
for agent in agents:
cmd = 'scp {user}@{agent}:{path} {base}/_{k}.txt'.format(user=ssh_user,
agent=agent, path=save_path, base=base, k=k)
shell(cmd)
k += 1
# Merge files and sort
cmd = 'cat {base}/_*.txt > {base}/result.txt'.format(base=base)
shell(cmd)
cmd = 'sort -k2 -n {base}/result.txt > {base}/sres.txt'.format(base=base)
shell(cmd)
print('Done')
def notice():
print("\tIf using multi-node trace gathering then make sure\n"
"\tthe clock of machines are in sync")
if __name__ == '__main__':
main()