aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2016-05-23 14:32:50 +0800
committerliang gao <jean.gaoliang@huawei.com>2016-06-12 06:16:44 +0000
commite8075bab08e15413dbd2eac5c13daa6e48838324 (patch)
tree95f83936ee1a88d1888926b233ff3e369462eeaf /yardstick
parent8b4dba01fef62959dee8493808c37074ba0fef8c (diff)
add compute capacity/scale scenario
JIRA: YARDSTICK-271 This scenario reads hardware specification, including number of cpus, number of cores, number of threads, available memory size and total cache size of a host. Change-Id: Icb6c2e103f63fdd61be2461d25c1cf1f4115f161 Signed-off-by: JingLu5 <lvjing5@huawei.com>
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.bash55
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.py68
2 files changed, 123 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.bash b/yardstick/benchmark/scenarios/compute/computecapacity.bash
new file mode 100644
index 000000000..98d4b8fb5
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/computecapacity.bash
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Measure compute capacity and scale of a host
+
+set -e
+
+# run capacity test
+run_capacity()
+{
+ # Number of CPUs
+ CPU=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
+ # Number of physical cores in a single CPU
+ CORE=$(grep 'core id' /proc/cpuinfo | sort -u | wc -l)
+ # Total physical core number
+ CORES=$[$CPU * $CORE]
+ # Number of logical cores
+ THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
+ # Total memory size
+ MEMORY=$(grep 'MemTotal' /proc/meminfo | sort -u)
+ ME=$(echo $MEMORY | awk '/ /{printf "%s %s", $2, $3}')
+ # Cache size per CPU
+ CACHE=$(grep 'cache size' /proc/cpuinfo | sort -u)
+ CA=$(echo $CACHE | awk '/ /{printf "%s", $4}')
+ CACHES=$[$CA * $CPU]
+}
+
+# write the result to stdout in json format
+output_json()
+{
+ echo -e "{ \
+ \"Cpu_number\":\"$CPU\", \
+ \"Core_number\":\"$CORES\", \
+ \"Thread_number\":\"$THREAD\", \
+ \"Memory_size\": \"$ME\", \
+ \"Cache_size\": \"$CACHES KB\" \
+ }"
+}
+
+main()
+{
+ run_capacity
+
+ output_json
+}
+
+main
diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.py b/yardstick/benchmark/scenarios/compute/computecapacity.py
new file mode 100644
index 000000000..366b470e8
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/computecapacity.py
@@ -0,0 +1,68 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import pkg_resources
+import logging
+import json
+
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class ComputeCapacity(base.Scenario):
+ """Measure compute capacity and scale.
+
+ This scenario reads hardware specification, including number of cpus,
+ number of cores, number of threads, available memory size and total cache
+ size of a host.
+ """
+ __scenario_type__ = "ComputeCapacity"
+ TARGET_SCRIPT = "computecapacity.bash"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+
+ def setup(self):
+ """scenario setup"""
+ self.target_script = pkg_resources.resource_filename(
+ "yardstick.benchmark.scenarios.compute",
+ ComputeCapacity.TARGET_SCRIPT)
+
+ nodes = self.context_cfg['nodes']
+ node = nodes.get('host1', None)
+ host_user = node.get('user', 'ubuntu')
+ host_ip = node.get('ip', None)
+ host_pwd = node.get('password', 'root')
+ LOG.debug("user:%s, host:%s", host_user, host_ip)
+ self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
+ self.client.wait(timeout=600)
+
+ # copy script to host
+ self.client.run("cat > ~/computecapacity.sh",
+ stdin=open(self.target_script, 'rb'))
+
+ self.setup_done = True
+
+ def run(self, result):
+ """execute the benchmark"""
+
+ if not self.setup_done:
+ self.setup()
+
+ cmd = "sudo bash computecapacity.sh"
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ result.update(json.loads(stdout))