diff --git a/lib/system_checks.py b/lib/system_checks.py index 04ceaaf16..db9553b74 100644 --- a/lib/system_checks.py +++ b/lib/system_checks.py @@ -12,7 +12,6 @@ import subprocess import psutil import locale -import platform from psycopg import OperationalError as psycopg_OperationalError @@ -57,18 +56,6 @@ def check_free_disk(): def check_free_memory(): return psutil.virtual_memory().available >= GMT_Resources['free_memory'] -def check_energy_filtering(): - if platform.system() != 'Linux': - print(TerminalColors.WARNING, '>>>> RAPL could not be checked as not running on Linux platform <<<<', TerminalColors.ENDC) - return True - - result = subprocess.run(['sudo', 'python3', '-m', 'lib.hardware_info_root', '--read-rapl-energy-filtering'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - cwd=os.path.abspath(os.path.join(CURRENT_DIR, '..')), - check=True, encoding='UTF-8') - return "1" != result.stdout.strip() - def check_containers_running(): result = subprocess.run(['docker', 'ps', '--format', '{{.Names}}'], stdout=subprocess.PIPE, @@ -98,7 +85,6 @@ def check_utf_encoding(): (check_docker_daemon, Status.ERROR, 'docker daemon', 'The docker daemon could not be reached. Are you running in rootless mode or have added yourself to the docker group? See installation: [See https://docs.green-coding.io/docs/installation/]'), (check_containers_running, Status.WARN, 'running containers', 'You have other containers running on the system. This is usually what you want in local development, but for undisturbed measurements consider going for a measurement cluster [See https://docs.green-coding.io/docs/installation/installation-cluster/].'), (check_utf_encoding, Status.ERROR, 'utf file encoding', 'Your system encoding is not set to utf-8. This is needed as we need to parse console output.'), - (check_energy_filtering, Status.ERROR, 'rapl energy filtering', 'RAPL Energy filtering is active!'), ] def check_start(): diff --git a/lib/utils.py b/lib/utils.py index 8ff3103cd..7b802faa1 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -9,6 +9,8 @@ from lib import error_helpers from lib.db import DB +CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) + def get_git_api(parsed_url): if parsed_url.netloc in ['github.com', 'www.github.com']: @@ -168,3 +170,12 @@ def get_architecture(): if output == 'darwin': return 'macos' return output + + +def is_rapl_energy_filtering_deactivated(): + result = subprocess.run(['sudo', 'python3', '-m', 'lib.hardware_info_root', '--read-rapl-energy-filtering'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=os.path.abspath(os.path.join(CURRENT_DIR, '..')), + check=True, encoding='UTF-8') + return '1' != result.stdout.strip() diff --git a/metric_providers/cpu/energy/rapl/msr/component/provider.py b/metric_providers/cpu/energy/rapl/msr/component/provider.py index 889df8346..1cb829ff4 100644 --- a/metric_providers/cpu/energy/rapl/msr/component/provider.py +++ b/metric_providers/cpu/energy/rapl/msr/component/provider.py @@ -1,6 +1,7 @@ import os -from metric_providers.base import BaseMetricProvider +from metric_providers.base import BaseMetricProvider, MetricProviderConfigurationError +from lib.utils import is_rapl_energy_filtering_deactivated class CpuEnergyRaplMsrComponentProvider(BaseMetricProvider): def __init__(self, resolution, skip_check=False): @@ -13,6 +14,11 @@ def __init__(self, resolution, skip_check=False): skip_check=skip_check, ) + def check_system(self, check_command="default", check_error_message=None, check_parallel_provider=True): + super().check_system() + if not is_rapl_energy_filtering_deactivated(): + raise MetricProviderConfigurationError('RAPL energy filtering is active and might skew results!') + def read_metrics(self, run_id, containers=None): df = super().read_metrics(run_id, containers) diff --git a/metric_providers/memory/energy/rapl/msr/component/provider.py b/metric_providers/memory/energy/rapl/msr/component/provider.py index 3583f128c..506ef5aaf 100644 --- a/metric_providers/memory/energy/rapl/msr/component/provider.py +++ b/metric_providers/memory/energy/rapl/msr/component/provider.py @@ -1,6 +1,7 @@ import os -from metric_providers.base import BaseMetricProvider +from metric_providers.base import BaseMetricProvider, MetricProviderConfigurationError +from lib.utils import is_rapl_energy_filtering_deactivated class MemoryEnergyRaplMsrComponentProvider(BaseMetricProvider): def __init__(self, resolution, skip_check=False): @@ -18,6 +19,9 @@ def check_system(self, check_command="default", check_error_message=None, check_ call_string = f"{self._current_dir}/{self._metric_provider_executable}" super().check_system(check_command=[f"{call_string}", '-c', '-d']) + if not is_rapl_energy_filtering_deactivated(): + raise MetricProviderConfigurationError('RAPL energy filtering is active and might skew results!') + def read_metrics(self, run_id, containers=None): df = super().read_metrics(run_id, containers) diff --git a/metric_providers/psu/energy/dc/rapl/msr/machine/provider.py b/metric_providers/psu/energy/dc/rapl/msr/machine/provider.py index 20f12eb07..f1fc01fde 100644 --- a/metric_providers/psu/energy/dc/rapl/msr/machine/provider.py +++ b/metric_providers/psu/energy/dc/rapl/msr/machine/provider.py @@ -1,6 +1,7 @@ import os -from metric_providers.base import BaseMetricProvider +from metric_providers.base import BaseMetricProvider, MetricProviderConfigurationError +from lib.utils import is_rapl_energy_filtering_deactivated class PsuEnergyDcRaplMsrMachineProvider(BaseMetricProvider): def __init__(self, resolution, skip_check=False): @@ -18,6 +19,9 @@ def check_system(self, check_command="default", check_error_message=None, check_ call_string = f"{self._current_dir}/{self._metric_provider_executable}" super().check_system(check_command=[f"{call_string}", '-c', '-p']) + if not is_rapl_energy_filtering_deactivated(): + raise MetricProviderConfigurationError('RAPL energy filtering is active and might skew results!') + def read_metrics(self, run_id, containers=None): df = super().read_metrics(run_id, containers)