-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
112 lines (85 loc) · 3.13 KB
/
util.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os
import subprocess
APPLICATION_CPU = 10 # (Bound to Core 10, Socket 0, NUMA 0)
APPLICATION_MEM = 0
LOGICAL_CPU = 22 # (Bound to Core 10, Socket 0, NUMA 0)
LOGICAL_MEM = 0
DIFFERENT_CPU = 11 # (Bound to Core 11, Socket 1, NUMA 1)
DIFFERENT_MEM = 1
def shell_call(command, show_command=False):
if show_command:
print('RUNNING COMMAND: ' + command)
p = subprocess.Popen(command, shell=True)
p.wait()
if show_command:
print('')
def shell_output(command, show_command=False):
if show_command:
print('RUNNING COMMAND: ' + command)
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).communicate()[0]
if show_command:
print('')
return output
def container_folder(process, container):
if not os.path.isdir("benchmark"):
shell_call("mkdir benchmark")
return "benchmark/{0:s}-{1:s}".format(process, container)
def instance_folder(cf, date):
return "{0:s}/{1:s}".format(cf, date)
def check_benchmark(args):
benchmarks = [
'cpu',
]
for benchmark in ['memBw', 'memCap', 'l3']:
for i in [1, 5, 9]:
benchmarks.append('{0:s}-{1:d}'.format(benchmark, i))
benchmark_tests = [
'bare'
]
for benchmark in benchmarks:
benchmark_tests.append('{0:s}-same-container'.format(benchmark))
benchmark_tests.append('{0:s}-no-container-different-core'.format(benchmark))
benchmark_tests.append('{0:s}-no-container-same-core'.format(benchmark))
benchmark_tests.append('{0:s}-no-container-different-logical-core'.format(benchmark))
benchmark_tests.append('{0:s}-different-container-same-core'.format(benchmark))
benchmark_tests.append('{0:s}-different-container-different-logical-core'.format(benchmark))
benchmark_tests.append('{0:s}-different-container-different-core'.format(benchmark))
if args.test == 'help':
print('Choose from the following:\n{0:s}'.format('\n'.join(benchmark_tests)))
os.exit(0)
elif args.test not in benchmark_tests:
raise Exception('Invalid benchmark {0:s}. Choose from the following:\n{1:s}'.format(args.test, '\n'.join(benchmark_tests)))
def cpu(v='default'):
if v == 'default':
return APPLICATION_CPU
elif v == 'logical':
return LOGICAL_CPU
elif v == 'different':
return DIFFERENT_CPU
else:
raise Exception('cpu - not implemented')
def processor(i):
return 18 + 2*i
def physical_processors(n):
processors = []
for i in range(n):
processors.append(processor(i))
return processors
def memory(v='default'):
if v == 'default':
return APPLICATION_MEM
elif v == 'logical':
return LOGICAL_MEM
elif v == 'different':
return DIFFERENT_MEM
else:
raise Exception('mem - not implemented')
def tmux_command(session, command, wait=False):
prefix_wait_command = ''
postfix_wait_command = ''
if wait:
prefix_wait_command = '; tmux wait-for -S command'
postfix_wait_command = '\; wait-for command'
shell_call('tmux send-keys -t {0:s} "{1:s}{2:s}" C-m{3:s}'.format(session, command, prefix_wait_command, postfix_wait_command))
def get_ip_address(name):
return shell_output("/sbin/ifconfig {0:s} | grep 'inet addr:' | cut -d: -f2 | awk '{{ print $1 }}'".format(name)).strip()