[PATCH 1/3] fsperf: add a few helper functions
From: Anand Jain <hidden>
Date: 2021-11-12 08:05:05
Subsystem:
the rest · Maintainer:
Linus Torvalds
This is in preparation to add read policy benchmarking add the following helpes get_fstype get_fsid get_readpolicies get_active_readpolicy set_readpolicy Signed-off-by: Anand Jain <redacted> --- src/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/src/utils.py b/src/utils.py
index 5629894ce1fb..a7f0f1baf448 100644
--- a/src/utils.py
+++ b/src/utils.py@@ -8,6 +8,8 @@ import itertools import numbers import datetime import statistics +import subprocess +import re LOWER_IS_BETTER = 0 HIGHER_IS_BETTER = 1
@@ -230,3 +232,46 @@ def print_comparison_table(baseline, results): table_rows.append(cur) table.add_rows(table_rows) print(table.draw()) + +def get_fstype(device): + fstype = subprocess.check_output("blkid -s TYPE -o value "+device, shell=True) + # strip the output b'btrfs\n' + return (str(fstype).removesuffix("\\n'")).removeprefix("b'") + +def get_fsid(device): + fsid = subprocess.check_output("blkid -s UUID -o value "+device, shell=True) + # Raw output is something like this + # b'abcf123f-7e95-40cd-8322-0d32773cb4ec\n' + # strip off extra characters. + return str(fsid)[2:38] + +def get_readpolicies(device): + fsid = get_fsid(device) + sysfs = open("/sys/fs/btrfs/"+fsid+"/read_policy", "r") + # Strip '[ ]' around the active policy + policies = (((sysfs.read()).strip()).strip("[")).strip("]") + sysfs.close() + return policies + +def get_active_readpolicy(device): + fsid = get_fsid(device) + sysfs = open("/sys/fs/btrfs/"+fsid+"/read_policy", "r") + policies = (sysfs.read()).strip() + # Output is as below, pick the policy within '[ ]' + # device [pid] latency + active = re.search(r"\[([A-Za-z0-9_]+)\]", policies) + sysfs.close() + return active.group(1) + +def set_readpolicy(device, policy="pid"): + if not policy in get_readpolicies(device): + print("Policy '{}' is invalid".format(policy)) + sys.exit(1) + return + fsid = get_fsid(device) + # Ran out of ideas why run_command fails. + # command = "echo "+policy+" > /sys/fs/btrfs/"+fsid+"/read_policy" + # run_command(command) + sysfs = open("/sys/fs/btrfs/"+fsid+"/read_policy", "w") + ret = sysfs.write(policy) + sysfs.close()
--
2.33.1