diff --git a/iprbench/autoparams.py b/iprbench/autoparams.py index bdafd19..e779f22 100644 --- a/iprbench/autoparams.py +++ b/iprbench/autoparams.py @@ -1,5 +1,8 @@ from datetime import datetime from .core import IAutoParam, BenchParam, BenchParamType +import socket +import subprocess +import re class MeasurementTime(IAutoParam): @@ -11,3 +14,46 @@ class MeasurementTime(IAutoParam): def get_value(self) -> BenchParamType: return datetime.now() + +class HostFqdn(IAutoParam): + + def __init__(self): + bench_param = BenchParam('host_fqdn', BenchParam.Type.PARAM_TYPE_STRING, 'the fully qualified domain name of the host running the benchmark') + super().__init__(bench_param) + + def get_value(self) -> BenchParamType: + return socket.getfqdn() + + +class CpuModel(IAutoParam): + + def __init__(self): + bench_param = BenchParam('cpu_model', BenchParam.Type.PARAM_TYPE_STRING, 'The exact model of the cpu running the benchmark eg "Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz"') + super().__init__(bench_param) + + @staticmethod + def model_name_to_cpu_model_id(cpu_model_name: str) -> str: + """ + cpu_model_name: the name of a cpu as seen in /proc/cpuinfo (eg 'Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz') + return: a compact identifier of the cpu model without spaces (eg 'intel_core_i5_8350u' (the frequency is implicit, as this model only operates at 1.7 Ghz)) + """ + cpu_model_id = None + match = re.match(r'Intel\(R\) Core\(TM\) i(?P[357])-(?P[0-9]+[U]) CPU @ [0-9]+\.[0-9]+GHz', cpu_model_name) + if match: + cpu_model_id = f'intel_core_i{match["major_id"]}_{match["minor_id"].lower()}' + else: + assert False, f'unhandled cpu model name: "{cpu_model_name}"' + return cpu_model_id + + def get_value(self) -> BenchParamType: + # completed_process = subprocess.run('grep "^model name +:" /proc/cpuinfo | head -1 | sed "s/model name *: //"', shell=True, check=True, capture_output=True) + completed_process = subprocess.run('grep -E "^model name\\s+:" /proc/cpuinfo', shell=True, check=False, capture_output=True) + cpu_model_lines = completed_process.stdout.decode().split('\n')[:-1] + # print(cpu_model_lines) + total_num_cores = len(cpu_model_lines) + print(f'total number of cores (including virtual cores) on this host : {total_num_cores}') + cpu_model_line = cpu_model_lines[0] # eg "model name : Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz" + match = re.match(r'model name\s+: (?P.*)$', cpu_model_line) + cpu_model = match['cpu_model'] + # print(cpu_model) + return CpuModel.model_name_to_cpu_model_id(cpu_model) diff --git a/iprbench/main.py b/iprbench/main.py index 202e932..d90b4ba 100644 --- a/iprbench/main.py +++ b/iprbench/main.py @@ -2,9 +2,10 @@ from .core import BenchmarkId, IBenchmark, ResultsDbFactory from .benchmarks.hibench import HiBench from .benchmarks.mamul1 import MaMul1 from .resultsdb.tsvresultsdb import TsvResultsDbCreator -from .resultsdb.sqlresultsdb import SqlResultsDbCreator +from .resultsdb.sqlresultsdb import SqliteResultsDbCreator, SqlServerResultsDbCreator + from .util import Singleton -from .autoparams import MeasurementTime +from .autoparams import MeasurementTime, HostFqdn, CpuModel import logging import argparse from pathlib import Path @@ -53,11 +54,15 @@ def main(): results_dir = args.results_dir ResultsDbFactory().register_resultsdb_creator(TsvResultsDbCreator()) - ResultsDbFactory().register_resultsdb_creator(SqlResultsDbCreator()) + ResultsDbFactory().register_resultsdb_creator(SqliteResultsDbCreator()) + ResultsDbFactory().register_resultsdb_creator(SqlServerResultsDbCreator()) resultsdb_params = json.loads(args.resultsdb_params) results_db = ResultsDbFactory().create_resultsdb(resultsdb_params['type'], resultsdb_params) results_db.add_auto_param(MeasurementTime()) + results_db.add_auto_param(HostFqdn()) + results_db.add_auto_param(CpuModel()) + results_table = results_db.get_table(benchmark) measurements = benchmark.execute(benchmark_config, results_dir)