forked from antonblanchard/will-it-scale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntest.py
executable file
·124 lines (102 loc) · 3.19 KB
/
runtest.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
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python
import time
import subprocess
import sys
import os
import re
class linux_stat():
def __init__(self, procstat='/proc/stat'):
fd = open(procstat, 'r');
for line in fd.readlines():
arr = line.split()
if arr[0] != 'cpu':
continue
self.user = int(arr[1])
self.nice = int(arr[2])
self.system = int(arr[3])
self.idle = int(arr[4])
self.iowait = int(arr[5])
self.irq = int(arr[6])
self.softirq = int(arr[7])
self.steal = 0
self.guest = 0
self.guest_nice = 0
if len(arr) > 8:
self.steal = int(arr[8])
if len(arr) > 9:
self.guest = int(arr[9])
if len(arr) > 10:
self.guest_nice = int(arr[10])
break
fd.close()
def idle_fraction(self, prev):
busy = self.user + self.nice + self.system + self.irq + self.softirq + self.steal + self.guest + self.guest_nice
idle = self.idle + self.iowait
if prev:
busy = busy - (prev.user + prev.nice + prev.system + prev.irq + prev.softirq + prev.steal + prev.guest + prev.guest_nice)
idle = idle - (prev.idle + prev.iowait)
if (idle + busy) == 0:
return 0
return 1.0 * idle / (idle + busy)
duration=5
if len(sys.argv) != 2:
print >> sys.stderr, 'Usage: runtest.py <testcase>'
sys.exit(1)
cmd = sys.argv[1]
nr_cores=0
r = re.compile('^processor')
fd = open('/proc/cpuinfo', 'r')
for line in fd.readlines():
if r.search(line):
nr_cores = nr_cores + 1
fd.close()
setarch = 'setarch linux64 -R'
try:
retcode = subprocess.call(setarch + " /bin/true", shell=True)
except OSError, e:
retcode = -1
if retcode != 0:
setarch = ''
print >> sys.stderr, 'WARNING: setarch -R failed, address space randomization may cause variability'
pipe = subprocess.Popen('uname -m', shell=True, stdout=subprocess.PIPE).stdout
arch = pipe.readline().rstrip(os.linesep)
pipe.close()
if arch == 'ppc64':
pipe = subprocess.Popen('ppc64_cpu --smt 2>&1', shell=True, stdout=subprocess.PIPE).stdout
smt_status = pipe.readline()
pipe.close()
if 'off' not in smt_status:
print >> sys.stderr, 'WARNING: SMT enabled, suggest disabling'
print 'tasks,processes,processes_idle,threads,threads_idle,linear'
print '0,0,100,0,100,0'
for i in range(1, nr_cores+1):
c = './%s_processes -t %d -s %d' % (cmd, i, duration)
before = linux_stat()
pipe = subprocess.Popen(setarch + ' ' + c, shell=True, stdout=subprocess.PIPE).stdout
processes_avg = -1
for line in pipe.readlines():
if 'testcase:' in line:
(testcase, val) = line.split(':')
title = open(cmd + '.title', 'w')
title.write(val)
title.close()
if 'average:' in line:
(name, val) = line.split(':')
processes_avg = int(val)
pipe.close()
after = linux_stat()
processes_idle = after.idle_fraction(before) * 100
c = './%s_threads -t %d -s %d' % (cmd, i, duration)
before = linux_stat()
pipe = subprocess.Popen(setarch + ' ' + c, shell=True, stdout=subprocess.PIPE).stdout
threads_avg = -1
for line in pipe.readlines():
if 'average:' in line:
(name, val) = line.split(':')
threads_avg = int(val)
pipe.close()
after = linux_stat()
threads_idle = after.idle_fraction(before) * 100
if i == 1:
linear = max(processes_avg, threads_avg)
print '%d,%d,%0.2f,%d,%0.2f,%d' % (i, processes_avg, processes_idle, threads_avg, threads_idle, linear * i)