aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2016-05-19 10:48:41 +0800
committerJingLu5 <lvjing5@huawei.com>2016-06-01 09:40:38 +0800
commit62181af69580ea0a80f50767803339bf1984f5ac (patch)
tree0cc8c2e83d7623ed5d4b061850c8361f2ae6d093 /yardstick
parent438596f8942f13e5c5c429b9ae38878e87a3e6ca (diff)
Add cachestat scenario
JIRA: YARDSTICK-267 This scenario reads system cache hit/miss ratio and other statistics using cachestat tool. Change-Id: I601cb7e64d234571c0a0fd65a5e32604b3a617ec Signed-off-by: JingLu5 <lvjing5@huawei.com>
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/scenarios/compute/cache_stat.bash30
-rw-r--r--yardstick/benchmark/scenarios/compute/cachestat.py163
2 files changed, 193 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/compute/cache_stat.bash b/yardstick/benchmark/scenarios/compute/cache_stat.bash
new file mode 100644
index 000000000..393af410c
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/cache_stat.bash
@@ -0,0 +1,30 @@
+#!/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
+##############################################################################
+
+# Run a cachestat cache benchmark in a host
+
+set -e
+
+INTERVAL=$1
+
+run_cachestat()
+{
+ cd /opt/tempT/Cachestat
+ bash cachestat $INTERVAL
+}
+
+main()
+{
+ # run the test
+ run_cachestat
+}
+
+main
diff --git a/yardstick/benchmark/scenarios/compute/cachestat.py b/yardstick/benchmark/scenarios/compute/cachestat.py
new file mode 100644
index 000000000..da4aa754f
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/cachestat.py
@@ -0,0 +1,163 @@
+##############################################################################
+# 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
+##############################################################################
+
+"""cache hit/miss ratio and usage statistics"""
+
+import pkg_resources
+import logging
+import re
+import yardstick.ssh as ssh
+
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class CACHEstat(base.Scenario):
+ '''Collect cache statistics.
+
+ This scenario reads system cache hit/miss ratio and other statistics on
+ a Linux host.
+
+ cache statistics are read using 'cachestat'.
+ cachestat - show Linux page cache hit/miss statistics.
+ Uses Linux ftrace.
+
+ This is a proof of concept using Linux ftrace capabilities on older
+ kernels, and works by using function profiling for in-kernel counters.
+ Specifically, four kernel functions are traced:
+
+ mark_page_accessed() for measuring cache accesses
+ mark_buffer_dirty() for measuring cache writes
+ add_to_page_cache_lru() for measuring page additions
+ account_page_dirtied() for measuring page dirties
+
+ It is possible that these functions have been renamed (or are different
+ logically) for your kernel version, and this script will not work as-is.
+ This script was written on Linux 3.13. This script is a sandcastle: the
+ kernel may wash some away, and you'll need to rebuild.
+
+ USAGE: cachestat [-Dht] [interval]
+ eg,
+ cachestat 5 # show stats every 5 seconds
+
+ Run "cachestat -h" for full usage.
+
+ WARNING: This uses dynamic tracing of kernel functions, and could cause
+ kernel panics or freezes. Test, and know what you are doing, before use.
+ It also traces cache activity, which can be frequent, and cost some
+ overhead. The statistics should be treated as best-effort: there may be
+ some error margin depending on unusual workload types.
+
+ REQUIREMENTS: CONFIG_FUNCTION_PROFILER, awk.
+ '''
+ __scenario_type__ = "CACHEstat"
+
+ TARGET_SCRIPT = "cache_stat.bash"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ """Scenario construction."""
+ 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",
+ CACHEstat.TARGET_SCRIPT)
+
+ host = self.context_cfg['host']
+ user = host.get('user', 'ubuntu')
+ ip = host.get('ip', None)
+ key_filename = host.get('key_filename', '~/.ssh/id_rsa')
+
+ LOG.info("user:%s, host:%s", user, ip)
+ self.client = ssh.SSH(user, ip, key_filename=key_filename)
+ self.client.wait(timeout=600)
+
+ # copy scripts to host
+ self.client.run("cat > ~/cache_stat.sh",
+ stdin=open(self.target_script, 'rb'))
+
+ self.setup_done = True
+
+ def _execute_command(self, cmd):
+ """Execute a command on server."""
+ LOG.info("Executing: %s" % cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError("Failed executing command: ",
+ cmd, stderr)
+ return stdout
+
+ def _filtrate_result(self, result):
+ fields = []
+ cachestat = {}
+ data_marker = re.compile("\d+")
+ ite = 0
+ average = {'HITS': 0, 'MISSES': 0, 'DIRTIES': 0, 'RATIO': 0,
+ 'BUFFERS_MB': 0, 'CACHE_MB': 0}
+ maximum = {'HITS': 0, 'MISSES': 0, 'DIRTIES': 0, 'RATIO': 0,
+ 'BUFFERS_MB': 0, 'CACHE_MB': 0}
+
+ # Parse cache stats
+ for row in result.split('\n'):
+ line = row.split()
+
+ if line and line[0] == 'HITS':
+ # header fields
+ fields = line[:]
+ elif line and re.match(data_marker, line[0]):
+ cache = 'cache' + str(ite)
+ ite += 1
+ values = line[:]
+ if values and len(values) == len(fields):
+ cachestat[cache] = dict(zip(fields, values))
+
+ for entry in cachestat:
+ for item in average:
+ if item != 'RATIO':
+ average[item] += int(cachestat[entry][item])
+ else:
+ average[item] += float(cachestat[entry][item][:-1])
+
+ for item in maximum:
+ if item != 'RATIO':
+ if int(cachestat[entry][item]) > maximum[item]:
+ maximum[item] = int(cachestat[entry][item])
+ else:
+ if float(cachestat[entry][item][:-1]) > maximum[item]:
+ maximum[item] = float(cachestat[entry][item][:-1])
+
+ for item in average:
+ if item != 'RATIO':
+ average[item] = average[item] / len(cachestat)
+ else:
+ average[item] = str(average[item] / len(cachestat)) + '%'
+
+ return {'cachestat': cachestat, 'average': average, 'max': maximum}
+
+ def _get_cache_usage(self):
+ """Get cache statistics."""
+ options = self.scenario_cfg['options']
+ interval = options.get("interval", 1)
+
+ cmd = "sudo bash cache_stat.sh %s" % (interval)
+
+ result = self._execute_command(cmd)
+ filtrated_result = self._filtrate_result(result)
+
+ return filtrated_result
+
+ def run(self, result):
+ if not self.setup_done:
+ self.setup()
+
+ result.update(self._get_cache_usage())