nvclocktop 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gpu_clock/__init__.py +5 -0
- gpu_clock/__main__.py +5 -0
- gpu_clock/app.py +130 -0
- gpu_clock/cli.py +55 -0
- gpu_clock/cpu.py +91 -0
- gpu_clock/figlet.py +64 -0
- gpu_clock/fonts/README.md +7 -0
- gpu_clock/gpu.py +258 -0
- gpu_clock/layout.py +346 -0
- gpu_clock/theme.py +66 -0
- nvclocktop-1.0.0.dist-info/METADATA +178 -0
- nvclocktop-1.0.0.dist-info/RECORD +15 -0
- nvclocktop-1.0.0.dist-info/WHEEL +4 -0
- nvclocktop-1.0.0.dist-info/entry_points.txt +2 -0
- nvclocktop-1.0.0.dist-info/licenses/LICENSE +21 -0
gpu_clock/__init__.py
ADDED
gpu_clock/__main__.py
ADDED
gpu_clock/app.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from contextlib import contextmanager, nullcontext
|
|
5
|
+
import select
|
|
6
|
+
import sys
|
|
7
|
+
import termios
|
|
8
|
+
import time
|
|
9
|
+
import tty
|
|
10
|
+
from typing import TextIO
|
|
11
|
+
|
|
12
|
+
from rich.align import Align
|
|
13
|
+
from rich.console import Console
|
|
14
|
+
from rich.live import Live
|
|
15
|
+
|
|
16
|
+
from gpu_clock.cpu import collect_cpu_info
|
|
17
|
+
from gpu_clock.gpu import collect_gpu_info
|
|
18
|
+
from gpu_clock.layout import build_snapshot
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
QUIT_KEY = "quit"
|
|
22
|
+
HELP_KEY = "help"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def run_app(args: argparse.Namespace) -> int:
|
|
26
|
+
console = Console()
|
|
27
|
+
if args.once:
|
|
28
|
+
console.print(_build_current_snapshot(args, console=console))
|
|
29
|
+
return 0
|
|
30
|
+
|
|
31
|
+
refresh = _refresh_interval(args.refresh)
|
|
32
|
+
show_help = False
|
|
33
|
+
try:
|
|
34
|
+
with _terminal_cbreak(sys.stdin):
|
|
35
|
+
with Live(
|
|
36
|
+
_build_live_snapshot(args, console, show_help=show_help),
|
|
37
|
+
console=console,
|
|
38
|
+
refresh_per_second=max(1, int(1 / refresh)),
|
|
39
|
+
screen=True,
|
|
40
|
+
transient=False,
|
|
41
|
+
) as live:
|
|
42
|
+
while True:
|
|
43
|
+
tick_started = time.monotonic()
|
|
44
|
+
live.update(_build_live_snapshot(args, console, show_help=show_help), refresh=True)
|
|
45
|
+
action = _wait_for_next_tick_or_key(sys.stdin, tick_started, refresh)
|
|
46
|
+
if action == QUIT_KEY:
|
|
47
|
+
return 0
|
|
48
|
+
if action == HELP_KEY:
|
|
49
|
+
show_help = not show_help
|
|
50
|
+
except KeyboardInterrupt:
|
|
51
|
+
return 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _build_current_snapshot(
|
|
55
|
+
args: argparse.Namespace,
|
|
56
|
+
console: Console | None = None,
|
|
57
|
+
show_help: bool = False,
|
|
58
|
+
):
|
|
59
|
+
cpu_info = None if args.no_cpu else collect_cpu_info()
|
|
60
|
+
gpu_info = collect_gpu_info(include_processes=False)
|
|
61
|
+
terminal_width = console.size.width if console else None
|
|
62
|
+
terminal_height = console.size.height if console else None
|
|
63
|
+
return build_snapshot(
|
|
64
|
+
args=args,
|
|
65
|
+
cpu_info=cpu_info,
|
|
66
|
+
gpu_info=gpu_info,
|
|
67
|
+
show_help=show_help,
|
|
68
|
+
terminal_width=terminal_width,
|
|
69
|
+
terminal_height=terminal_height,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _build_live_snapshot(args: argparse.Namespace, console: Console, show_help: bool = False):
|
|
74
|
+
return Align.center(
|
|
75
|
+
_build_current_snapshot(args, console=console, show_help=show_help),
|
|
76
|
+
vertical="middle",
|
|
77
|
+
height=console.size.height,
|
|
78
|
+
width=console.size.width,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _refresh_interval(value: float) -> float:
|
|
83
|
+
if value <= 0:
|
|
84
|
+
return 1.0
|
|
85
|
+
return max(0.1, value)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _wait_for_next_tick_or_key(stdin: TextIO, tick_started: float, refresh: float) -> str | None:
|
|
89
|
+
while True:
|
|
90
|
+
action = _read_action(stdin)
|
|
91
|
+
if action is not None:
|
|
92
|
+
return action
|
|
93
|
+
remaining = refresh - (time.monotonic() - tick_started)
|
|
94
|
+
if remaining <= 0:
|
|
95
|
+
return None
|
|
96
|
+
time.sleep(min(remaining, 0.05))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _read_action(stdin: TextIO) -> str | None:
|
|
100
|
+
if not stdin.isatty():
|
|
101
|
+
return None
|
|
102
|
+
readable, _, _ = select.select([stdin], [], [], 0)
|
|
103
|
+
if not readable:
|
|
104
|
+
return None
|
|
105
|
+
return _key_action(stdin.read(1))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _key_action(key: str) -> str | None:
|
|
109
|
+
normalized = key.lower()
|
|
110
|
+
if normalized == "q":
|
|
111
|
+
return QUIT_KEY
|
|
112
|
+
if normalized == "h":
|
|
113
|
+
return HELP_KEY
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@contextmanager
|
|
118
|
+
def _terminal_cbreak(stdin: TextIO):
|
|
119
|
+
if not stdin.isatty():
|
|
120
|
+
with nullcontext():
|
|
121
|
+
yield
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
file_descriptor = stdin.fileno()
|
|
125
|
+
previous_settings = termios.tcgetattr(file_descriptor)
|
|
126
|
+
try:
|
|
127
|
+
tty.setcbreak(file_descriptor)
|
|
128
|
+
yield
|
|
129
|
+
finally:
|
|
130
|
+
termios.tcsetattr(file_descriptor, termios.TCSADRAIN, previous_settings)
|
gpu_clock/cli.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from gpu_clock.app import run_app
|
|
6
|
+
from gpu_clock.figlet import FONT_PRESETS
|
|
7
|
+
from gpu_clock.theme import THEME_PRESETS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="nvclocktop",
|
|
13
|
+
description="Fullscreen terminal clock and GPU dashboard.",
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument("--refresh", type=float, default=1.0, help="Refresh interval in seconds.")
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"--font",
|
|
18
|
+
choices=FONT_PRESETS,
|
|
19
|
+
default="terrace",
|
|
20
|
+
help="Clock FIGlet font preset.",
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--theme",
|
|
24
|
+
choices=THEME_PRESETS,
|
|
25
|
+
default="rainbow",
|
|
26
|
+
help="Clock color theme preset.",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument("--clock", choices=["12h", "24h"], default="12h", help="Clock format.")
|
|
29
|
+
seconds = parser.add_mutually_exclusive_group()
|
|
30
|
+
seconds.add_argument(
|
|
31
|
+
"--show-seconds",
|
|
32
|
+
dest="show_seconds",
|
|
33
|
+
action="store_true",
|
|
34
|
+
default=True,
|
|
35
|
+
help="Show seconds in the clock.",
|
|
36
|
+
)
|
|
37
|
+
seconds.add_argument(
|
|
38
|
+
"--hide-seconds",
|
|
39
|
+
dest="show_seconds",
|
|
40
|
+
action="store_false",
|
|
41
|
+
help="Hide seconds in the clock.",
|
|
42
|
+
)
|
|
43
|
+
parser.add_argument("--no-cpu", action="store_true", help="Hide the CPU panel.")
|
|
44
|
+
parser.add_argument("--no-processes", action="store_true", help="Hide the GPU process table.")
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--once",
|
|
47
|
+
action="store_true",
|
|
48
|
+
help="Render one snapshot and exit. Useful during early development and tests.",
|
|
49
|
+
)
|
|
50
|
+
return parser
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main(argv: list[str] | None = None) -> int:
|
|
54
|
+
args = build_parser().parse_args(argv)
|
|
55
|
+
return run_app(args)
|
gpu_clock/cpu.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import os
|
|
5
|
+
import platform
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
import psutil
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class CpuInfo:
|
|
13
|
+
model: str
|
|
14
|
+
usage_percent: float
|
|
15
|
+
per_cpu_percent: list[float]
|
|
16
|
+
memory_used_gib: float
|
|
17
|
+
memory_total_gib: float
|
|
18
|
+
load_average: tuple[float, float, float] | None
|
|
19
|
+
thread_count: int
|
|
20
|
+
frequency_ghz: float | None
|
|
21
|
+
temperature_c: float | None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def collect_cpu_info() -> CpuInfo:
|
|
25
|
+
memory = psutil.virtual_memory()
|
|
26
|
+
frequency = psutil.cpu_freq()
|
|
27
|
+
return CpuInfo(
|
|
28
|
+
model=_cpu_model(),
|
|
29
|
+
usage_percent=psutil.cpu_percent(interval=None),
|
|
30
|
+
per_cpu_percent=psutil.cpu_percent(interval=None, percpu=True),
|
|
31
|
+
memory_used_gib=(memory.total - memory.available) / 1024**3,
|
|
32
|
+
memory_total_gib=memory.total / 1024**3,
|
|
33
|
+
load_average=_load_average(),
|
|
34
|
+
thread_count=psutil.cpu_count(logical=True) or 0,
|
|
35
|
+
frequency_ghz=(frequency.current / 1000) if frequency else None,
|
|
36
|
+
temperature_c=_cpu_temperature(),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _cpu_model() -> str:
|
|
41
|
+
if platform.system() == "Darwin":
|
|
42
|
+
return _mac_cpu_model()
|
|
43
|
+
if platform.system() != "Linux":
|
|
44
|
+
return platform.processor() or platform.machine() or "Unknown CPU"
|
|
45
|
+
try:
|
|
46
|
+
with open("/proc/cpuinfo", encoding="utf-8") as cpuinfo:
|
|
47
|
+
for line in cpuinfo:
|
|
48
|
+
if line.startswith("model name"):
|
|
49
|
+
return line.split(":", 1)[1].strip()
|
|
50
|
+
except OSError:
|
|
51
|
+
pass
|
|
52
|
+
return platform.processor() or "Unknown CPU"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _mac_cpu_model() -> str:
|
|
56
|
+
try:
|
|
57
|
+
result = subprocess.run(
|
|
58
|
+
["sysctl", "-n", "machdep.cpu.brand_string"],
|
|
59
|
+
check=False,
|
|
60
|
+
capture_output=True,
|
|
61
|
+
text=True,
|
|
62
|
+
timeout=1,
|
|
63
|
+
)
|
|
64
|
+
except (OSError, subprocess.SubprocessError, TimeoutError):
|
|
65
|
+
result = None
|
|
66
|
+
if result and result.returncode == 0 and result.stdout.strip():
|
|
67
|
+
return result.stdout.strip()
|
|
68
|
+
return platform.processor() or platform.machine() or "Apple Silicon"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _load_average() -> tuple[float, float, float] | None:
|
|
72
|
+
try:
|
|
73
|
+
return os.getloadavg()
|
|
74
|
+
except OSError:
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _cpu_temperature() -> float | None:
|
|
79
|
+
try:
|
|
80
|
+
temperatures = psutil.sensors_temperatures()
|
|
81
|
+
except (AttributeError, OSError):
|
|
82
|
+
return None
|
|
83
|
+
for entries in temperatures.values():
|
|
84
|
+
for entry in entries:
|
|
85
|
+
label = (entry.label or "").lower()
|
|
86
|
+
if "cpu" in label or "package" in label or "core" in label:
|
|
87
|
+
return float(entry.current)
|
|
88
|
+
for entries in temperatures.values():
|
|
89
|
+
if entries:
|
|
90
|
+
return float(entries[0].current)
|
|
91
|
+
return None
|
gpu_clock/figlet.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
|
|
5
|
+
import pyfiglet
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
FONT_PRESETS = ("terrace", "big", "standard", "slant", "chunky")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def render_time(value: str, font: str = "terrace") -> str:
|
|
12
|
+
normalized = _normalize_font(font)
|
|
13
|
+
try:
|
|
14
|
+
return _fixed_width_figlet(value, normalized)
|
|
15
|
+
except pyfiglet.FontNotFound:
|
|
16
|
+
return _fixed_width_figlet(value, "big")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _fixed_width_figlet(value: str, font: str) -> str:
|
|
20
|
+
rendered_chars = [_render_char(char, font) for char in value]
|
|
21
|
+
height = max((len(lines) for lines in rendered_chars), default=0)
|
|
22
|
+
output_lines = []
|
|
23
|
+
|
|
24
|
+
for line_index in range(height):
|
|
25
|
+
parts = []
|
|
26
|
+
for char, lines in zip(value, rendered_chars):
|
|
27
|
+
cell_width = _cell_width(char, font)
|
|
28
|
+
line = lines[line_index] if line_index < len(lines) else ""
|
|
29
|
+
parts.append(line.ljust(cell_width))
|
|
30
|
+
output_lines.append("".join(parts).rstrip())
|
|
31
|
+
|
|
32
|
+
return "\n".join(output_lines)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@lru_cache(maxsize=None)
|
|
36
|
+
def _render_char(char: str, font: str) -> tuple[str, ...]:
|
|
37
|
+
lines = [line.rstrip() for line in pyfiglet.figlet_format(char, font=font, width=200).splitlines()]
|
|
38
|
+
while lines and not lines[-1]:
|
|
39
|
+
lines.pop()
|
|
40
|
+
return tuple(lines)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@lru_cache(maxsize=None)
|
|
44
|
+
def _cell_width(char: str, font: str) -> int:
|
|
45
|
+
if char.isdigit():
|
|
46
|
+
return _max_char_width("0123456789", font)
|
|
47
|
+
if char in ":":
|
|
48
|
+
return _max_char_width(":", font)
|
|
49
|
+
if char == " ":
|
|
50
|
+
return _max_char_width(" ", font)
|
|
51
|
+
if char.upper() in "APM":
|
|
52
|
+
return _max_char_width("APM", font)
|
|
53
|
+
return max((len(line) for line in _render_char(char, font)), default=1)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@lru_cache(maxsize=None)
|
|
57
|
+
def _max_char_width(chars: str, font: str) -> int:
|
|
58
|
+
return max(max((len(line) for line in _render_char(char, font)), default=1) for char in chars)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _normalize_font(font: str) -> str:
|
|
62
|
+
if font.lower() == "terrace":
|
|
63
|
+
return "ansi_shadow"
|
|
64
|
+
return font
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Fonts
|
|
2
|
+
|
|
3
|
+
The planned default time face is `Terrace`.
|
|
4
|
+
|
|
5
|
+
If PyPI packaging or runtime environments cannot reliably access the pyfiglet-provided Terrace font, the project should vendor the compatible FIGlet `.flf` file here and load it explicitly.
|
|
6
|
+
|
|
7
|
+
Do not add font files without checking their license.
|
gpu_clock/gpu.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import csv
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import pwd
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
|
|
13
|
+
import psutil
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class GpuSummary:
|
|
18
|
+
name: str
|
|
19
|
+
utilization_percent: float | None
|
|
20
|
+
memory_used_mib: float | None
|
|
21
|
+
memory_total_mib: float | None
|
|
22
|
+
temperature_c: float | None
|
|
23
|
+
power_draw_w: float | None
|
|
24
|
+
power_limit_w: float | None
|
|
25
|
+
fan_percent: float | None
|
|
26
|
+
driver_version: str | None
|
|
27
|
+
backend: str = "NVIDIA"
|
|
28
|
+
core_count: int | None = None
|
|
29
|
+
memory_label: str = "Memory"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class GpuProcess:
|
|
34
|
+
pid: int
|
|
35
|
+
process_name: str
|
|
36
|
+
used_memory_mib: float | None
|
|
37
|
+
user: str | None = None
|
|
38
|
+
command: str | None = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class GpuInfo:
|
|
43
|
+
available: bool
|
|
44
|
+
error: str | None
|
|
45
|
+
gpus: list[GpuSummary]
|
|
46
|
+
processes: list[GpuProcess]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def collect_gpu_info(include_processes: bool = True) -> GpuInfo:
|
|
50
|
+
if platform.system() == "Darwin":
|
|
51
|
+
return collect_apple_gpu_info()
|
|
52
|
+
|
|
53
|
+
if shutil.which("nvidia-smi") is None:
|
|
54
|
+
return GpuInfo(
|
|
55
|
+
available=False,
|
|
56
|
+
error="nvidia-smi not found. NVIDIA GPU support requires NVIDIA drivers.",
|
|
57
|
+
gpus=[],
|
|
58
|
+
processes=[],
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
gpus = query_gpu_summary()
|
|
63
|
+
processes = query_gpu_processes() if include_processes else []
|
|
64
|
+
except subprocess.SubprocessError as exc:
|
|
65
|
+
return GpuInfo(available=False, error=str(exc), gpus=[], processes=[])
|
|
66
|
+
|
|
67
|
+
return GpuInfo(available=True, error=None, gpus=gpus, processes=processes)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def collect_apple_gpu_info() -> GpuInfo:
|
|
71
|
+
try:
|
|
72
|
+
gpus = query_apple_gpu_summary()
|
|
73
|
+
except subprocess.SubprocessError as exc:
|
|
74
|
+
return GpuInfo(available=False, error=str(exc), gpus=[], processes=[])
|
|
75
|
+
return GpuInfo(available=bool(gpus), error=None if gpus else "Apple GPU not detected.", gpus=gpus, processes=[])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def query_apple_gpu_summary() -> list[GpuSummary]:
|
|
79
|
+
output = subprocess.run(
|
|
80
|
+
["system_profiler", "SPDisplaysDataType", "-json"],
|
|
81
|
+
check=False,
|
|
82
|
+
capture_output=True,
|
|
83
|
+
text=True,
|
|
84
|
+
timeout=5,
|
|
85
|
+
)
|
|
86
|
+
if output.returncode != 0:
|
|
87
|
+
raise subprocess.CalledProcessError(
|
|
88
|
+
output.returncode,
|
|
89
|
+
output.args,
|
|
90
|
+
output.stdout,
|
|
91
|
+
output.stderr,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
memory = psutil.virtual_memory()
|
|
95
|
+
entries = json.loads(output.stdout).get("SPDisplaysDataType", [])
|
|
96
|
+
summaries = []
|
|
97
|
+
for entry in entries:
|
|
98
|
+
name = entry.get("sppci_model") or entry.get("_name") or "Apple GPU"
|
|
99
|
+
cores = _int_text(entry.get("sppci_cores"))
|
|
100
|
+
metal = _metal_version(entry.get("spdisplays_mtlgpufamilysupport"))
|
|
101
|
+
summaries.append(
|
|
102
|
+
GpuSummary(
|
|
103
|
+
name=name,
|
|
104
|
+
utilization_percent=None,
|
|
105
|
+
memory_used_mib=(memory.total - memory.available) / 1024**2,
|
|
106
|
+
memory_total_mib=memory.total / 1024**2,
|
|
107
|
+
temperature_c=None,
|
|
108
|
+
power_draw_w=None,
|
|
109
|
+
power_limit_w=None,
|
|
110
|
+
fan_percent=None,
|
|
111
|
+
driver_version=metal,
|
|
112
|
+
backend="Apple",
|
|
113
|
+
core_count=cores,
|
|
114
|
+
memory_label="Unified Memory",
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
return summaries
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def query_gpu_summary() -> list[GpuSummary]:
|
|
121
|
+
output = _run_nvidia_smi(
|
|
122
|
+
[
|
|
123
|
+
"--query-gpu=name,utilization.gpu,memory.used,memory.total,temperature.gpu,"
|
|
124
|
+
"power.draw,power.limit,fan.speed,driver_version",
|
|
125
|
+
"--format=csv,noheader,nounits",
|
|
126
|
+
]
|
|
127
|
+
)
|
|
128
|
+
rows = _parse_csv_lines(output)
|
|
129
|
+
return [_gpu_summary_from_row(row) for row in rows if row]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def query_gpu_processes() -> list[GpuProcess]:
|
|
133
|
+
output = _run_nvidia_smi(
|
|
134
|
+
[
|
|
135
|
+
"--query-compute-apps=pid,process_name,used_memory",
|
|
136
|
+
"--format=csv,noheader,nounits",
|
|
137
|
+
],
|
|
138
|
+
allow_empty=True,
|
|
139
|
+
)
|
|
140
|
+
rows = _parse_csv_lines(output)
|
|
141
|
+
return [_gpu_process_from_row(row) for row in rows if len(row) >= 3]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _run_nvidia_smi(args: list[str], allow_empty: bool = False) -> str:
|
|
145
|
+
result = subprocess.run(
|
|
146
|
+
["nvidia-smi", *args],
|
|
147
|
+
check=False,
|
|
148
|
+
capture_output=True,
|
|
149
|
+
text=True,
|
|
150
|
+
timeout=3,
|
|
151
|
+
)
|
|
152
|
+
if result.returncode != 0 and not allow_empty:
|
|
153
|
+
raise subprocess.CalledProcessError(result.returncode, result.args, result.stdout, result.stderr)
|
|
154
|
+
if result.returncode != 0 and allow_empty:
|
|
155
|
+
return ""
|
|
156
|
+
return result.stdout.strip()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _parse_csv_lines(output: str) -> list[list[str]]:
|
|
160
|
+
if not output:
|
|
161
|
+
return []
|
|
162
|
+
return [[cell.strip() for cell in row] for row in csv.reader(output.splitlines())]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _gpu_summary_from_row(row: list[str]) -> GpuSummary:
|
|
166
|
+
return GpuSummary(
|
|
167
|
+
name=_text(row, 0, "Unknown NVIDIA GPU"),
|
|
168
|
+
utilization_percent=_number(row, 1),
|
|
169
|
+
memory_used_mib=_number(row, 2),
|
|
170
|
+
memory_total_mib=_number(row, 3),
|
|
171
|
+
temperature_c=_number(row, 4),
|
|
172
|
+
power_draw_w=_number(row, 5),
|
|
173
|
+
power_limit_w=_number(row, 6),
|
|
174
|
+
fan_percent=_number(row, 7),
|
|
175
|
+
driver_version=_optional_text(row, 8),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _gpu_process_from_row(row: list[str]) -> GpuProcess:
|
|
180
|
+
pid = int(_number(row, 0) or 0)
|
|
181
|
+
return GpuProcess(
|
|
182
|
+
pid=pid,
|
|
183
|
+
process_name=_text(row, 1, "unknown"),
|
|
184
|
+
used_memory_mib=_number(row, 2),
|
|
185
|
+
user=_process_user(pid),
|
|
186
|
+
command=_process_command(pid),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _process_user(pid: int) -> str | None:
|
|
191
|
+
try:
|
|
192
|
+
stat_info = os.stat(f"/proc/{pid}")
|
|
193
|
+
except OSError:
|
|
194
|
+
return None
|
|
195
|
+
try:
|
|
196
|
+
return pwd.getpwuid(stat_info.st_uid).pw_name
|
|
197
|
+
except KeyError:
|
|
198
|
+
return str(stat_info.st_uid)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _process_command(pid: int) -> str | None:
|
|
202
|
+
proc_path = Path(f"/proc/{pid}")
|
|
203
|
+
try:
|
|
204
|
+
command = proc_path.joinpath("cmdline").read_text(encoding="utf-8", errors="replace")
|
|
205
|
+
except OSError:
|
|
206
|
+
command = ""
|
|
207
|
+
command = " ".join(part for part in command.split("\0") if part).strip()
|
|
208
|
+
if command:
|
|
209
|
+
return command
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
return proc_path.joinpath("comm").read_text(encoding="utf-8", errors="replace").strip()
|
|
213
|
+
except OSError:
|
|
214
|
+
return None
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _number(row: list[str], index: int) -> float | None:
|
|
218
|
+
if index >= len(row):
|
|
219
|
+
return None
|
|
220
|
+
value = row[index].strip()
|
|
221
|
+
if not value or value.upper() == "N/A":
|
|
222
|
+
return None
|
|
223
|
+
try:
|
|
224
|
+
return float(value)
|
|
225
|
+
except ValueError:
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _text(row: list[str], index: int, fallback: str) -> str:
|
|
230
|
+
value = _optional_text(row, index)
|
|
231
|
+
return value or fallback
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _optional_text(row: list[str], index: int) -> str | None:
|
|
235
|
+
if index >= len(row):
|
|
236
|
+
return None
|
|
237
|
+
value = row[index].strip()
|
|
238
|
+
if not value or value.upper() == "N/A":
|
|
239
|
+
return None
|
|
240
|
+
return value
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _int_text(value: object) -> int | None:
|
|
244
|
+
try:
|
|
245
|
+
return int(str(value))
|
|
246
|
+
except (TypeError, ValueError):
|
|
247
|
+
return None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _metal_version(value: object) -> str | None:
|
|
251
|
+
text = str(value or "").lower()
|
|
252
|
+
if "metal3" in text:
|
|
253
|
+
return "Metal 3"
|
|
254
|
+
if "metal2" in text:
|
|
255
|
+
return "Metal 2"
|
|
256
|
+
if "metal" in text:
|
|
257
|
+
return "Metal"
|
|
258
|
+
return None
|
gpu_clock/layout.py
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
|
|
6
|
+
from rich import box
|
|
7
|
+
from rich.align import Align
|
|
8
|
+
from rich.console import Group
|
|
9
|
+
from rich.panel import Panel
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
from rich.text import Text
|
|
12
|
+
|
|
13
|
+
from gpu_clock.cpu import CpuInfo
|
|
14
|
+
from gpu_clock.figlet import render_time
|
|
15
|
+
from gpu_clock.gpu import GpuInfo
|
|
16
|
+
from gpu_clock.theme import clock_text
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
PANEL_HEIGHT = 14
|
|
20
|
+
COMPACT_PANEL_HEIGHT = 9
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build_snapshot(
|
|
24
|
+
args: argparse.Namespace,
|
|
25
|
+
cpu_info: CpuInfo | None,
|
|
26
|
+
gpu_info: GpuInfo,
|
|
27
|
+
show_help: bool = False,
|
|
28
|
+
terminal_width: int | None = None,
|
|
29
|
+
terminal_height: int | None = None,
|
|
30
|
+
) -> Group:
|
|
31
|
+
compact = _compact_layout(terminal_width, terminal_height)
|
|
32
|
+
now = datetime.now()
|
|
33
|
+
time_value = _format_time(now, args.clock, args.show_seconds)
|
|
34
|
+
date_line = now.strftime("%B %-d, %Y | %A")
|
|
35
|
+
|
|
36
|
+
time_art = render_time(time_value, font=_time_font(args.font, compact))
|
|
37
|
+
header_width = terminal_width or 120
|
|
38
|
+
header = Group(
|
|
39
|
+
Align.center(clock_text(time_art, args.theme), width=header_width),
|
|
40
|
+
Align.center(Text(date_line, style="bold"), width=header_width),
|
|
41
|
+
Align.center(Text("Q Quit | H Help", style="dim"), width=header_width),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if show_help:
|
|
45
|
+
return Group(header, Text(""), _help_panel(compact))
|
|
46
|
+
|
|
47
|
+
bottom = Table.grid(expand=True)
|
|
48
|
+
if cpu_info is not None:
|
|
49
|
+
bottom.add_column(ratio=1)
|
|
50
|
+
bottom.add_column(ratio=2)
|
|
51
|
+
|
|
52
|
+
row = []
|
|
53
|
+
if cpu_info is not None:
|
|
54
|
+
row.append(_cpu_panel(cpu_info, compact))
|
|
55
|
+
row.append(_gpu_panel(gpu_info, compact, terminal_width))
|
|
56
|
+
bottom.add_row(*row)
|
|
57
|
+
|
|
58
|
+
return Group(header, Text(""), bottom)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _compact_layout(width: int | None, height: int | None) -> bool:
|
|
62
|
+
return (width is not None and width < 100) or (height is not None and height < 28)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _time_font(font: str, compact: bool) -> str:
|
|
66
|
+
if compact and font == "terrace":
|
|
67
|
+
return "standard"
|
|
68
|
+
return font
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _panel_height(compact: bool) -> int:
|
|
72
|
+
return COMPACT_PANEL_HEIGHT if compact else PANEL_HEIGHT
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _help_panel(compact: bool) -> Panel:
|
|
76
|
+
table = Table.grid(padding=(0, 2))
|
|
77
|
+
table.add_column(style="bold cyan", no_wrap=True)
|
|
78
|
+
table.add_column()
|
|
79
|
+
table.add_row("Q", "Quit nvclocktop and restore the terminal.")
|
|
80
|
+
table.add_row("H", "Show or hide this help screen.")
|
|
81
|
+
table.add_row("Ctrl+C", "Quit immediately.")
|
|
82
|
+
return Panel(
|
|
83
|
+
Align.center(table, vertical="middle"),
|
|
84
|
+
title="Help",
|
|
85
|
+
box=box.SQUARE,
|
|
86
|
+
height=_panel_height(compact),
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _format_time(now: datetime, clock: str, show_seconds: bool) -> str:
|
|
91
|
+
if clock == "24h":
|
|
92
|
+
return now.strftime("%H:%M:%S" if show_seconds else "%H:%M")
|
|
93
|
+
return now.strftime("%I:%M:%S %p" if show_seconds else "%I:%M %p")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _cpu_panel(cpu: CpuInfo, compact: bool = False) -> Panel:
|
|
97
|
+
table = Table.grid(expand=True)
|
|
98
|
+
table.add_column(width=7)
|
|
99
|
+
table.add_column(ratio=2)
|
|
100
|
+
bar_width = 8 if compact else 18
|
|
101
|
+
table.add_row(Text("CPU", style="bold dim"), Text(_short_cpu_model(cpu.model), style="bold"))
|
|
102
|
+
table.add_row(Text("Use", style="bold dim"), _status_bar(cpu.usage_percent, bar_width, "green", value_suffix="%"))
|
|
103
|
+
if compact:
|
|
104
|
+
table.add_row(
|
|
105
|
+
Text("RAM", style="bold dim"),
|
|
106
|
+
Text(f"{cpu.memory_used_gib:.1f}/{cpu.memory_total_gib:.1f} GiB", style="bold cyan"),
|
|
107
|
+
)
|
|
108
|
+
else:
|
|
109
|
+
table.add_row(
|
|
110
|
+
Text("RAM", style="bold dim"),
|
|
111
|
+
_status_bar(
|
|
112
|
+
_memory_percent(cpu.memory_used_gib, cpu.memory_total_gib),
|
|
113
|
+
bar_width,
|
|
114
|
+
"cyan",
|
|
115
|
+
value_text=f"{cpu.memory_used_gib:.1f}/{cpu.memory_total_gib:.1f} GiB",
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
if cpu.load_average:
|
|
119
|
+
table.add_row(Text("Load", style="bold dim"), Text(_load_text(cpu, compact), style="white"))
|
|
120
|
+
if not compact:
|
|
121
|
+
table.add_row(Text("Freq", style="bold dim"), Text(_frequency_text(cpu), style="white"))
|
|
122
|
+
table.add_row(Text("Temp", style="bold dim"), Text(_temperature_text(cpu), style="yellow"))
|
|
123
|
+
table.add_row(Text("Threads", style="bold dim"), _thread_grid(cpu.per_cpu_percent))
|
|
124
|
+
return Panel(table, title="CPU", box=box.SQUARE, height=_panel_height(compact))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _gpu_panel(gpu_info: GpuInfo, compact: bool = False, terminal_width: int | None = None) -> Panel:
|
|
128
|
+
if not gpu_info.available:
|
|
129
|
+
return Panel(
|
|
130
|
+
gpu_info.error or "NVIDIA GPU not detected.",
|
|
131
|
+
title="GPU",
|
|
132
|
+
box=box.SQUARE,
|
|
133
|
+
height=_panel_height(compact),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
summary = Table.grid(expand=True)
|
|
137
|
+
summary.add_column(width=10)
|
|
138
|
+
summary.add_column(ratio=1)
|
|
139
|
+
summary.add_column(width=22)
|
|
140
|
+
bar_width = _gpu_bar_width(terminal_width, compact)
|
|
141
|
+
|
|
142
|
+
for index, gpu in enumerate(gpu_info.gpus):
|
|
143
|
+
summary.add_row(
|
|
144
|
+
Text("Device", style="bold dim"),
|
|
145
|
+
_gpu_title(index, gpu.name),
|
|
146
|
+
Text(""),
|
|
147
|
+
)
|
|
148
|
+
if gpu.core_count:
|
|
149
|
+
summary.add_row(
|
|
150
|
+
Text("Cores", style="bold dim"),
|
|
151
|
+
Text(f"{gpu.core_count} GPU cores", style="bold white"),
|
|
152
|
+
Text(""),
|
|
153
|
+
)
|
|
154
|
+
summary.add_row(
|
|
155
|
+
Text("GPU", style="bold dim"),
|
|
156
|
+
_metric_bar(gpu.utilization_percent, bar_width, "green"),
|
|
157
|
+
_metric_value(gpu.utilization_percent, "green", suffix="%"),
|
|
158
|
+
)
|
|
159
|
+
summary.add_row(
|
|
160
|
+
Text(_fit_label(gpu.memory_label), style="bold dim"),
|
|
161
|
+
_metric_bar(
|
|
162
|
+
_memory_percent(gpu.memory_used_mib, gpu.memory_total_mib),
|
|
163
|
+
bar_width,
|
|
164
|
+
"cyan",
|
|
165
|
+
),
|
|
166
|
+
_metric_value_text(_memory(gpu.memory_used_mib, gpu.memory_total_mib, compact), "cyan"),
|
|
167
|
+
)
|
|
168
|
+
if not compact or gpu.temperature_c is not None:
|
|
169
|
+
summary.add_row(
|
|
170
|
+
Text("Temp", style="bold dim"),
|
|
171
|
+
_metric_bar(_temperature_percent(gpu.temperature_c), bar_width, "yellow"),
|
|
172
|
+
_metric_value_text(_fmt(gpu.temperature_c, " C"), "yellow"),
|
|
173
|
+
)
|
|
174
|
+
if not compact or gpu.power_draw_w is not None:
|
|
175
|
+
summary.add_row(
|
|
176
|
+
Text("Power", style="bold dim"),
|
|
177
|
+
_metric_bar(_memory_percent(gpu.power_draw_w, gpu.power_limit_w), bar_width, "magenta"),
|
|
178
|
+
_metric_value_text(_power(gpu.power_draw_w, gpu.power_limit_w), "magenta"),
|
|
179
|
+
)
|
|
180
|
+
if not compact or gpu.fan_percent is not None:
|
|
181
|
+
summary.add_row(
|
|
182
|
+
Text("Fan", style="bold dim"),
|
|
183
|
+
_metric_bar(gpu.fan_percent, bar_width, "blue"),
|
|
184
|
+
_metric_value(gpu.fan_percent, "blue", suffix="%"),
|
|
185
|
+
)
|
|
186
|
+
summary.add_row(
|
|
187
|
+
Text(_gpu_driver_label(gpu.backend), style="bold dim"),
|
|
188
|
+
Text(gpu.driver_version or "N/A", style="dim"),
|
|
189
|
+
Text(""),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
return Panel(summary, title="GPU", box=box.SQUARE, height=_panel_height(compact))
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _gpu_title(index: int, name: str) -> Text:
|
|
196
|
+
text = Text()
|
|
197
|
+
text.append(f"GPU {index}", style="bold cyan")
|
|
198
|
+
text.append(f" {name}", style="bold")
|
|
199
|
+
return text
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _fit_label(label: str) -> str:
|
|
203
|
+
if label == "Unified Memory":
|
|
204
|
+
return "Unified"
|
|
205
|
+
return label
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _gpu_driver_label(backend: str) -> str:
|
|
209
|
+
if backend == "Apple":
|
|
210
|
+
return "Metal"
|
|
211
|
+
return "Driver"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _gpu_bar_width(terminal_width: int | None, compact: bool) -> int:
|
|
215
|
+
if compact:
|
|
216
|
+
return 18
|
|
217
|
+
if terminal_width is None:
|
|
218
|
+
return 36
|
|
219
|
+
return max(24, min(96, int(terminal_width * 0.35)))
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _metric_bar(percent: float | None, width: int, style: str) -> Text:
|
|
223
|
+
text = Text(no_wrap=True, overflow="crop")
|
|
224
|
+
if percent is None:
|
|
225
|
+
text.append(" " * width, style="on #3a3a3a")
|
|
226
|
+
return text
|
|
227
|
+
|
|
228
|
+
clamped = max(0, min(percent, 100))
|
|
229
|
+
filled = round(clamped / 100 * width)
|
|
230
|
+
text.append(" " * filled, style=f"on {style}")
|
|
231
|
+
text.append(" " * (width - filled), style="on #3a3a3a")
|
|
232
|
+
return text
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _metric_value(value: float | None, style: str, suffix: str = "") -> Text:
|
|
236
|
+
if value is None:
|
|
237
|
+
return Text("N/A", style="dim", no_wrap=True)
|
|
238
|
+
return Text(f"{max(0, min(value, 100)):.0f}{suffix}", style=f"bold {style}", no_wrap=True)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _metric_value_text(value: str, style: str) -> Text:
|
|
242
|
+
if value == "N/A":
|
|
243
|
+
return Text(value, style="dim", no_wrap=True)
|
|
244
|
+
return Text(value, style=f"bold {style}", no_wrap=True)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _status_bar(
|
|
248
|
+
percent: float | None,
|
|
249
|
+
width: int,
|
|
250
|
+
style: str,
|
|
251
|
+
value_text: str | None = None,
|
|
252
|
+
value_suffix: str = "",
|
|
253
|
+
) -> Text:
|
|
254
|
+
text = Text(no_wrap=True, overflow="ellipsis")
|
|
255
|
+
if percent is None:
|
|
256
|
+
text.append(" " * width, style="on #3a3a3a")
|
|
257
|
+
text.append(" N/A", style="dim")
|
|
258
|
+
return text
|
|
259
|
+
|
|
260
|
+
clamped = max(0, min(percent, 100))
|
|
261
|
+
filled = round(clamped / 100 * width)
|
|
262
|
+
text.append(" " * filled, style=f"on {style}")
|
|
263
|
+
text.append(" " * (width - filled), style="on #3a3a3a")
|
|
264
|
+
label = value_text if value_text is not None else f"{clamped:.0f}{value_suffix}"
|
|
265
|
+
text.append(f" {label}", style=f"bold {style}")
|
|
266
|
+
return text
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _thread_grid(values: list[float]) -> Text:
|
|
270
|
+
text = Text()
|
|
271
|
+
for index, value in enumerate(values):
|
|
272
|
+
if index and index % 10 == 0:
|
|
273
|
+
text.append("\n")
|
|
274
|
+
text.append("■", style=_usage_style(value))
|
|
275
|
+
if index % 10 != 9:
|
|
276
|
+
text.append(" ")
|
|
277
|
+
if not values:
|
|
278
|
+
text.append("N/A", style="dim")
|
|
279
|
+
return text
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _short_cpu_model(model: str) -> str:
|
|
283
|
+
return (
|
|
284
|
+
model.replace("12th Gen Intel(R) Core(TM)", "Intel")
|
|
285
|
+
.replace("Intel(R) Core(TM)", "Intel")
|
|
286
|
+
.replace("AMD Ryzen", "Ryzen")
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _usage_style(value: float) -> str:
|
|
291
|
+
if value >= 85:
|
|
292
|
+
return "bold red"
|
|
293
|
+
if value >= 60:
|
|
294
|
+
return "bold yellow"
|
|
295
|
+
if value >= 30:
|
|
296
|
+
return "bold green"
|
|
297
|
+
return "dim"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _load_text(cpu: CpuInfo, compact: bool = False) -> str:
|
|
301
|
+
if compact:
|
|
302
|
+
return " ".join(f"{value:.1f}" for value in cpu.load_average or ())
|
|
303
|
+
return " / ".join(f"{value:.2f}" for value in cpu.load_average or ())
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _frequency_text(cpu: CpuInfo) -> str:
|
|
307
|
+
frequency = f"{cpu.frequency_ghz:.2f} GHz" if cpu.frequency_ghz else "N/A"
|
|
308
|
+
return f"{cpu.thread_count} threads {frequency}"
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _temperature_text(cpu: CpuInfo) -> str:
|
|
312
|
+
return f"{cpu.temperature_c:.0f} C" if cpu.temperature_c else "N/A"
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _fmt(value: float | None, suffix: str) -> str:
|
|
316
|
+
if value is None:
|
|
317
|
+
return "N/A"
|
|
318
|
+
return f"{value:.0f}{suffix}"
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _memory(used: float | None, total: float | None, compact: bool = False) -> str:
|
|
322
|
+
if used is None or total is None:
|
|
323
|
+
return "N/A"
|
|
324
|
+
if compact:
|
|
325
|
+
return f"{used / 1024:.1f}/{total / 1024:.1f} GiB"
|
|
326
|
+
return f"{used:.0f} / {total:.0f} MiB"
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _memory_percent(used: float | None, total: float | None) -> float | None:
|
|
330
|
+
if used is None or total in (None, 0):
|
|
331
|
+
return None
|
|
332
|
+
return used / total * 100
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _temperature_percent(value: float | None) -> float | None:
|
|
336
|
+
if value is None:
|
|
337
|
+
return None
|
|
338
|
+
return value / 90 * 100
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _power(draw: float | None, limit: float | None) -> str:
|
|
342
|
+
if draw is None:
|
|
343
|
+
return "N/A"
|
|
344
|
+
if limit is None:
|
|
345
|
+
return f"{draw:.1f} W"
|
|
346
|
+
return f"{draw:.1f} / {limit:.0f} W"
|
gpu_clock/theme.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from rich.text import Text
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
CLOCK_THEMES = {
|
|
7
|
+
"rainbow": [
|
|
8
|
+
(231, 72, 86),
|
|
9
|
+
(226, 106, 20),
|
|
10
|
+
(220, 158, 0),
|
|
11
|
+
(98, 168, 0),
|
|
12
|
+
(0, 153, 94),
|
|
13
|
+
(0, 137, 163),
|
|
14
|
+
(37, 91, 201),
|
|
15
|
+
(127, 46, 176),
|
|
16
|
+
],
|
|
17
|
+
"cyber": [
|
|
18
|
+
(0, 229, 255),
|
|
19
|
+
(0, 184, 255),
|
|
20
|
+
(80, 117, 255),
|
|
21
|
+
(177, 74, 255),
|
|
22
|
+
(255, 67, 210),
|
|
23
|
+
],
|
|
24
|
+
"ocean": [
|
|
25
|
+
(91, 206, 250),
|
|
26
|
+
(45, 156, 219),
|
|
27
|
+
(33, 150, 136),
|
|
28
|
+
(39, 174, 96),
|
|
29
|
+
(166, 226, 161),
|
|
30
|
+
],
|
|
31
|
+
"amber": [
|
|
32
|
+
(255, 202, 40),
|
|
33
|
+
(255, 171, 0),
|
|
34
|
+
(255, 112, 67),
|
|
35
|
+
(255, 213, 79),
|
|
36
|
+
],
|
|
37
|
+
"mono": [
|
|
38
|
+
(245, 245, 245),
|
|
39
|
+
(210, 210, 210),
|
|
40
|
+
(170, 170, 170),
|
|
41
|
+
],
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
THEME_PRESETS = tuple(CLOCK_THEMES)
|
|
45
|
+
|
|
46
|
+
RAINBOW_2 = CLOCK_THEMES["rainbow"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def clock_text(value: str, theme: str = "rainbow") -> Text:
|
|
50
|
+
palette = CLOCK_THEMES[theme]
|
|
51
|
+
return gradient_text(value, palette)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def gradient_text(value: str, palette: list[tuple[int, int, int]]) -> Text:
|
|
55
|
+
text = Text(justify="center")
|
|
56
|
+
for line in value.splitlines():
|
|
57
|
+
width = max(len(line), 1)
|
|
58
|
+
for index, char in enumerate(line):
|
|
59
|
+
color = palette[int(index / width * len(palette))]
|
|
60
|
+
text.append(char, style=f"rgb({color[0]},{color[1]},{color[2]})")
|
|
61
|
+
text.append("\n")
|
|
62
|
+
return text
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def rainbow_text(value: str) -> Text:
|
|
66
|
+
return gradient_text(value, RAINBOW_2)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nvclocktop
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A fullscreen terminal clock and GPU dashboard for NVIDIA Linux workstations and Apple Silicon Macs.
|
|
5
|
+
Author: nvclocktop contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: apple-silicon,clock,dashboard,gpu,linux,macos,monitoring,nvidia,nvidia-smi,terminal,tui
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: System :: Monitoring
|
|
19
|
+
Classifier: Topic :: Terminals
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: psutil>=5.9
|
|
22
|
+
Requires-Dist: pyfiglet>=1.0
|
|
23
|
+
Requires-Dist: rich>=13.7
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: cairosvg>=2.7; extra == 'dev'
|
|
26
|
+
Requires-Dist: pillow>=10.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
<h1>nvclocktop</h1>
|
|
34
|
+
|
|
35
|
+
<p>
|
|
36
|
+
<strong>A fullscreen terminal clock and GPU dashboard for NVIDIA Linux workstations and Apple Silicon Macs.</strong>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<p>
|
|
40
|
+
Turn any terminal into a live status screen for AI workstations, local model machines, homelab servers, and SSH sessions.
|
|
41
|
+
</p>
|
|
42
|
+
|
|
43
|
+
<img src="docs/assets/hero-macos-apple-silicon.png" alt="nvclocktop running on an Apple Silicon Mac">
|
|
44
|
+
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
`nvclocktop` combines a large readable clock, CPU activity, memory usage, and GPU metrics in one colorful terminal dashboard.
|
|
50
|
+
|
|
51
|
+
## Preset Gallery
|
|
52
|
+
|
|
53
|
+
<table>
|
|
54
|
+
<tr>
|
|
55
|
+
<th><code>--font terrace --theme rainbow</code></th>
|
|
56
|
+
<th><code>--font terrace --theme cyber</code></th>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<td><img src="docs/assets/presets/preset-terrace-rainbow-nvidia.png" alt="terrace font with rainbow theme on NVIDIA Linux" width="420"></td>
|
|
60
|
+
<td><img src="docs/assets/presets/preset-terrace-cyber-nvidia.png" alt="terrace font with cyber theme on NVIDIA Linux" width="420"></td>
|
|
61
|
+
</tr>
|
|
62
|
+
<tr>
|
|
63
|
+
<th><code>--font big --theme ocean</code></th>
|
|
64
|
+
<th><code>--font standard --theme amber</code></th>
|
|
65
|
+
</tr>
|
|
66
|
+
<tr>
|
|
67
|
+
<td><img src="docs/assets/presets/preset-big-ocean-nvidia.png" alt="big font with ocean theme on NVIDIA Linux" width="420"></td>
|
|
68
|
+
<td><img src="docs/assets/presets/preset-standard-amber-nvidia.png" alt="standard font with amber theme on NVIDIA Linux" width="420"></td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<th><code>--font slant --theme mono</code></th>
|
|
72
|
+
<th></th>
|
|
73
|
+
</tr>
|
|
74
|
+
<tr>
|
|
75
|
+
<td><img src="docs/assets/presets/preset-slant-mono-nvidia.png" alt="slant font with mono theme on NVIDIA Linux" width="420"></td>
|
|
76
|
+
<td></td>
|
|
77
|
+
</tr>
|
|
78
|
+
</table>
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install nvclocktop
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Or with `pipx`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pipx install nvclocktop
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Usage
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
nvclocktop
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Useful options:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
nvclocktop --refresh 1
|
|
102
|
+
nvclocktop --once
|
|
103
|
+
nvclocktop --font big
|
|
104
|
+
nvclocktop --theme cyber
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Features
|
|
108
|
+
|
|
109
|
+
- Large fixed-position terminal clock with seconds
|
|
110
|
+
- CPU usage, memory, load average, and per-thread activity
|
|
111
|
+
- NVIDIA GPU usage, memory, temperature, power, fan, and driver info on Linux
|
|
112
|
+
- Apple Silicon GPU and unified memory display on macOS
|
|
113
|
+
- Adaptive layout for wide and compact terminals
|
|
114
|
+
- Keyboard controls: `Q` to quit, `H` for help
|
|
115
|
+
- Works well over SSH
|
|
116
|
+
|
|
117
|
+
## Style Presets
|
|
118
|
+
|
|
119
|
+
`nvclocktop` ships with official clock font and color presets. Invalid preset names are rejected by the CLI, so saved scripts and dashboard setups fail fast instead of silently falling back to an unexpected style.
|
|
120
|
+
|
|
121
|
+
Available font presets:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
nvclocktop --font terrace
|
|
125
|
+
nvclocktop --font big
|
|
126
|
+
nvclocktop --font standard
|
|
127
|
+
nvclocktop --font slant
|
|
128
|
+
nvclocktop --font chunky
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Available color themes:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
nvclocktop --theme rainbow
|
|
135
|
+
nvclocktop --theme cyber
|
|
136
|
+
nvclocktop --theme ocean
|
|
137
|
+
nvclocktop --theme amber
|
|
138
|
+
nvclocktop --theme mono
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Platform Support
|
|
142
|
+
|
|
143
|
+
Currently supported:
|
|
144
|
+
|
|
145
|
+
| Platform | GPU support | Notes |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| Linux | NVIDIA GPUs via `nvidia-smi` | Best supported path |
|
|
148
|
+
| macOS | Apple Silicon GPU display | Includes unified memory display |
|
|
149
|
+
| CPU | Intel and AMD CPUs | Uses standard system metrics |
|
|
150
|
+
|
|
151
|
+
Not currently supported:
|
|
152
|
+
|
|
153
|
+
- AMD GPUs
|
|
154
|
+
- Intel GPUs
|
|
155
|
+
- Windows native terminal
|
|
156
|
+
|
|
157
|
+
## Keyboard Shortcuts
|
|
158
|
+
|
|
159
|
+
| Key | Action |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `Q` | Quit |
|
|
162
|
+
| `H` | Show or hide help |
|
|
163
|
+
| `Ctrl+C` | Quit immediately |
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
git clone https://github.com/YOUR_USERNAME/nvclocktop.git
|
|
169
|
+
cd nvclocktop
|
|
170
|
+
python3 -m venv .venv
|
|
171
|
+
. .venv/bin/activate
|
|
172
|
+
pip install -e ".[dev]"
|
|
173
|
+
pytest
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
gpu_clock/__init__.py,sha256=iNPWX5ffcXt0_yPDk8-MD-O--Cb-jUFwgLMXnAPnoUE,76
|
|
2
|
+
gpu_clock/__main__.py,sha256=Cbjma_Ddvqz7i4gyXyxk5uuUfBSLJlv-e5RWksFG7bU,89
|
|
3
|
+
gpu_clock/app.py,sha256=Q7dkG957pgJ-Bq7IC0RGfTFD-oG61m7iNbn_al--oTM,3693
|
|
4
|
+
gpu_clock/cli.py,sha256=SBSjSPcJ_qXTQ4H06SetxG_uju61KiN2KQjVrPaMDWI,1732
|
|
5
|
+
gpu_clock/cpu.py,sha256=vuKf2mcANnzL3rAFb43FptB5VT88_Q8Hbd76wuIGS1I,2731
|
|
6
|
+
gpu_clock/figlet.py,sha256=W7jNPCc8jS0LXgIaMeRA2hzAyBDjQO4P1nfqtncQz68,1971
|
|
7
|
+
gpu_clock/gpu.py,sha256=K2Q3Ma3dXlFMHmcH2NZU7mJhk0PMPeQ4k_V9Whunj6k,7310
|
|
8
|
+
gpu_clock/layout.py,sha256=j8eiThJES9udAgUgvivwdqRAr3k_34EJTpCk5f1RCXw,11363
|
|
9
|
+
gpu_clock/theme.py,sha256=2YjN2zSdtrzlmOmop00d64c9-PnQgEDpSqSo5b-pIeA,1490
|
|
10
|
+
gpu_clock/fonts/README.md,sha256=xLeh3xX0ZwA2kvENQ660Of6FYzzQTTFxRzzpSGKABUk,299
|
|
11
|
+
nvclocktop-1.0.0.dist-info/METADATA,sha256=gUmwrpDZHHAIJ6IZOv2bLuM5LYkyHHpM08p06Ij8wgU,4744
|
|
12
|
+
nvclocktop-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
13
|
+
nvclocktop-1.0.0.dist-info/entry_points.txt,sha256=IfOBKUmcdtAeivccF4qizpVstBgai6KTIxHWMcRwb_Q,50
|
|
14
|
+
nvclocktop-1.0.0.dist-info/licenses/LICENSE,sha256=g36JVCaskaXnYF5wHxfgJP87-PNT-Wonumpf_UhF5GA,1079
|
|
15
|
+
nvclocktop-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gpu-clock contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|