Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/hpc_eff/utils/command_runner.py

This file was deleted.

16 changes: 1 addition & 15 deletions src/hpc_eff/utils/cpu_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,10 @@
import time
import requests
from .set_cpu import log_setting, logger
from .command_runner import run_command
from .system_utils import run_command, read_temperature
from .frequency_reader import get_cpu_max_frequency, freq_to_khz, get_cpu_count


def read_temperature(sensor_name: str) -> int | None:
"""Try to read temperature via ipmitool sensor reading. Return integer Celsius or None."""
try:
out = run_command(f'ipmitool sensor reading "{sensor_name}" 2>/dev/null')
if not out:
return None
m = re.search(r"\d+", out)
if not m:
return None
return int(m.group(0))
except Exception:
return None


def apply_cpu_thermo(conn=None, log_context=None, config=None):
"""Apply temperature-based CPU max-frequency settings.

Expand Down
2 changes: 1 addition & 1 deletion src/hpc_eff/utils/frequency_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import shutil
import glob
from .command_runner import run_command
from .system_utils import run_command


def freq_to_khz(freq_str: str) -> int:
Expand Down
2 changes: 1 addition & 1 deletion src/hpc_eff/utils/get_available_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import glob
import shutil
from .command_runner import run_command
from .system_utils import run_command


def get_available_frequencies():
Expand Down
36 changes: 36 additions & 0 deletions src/hpc_eff/utils/system_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
General system utilities: centralized command execution and hardware sensors.
"""
import subprocess
import re
from typing import Optional


def run_command(cmd: str) -> str:
"""Execute a shell command and return its stdout (stripped).

Args:
cmd: Shell command to execute

Returns:
Command stdout (stripped)
"""
result = subprocess.run(cmd, capture_output=True, text=True, shell=True)
return result.stdout.strip()


def read_temperature(sensor_name: str) -> Optional[int]:
"""Try to read temperature via `ipmitool sensor reading`.

Returns integer Celsius on success or None on failure.
"""
try:
out = run_command(f'ipmitool sensor reading "{sensor_name}" 2>/dev/null')
if not out:
return None
m = re.search(r"\d+", out)
if not m:
return None
return int(m.group(0))
except Exception:
return None