From 84374b4b4e41c4bb7896092c10098b5e6b5f68c1 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 11 Sep 2019 17:59:23 +0200 Subject: explicitly collect binary versions There is no generic way to retrieve the version of a binary. Not everyone followes GNU cli guidelines and supports "--version". The larson benchmark for example reads input from stdin when started with "larson --version" blocking the Benchmark.prepare() call. --- src/benchmark.py | 1 - src/benchmarks/httpd.py | 7 +++++++ src/benchmarks/lld.py | 4 ++++ src/benchmarks/mysql.py | 5 +++++ src/benchmarks/redis.py | 2 ++ src/facter.py | 6 +++--- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/benchmark.py b/src/benchmark.py index f9b4dfd..df31068 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -193,7 +193,6 @@ class Benchmark: exe = src.util.find_cmd(r) if exe is not None: self.results["facts"]["libcs"][r] = src.facter.libc_ver(executable=exe) - self.results["facts"]["versions"][r] = src.facter.exec_ver(exe) else: raise Exception("Requirement: {} not found".format(r)) diff --git a/src/benchmarks/httpd.py b/src/benchmarks/httpd.py index 4569500..7284e2e 100644 --- a/src/benchmarks/httpd.py +++ b/src/benchmarks/httpd.py @@ -20,6 +20,7 @@ import re from src.benchmark import Benchmark +import src.facter class BenchmarkHTTPD(Benchmark): @@ -42,6 +43,12 @@ class BenchmarkHTTPD(Benchmark): super().__init__(name) + def prepare(self): + super().prepare() + + self.results["facts"]["versions"]["nginx"] = src.facter.exe_version("nginx", "-v") + self.results["facts"]["versions"]["ab"] = src.facter.exe_version("ab", "-V") + @staticmethod def process_output(result, stdout, stderr, allocator, perm): result["time"] = re.search("Time taken for tests:\\s*(\\d*\\.\\d*) seconds", stdout).group(1) diff --git a/src/benchmarks/lld.py b/src/benchmarks/lld.py index bcedced..97ef545 100644 --- a/src/benchmarks/lld.py +++ b/src/benchmarks/lld.py @@ -25,6 +25,7 @@ import sys import matplotlib.pyplot as plt from src.benchmark import Benchmark +import src.facter from src.util import download_reporthook @@ -51,6 +52,9 @@ class BenchmarkLld(Benchmark): def prepare(self): super().prepare() + # save lld version + self.results["facts"]["versions"]["lld"] = src.facter.exe_version("ld.lld", "-v") + test_dir = "lld-speed-test" test_archive = f"{test_dir}.tar.xz" if not os.path.isdir(test_dir): diff --git a/src/benchmarks/mysql.py b/src/benchmarks/mysql.py index a47873b..e71038f 100644 --- a/src/benchmarks/mysql.py +++ b/src/benchmarks/mysql.py @@ -28,6 +28,7 @@ import sys import numpy as np from src.benchmark import Benchmark +import src.facter from src.util import print_status, print_debug, print_info2 TESTDIR = os.path.join(os.getcwd(), "mysql_test") @@ -72,6 +73,10 @@ class BenchmarkMYSQL(Benchmark): def prepare(self): super().prepare() + # save mysqld and sysbench versions + for exe in self.requirements: + self.results["facts"]["versions"][exe] = src.facter.exe_version(exe, "--version") + # Setup Test Environment if not os.path.exists("mysql_test"): print_status("Prepare mysqld directory and database") diff --git a/src/benchmarks/redis.py b/src/benchmarks/redis.py index 689a9b6..0afddba 100644 --- a/src/benchmarks/redis.py +++ b/src/benchmarks/redis.py @@ -55,6 +55,8 @@ class BenchmarkRedis(Benchmark): redis_url = f"http://download.redis.io/releases/{redis_archive}" redis_dir = os.path.join(self.build_dir, f"redis-{redis_version}") + self.results["facts"]["versions"]["redis"] = redis_version + if not os.path.isdir(redis_dir): if not os.path.isfile(redis_archive): print(f"Downloading redis-{redis_version}...") diff --git a/src/facter.py b/src/facter.py index 387c75c..a1ee952 100644 --- a/src/facter.py +++ b/src/facter.py @@ -110,13 +110,13 @@ def libc_ver(executable=None): return ("glibc", glibc_version) -def exec_ver(executable): +def exe_version(executable, version_flag="--version"): """Return version of executable""" - proc = subprocess.run([executable, "--version"], + proc = subprocess.run([executable, version_flag], universal_newlines=True, stdout=subprocess.PIPE) if proc.returncode != 0: - print_error(f"failed to get version of {executable}") + print_warning(f"failed to get version of {executable}") return "" return proc.stdout[:-1] -- cgit v1.2.3