From 3d8a0ff4adb63216fb61826d129298d5699e178b Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Wed, 13 Nov 2024 17:42:01 +0100 Subject: [PATCH] added the following automatic parameters (parameters common to all benchmarks): - host_id (host serial number) - num_cpus - iprbench_version (took inspiration from [https://git.ipr.univ-rennes.fr/cellinfo/maco/src/branch/main/Libs/Benchmark.bash]) work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=3958] --- iprbench/autoparams.py | 39 +++++++++++++++++++++++++++++++++++++++ iprbench/main.py | 9 ++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/iprbench/autoparams.py b/iprbench/autoparams.py index e779f22..f4cafc7 100644 --- a/iprbench/autoparams.py +++ b/iprbench/autoparams.py @@ -1,5 +1,6 @@ from datetime import datetime from .core import IAutoParam, BenchParam, BenchParamType +from .main import __version__ as iprbench_version import socket import subprocess import re @@ -15,6 +16,30 @@ class MeasurementTime(IAutoParam): return datetime.now() +class IprBenchVersion(IAutoParam): + + def __init__(self): + bench_param = BenchParam('ipr_bench_version', BenchParam.Type.PARAM_TYPE_STRING, 'the version of iprbench used for this measurement') + super().__init__(bench_param) + + def get_value(self) -> BenchParamType: + return iprbench_version + + +class HostId(IAutoParam): + + def __init__(self): + bench_param = BenchParam('host_id', BenchParam.Type.PARAM_TYPE_STRING, 'the serial number of the host running the benchmark') + super().__init__(bench_param) + + def get_value(self) -> BenchParamType: + serial_number = '' + completed_process = subprocess.run(r"dmidecode | grep -A4 '^System Information' | grep 'Serial Number' | sed 's/^\s*Serial Number: //'; exit $PIPESTATUS[0]", check=False, shell=True, capture_output=True) + if completed_process.returncode == 0: + serial_number = completed_process.stdout.decode(encoding='utf-8').split('\n')[0] + return serial_number + + class HostFqdn(IAutoParam): def __init__(self): @@ -25,6 +50,20 @@ class HostFqdn(IAutoParam): return socket.getfqdn() +class NumCpus(IAutoParam): + + def __init__(self): + bench_param = BenchParam('num_cpus', BenchParam.Type.PARAM_TYPE_INT, 'the number of cpus on the benchmarked system') + super().__init__(bench_param) + + def get_value(self) -> BenchParamType: + num_cpus = 0 + completed_process = subprocess.run(r"cat /proc/cpuinfo | awk 'BEGIN { maxid=0; } /^physical id/ {if ($4 > maxid) { maxid = $4 };} END {print maxid+1;}'", check=False, shell=True, capture_output=True) + if completed_process.returncode == 0: + num_cpus = int(completed_process.stdout.decode(encoding='utf-8').split('\n')[0]) + return num_cpus + + class CpuModel(IAutoParam): def __init__(self): diff --git a/iprbench/main.py b/iprbench/main.py index d90b4ba..48a0827 100644 --- a/iprbench/main.py +++ b/iprbench/main.py @@ -1,3 +1,5 @@ +__version__ = '0.0.1' + from .core import BenchmarkId, IBenchmark, ResultsDbFactory from .benchmarks.hibench import HiBench from .benchmarks.mamul1 import MaMul1 @@ -5,14 +7,12 @@ from .resultsdb.tsvresultsdb import TsvResultsDbCreator from .resultsdb.sqlresultsdb import SqliteResultsDbCreator, SqlServerResultsDbCreator from .util import Singleton -from .autoparams import MeasurementTime, HostFqdn, CpuModel +from .autoparams import MeasurementTime, HostFqdn, NumCpus, CpuModel, IprBenchVersion, HostId import logging import argparse from pathlib import Path import json -__version__ = '0.0.1' - class BenchmarkFactory(metaclass=Singleton): @@ -60,7 +60,10 @@ def main(): results_db = ResultsDbFactory().create_resultsdb(resultsdb_params['type'], resultsdb_params) results_db.add_auto_param(MeasurementTime()) + results_db.add_auto_param(IprBenchVersion()) + results_db.add_auto_param(HostId()) results_db.add_auto_param(HostFqdn()) + results_db.add_auto_param(NumCpus()) results_db.add_auto_param(CpuModel()) results_table = results_db.get_table(benchmark)