Skip to content

Commit

Permalink
Merge pull request #195 from con/bf-uid
Browse files Browse the repository at this point in the history
Report $USER as .user, and store actual numeric UID as .uid
  • Loading branch information
asmacdo authored Oct 2, 2024
2 parents 6b73360 + a60ce44 commit 1d4f0bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import IO, Any, Optional, TextIO

__version__ = "0.4.0"
__schema_version__ = "0.1.0"
__schema_version__ = "0.1.1"


lgr = logging.getLogger("con-duct")
Expand Down Expand Up @@ -121,10 +121,11 @@ def has_processes_samples(self) -> bool:

@dataclass
class SystemInfo:
uid: str | None
memory_total: int
cpu_total: int
memory_total: int
hostname: str | None
uid: int
user: str | None


@dataclass
Expand Down Expand Up @@ -381,12 +382,12 @@ def collect_environment(self) -> None:

def get_system_info(self) -> None:
"""Gathers system information related to CPU, GPU, memory, and environment variables."""
uid = os.environ.get("USER")
hostname = socket.gethostname()
memory_total = os.sysconf("SC_PAGESIZE") * os.sysconf("SC_PHYS_PAGES")
cpu_total = os.sysconf("SC_NPROCESSORS_CONF")
self.system_info = SystemInfo(
uid=uid, memory_total=memory_total, cpu_total=cpu_total, hostname=hostname
cpu_total=os.sysconf("SC_NPROCESSORS_CONF"),
memory_total=os.sysconf("SC_PAGESIZE") * os.sysconf("SC_PHYS_PAGES"),
hostname=socket.gethostname(),
uid=os.getuid(),
user=os.environ.get("USER"),
)
# GPU information
if shutil.which("nvidia-smi") is not None:
Expand Down
4 changes: 3 additions & 1 deletion test/test_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from datetime import datetime
import os
import subprocess
from unittest import mock
import pytest
Expand Down Expand Up @@ -193,7 +194,8 @@ def test_system_info_sanity(mock_log_paths: mock.MagicMock) -> None:
assert report.system_info.hostname
assert report.system_info.cpu_total
assert report.system_info.memory_total > 10
assert report.system_info.uid
assert report.system_info.uid == os.getuid()
assert report.system_info.user == os.environ.get("USER")


@mock.patch("con_duct.__main__.shutil.which")
Expand Down

0 comments on commit 1d4f0bc

Please sign in to comment.