added autoparams `host_fqdn` and `cpu_model`

these parameters are very much needed as they allow to identify the system on which the benchmark is run. Each performance benchmark highly depends on the host it's run on.

work rleated to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=3958]
This commit is contained in:
Guillaume Raffy 2024-11-08 09:12:51 +01:00
parent 2ee1988721
commit ca1f4c1a88
2 changed files with 54 additions and 3 deletions

View File

@ -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<major_id>[357])-(?P<minor_id>[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>.*)$', cpu_model_line)
cpu_model = match['cpu_model']
# print(cpu_model)
return CpuModel.model_name_to_cpu_model_id(cpu_model)

View File

@ -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)