7
from tempfile import NamedTemporaryFile
8
from distutils.spawn import find_executable
11
from charmhelpers.contrib.benchmark import Benchmark
13
subprocess.check_call(['apt-get', 'install', '-y', 'python-pip'])
14
subprocess.check_call(['pip', 'install', 'charmhelpers'])
15
from charmhelpers.contrib.benchmark import Benchmark
18
def handler(signum, frame):
19
raise IOError('Timeout')
22
def action_set(key, val):
23
action_cmd = ['action-set']
24
if isinstance(val, dict):
25
for k, v in val.iteritems():
26
action_set('%s.%s' % (key, k), v)
29
action_cmd.append('%s=%s' % (key, val))
30
subprocess.check_call(action_cmd)
34
if find_executable('action-get'):
35
return subprocess.check_output(['action-get', key]).strip()
44
mongoperf runs until interupted so we have to use a
45
signal handler to stop it and gather the results
47
signal.signal(signal.SIGALRM, handler)
48
runtime = int(action_get('runtime') or 180)
52
js['nThreads'] = int(action_get('nthreads'))
53
js['fileSizeMB'] = int(action_get('fileSizeMB'))
54
js['sleepMicros'] = int(action_get('sleepMicros'))
55
js['mmf'] = action_get('mmf')
56
js['r'] = action_get('r')
57
js['w'] = action_get('w')
58
js['recSizeKB'] = int(action_get('recSizeKB'))
59
js['syncDelay'] = int(action_get('syncDelay'))
61
config = NamedTemporaryFile(delete=False)
62
config.write(json.dumps(js))
64
config = open(config.name, 'r')
66
output = NamedTemporaryFile(delete=False)
76
except subprocess.CalledProcessError as e:
78
print "Exit with error code %d" % rc
81
os.kill(p.pid, signal.SIGKILL)
83
os.unlink(config.name)
86
output = open(output.name, 'r')
88
regex = re.compile(r'(\d+)\sops\/sec')
92
scores.append(int(m.group(1)))
96
{'value': sum(scores), 'units': 'ops'}
100
"results.iterations",
101
{'value': len(scores), 'units': 'iterations'}
106
{'value': sum(scores) / float(len(scores)), 'units': 'ops/sec'}
110
{'value': max(scores), 'units': 'ops/sec'}
114
{'value': min(scores), 'units': 'ops/sec'}
117
Benchmark.set_composite_score(
118
sum(scores) / float(len(scores)),
126
if __name__ == "__main__":