1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class Lmbench(base.Scenario):
20 """Execute lmbench memory read latency benchmark in a host
23 stride - number of locations in memory between starts of array elements
27 stop_size - maximum array size to test (minimum value is 0.000512)
32 Results are accurate to the ~2-5 nanosecond range.
34 __scenario_type__ = "Lmbench"
36 TARGET_SCRIPT = "lmbench_benchmark.bash"
38 def __init__(self, scenario_cfg, context_cfg):
39 self.scenario_cfg = scenario_cfg
40 self.context_cfg = context_cfg
41 self.setup_done = False
45 self.target_script = pkg_resources.resource_filename(
46 "yardstick.benchmark.scenarios.compute",
47 Lmbench.TARGET_SCRIPT)
48 host = self.context_cfg["host"]
49 user = host.get("user", "ubuntu")
50 ip = host.get("ip", None)
51 key_filename = host.get('key_filename', "~/.ssh/id_rsa")
53 LOG.info("user:%s, host:%s", user, ip)
54 self.client = ssh.SSH(user, ip, key_filename=key_filename)
55 self.client.wait(timeout=600)
58 self.client.run("cat > ~/lmbench.sh",
59 stdin=open(self.target_script, 'rb'))
61 self.setup_done = True
63 def run(self, result):
64 """execute the benchmark"""
66 if not self.setup_done:
69 options = self.scenario_cfg['options']
70 stride = options.get('stride', 128)
71 stop_size = options.get('stop_size', 16)
73 cmd = "sudo bash lmbench.sh %d %d" % (stop_size, stride)
74 LOG.debug("Executing command: %s", cmd)
75 status, stdout, stderr = self.client.execute(cmd)
78 raise RuntimeError(stderr)
80 result.update({"latencies": json.loads(stdout)})
81 if "sla" in self.scenario_cfg:
83 sla_max_latency = int(self.scenario_cfg['sla']['max_latency'])
84 for t_latency in result:
85 latency = t_latency['latency']
86 if latency > sla_max_latency:
87 sla_error += "latency %f > sla:max_latency(%f); " \
88 % (latency, sla_max_latency)
89 assert sla_error == "", sla_error
93 """internal test function"""
94 key_filename = pkg_resources.resource_filename('yardstick.resources',
95 'files/yardstick_key')
98 'ip': '10.229.47.137',
100 'key_filename': key_filename
104 logger = logging.getLogger('yardstick')
105 logger.setLevel(logging.DEBUG)
107 options = {'stride': 128, 'stop_size': 16}
108 args = {'options': options}
111 p = Lmbench(args, ctx)
115 if __name__ == '__main__':