From 8dc3ae4fbd33591dc1e4a00161ea5ef1cd53e976 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Wed, 22 Jan 2025 12:02:22 -0500 Subject: [PATCH] benchmark: Add option to control the taskset used for the command Change-Id: Ibf13d6ff0f74adc298cd2129c8960da2ba64f5e8 Signed-off-by: Kienan Stewart --- scripts/babeltrace-benchmark/time.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/babeltrace-benchmark/time.py diff --git a/scripts/babeltrace-benchmark/time.py b/scripts/babeltrace-benchmark/time.py old mode 100644 new mode 100755 index c7f7505..0c414f1 --- a/scripts/babeltrace-benchmark/time.py +++ b/scripts/babeltrace-benchmark/time.py @@ -106,7 +106,7 @@ def save(path, results): json.dump(results, out, sort_keys=True, indent=4) -def run(command, iteration, output, stdout, stderr): +def run(command, iteration, output, stdout, stderr, taskset=""): """ Run the command throught /usr/bin/time n iterations and parse each result. """ @@ -117,6 +117,8 @@ def run(command, iteration, output, stdout, stderr): time_stdout.close() with open(stdout, "a+") as out, open(stderr, "a+") as err: cmd = "/usr/bin/time -v --output='{}' {}".format(time_stdout.name, command) + if taskset: + cmd = "taskset -c {} {}".format(taskset, cmd) ret = subprocess.run(cmd, shell=True, stdout=out, stderr=err) if ret.returncode != 0: print("Iteration: {}, Command failed: {}".format(str(i), cmd)) @@ -176,9 +178,21 @@ def main(): default=os.path.join(os.getcwd(), "stderr.out"), help="Where to append the stderr of each command (default: $CWD/stderr.out)", ) + parser.add_argument( + "--taskset", + default="", + help="Define a CPU taskset for the test command. See `man taskset`'s `-c` argument", + ) args = parser.parse_args() - run(args.command, args.iteration, args.output, args.stdout, args.stderr) + run( + args.command, + args.iteration, + args.output, + args.stdout, + args.stderr, + args.taskset, + ) if __name__ == "__main__": -- 2.39.5