Spaces:
Paused
Paused
File size: 1,779 Bytes
289fb74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import psutil
import time
import GPUtil
from rich.live import Live
from rich.progress import Progress, BarColumn, ProgressColumn
from rich.console import Console
from rich.text import Text
class PercentageColumn(ProgressColumn):
def render(self, task):
return Text(f"{task.percentage:>5.1f}%")
def main():
console = Console()
progress = Progress(
"[progress.description]{task.description}",
BarColumn(bar_width=None),
PercentageColumn(),
)
# Create tasks for CPU and GPUs
cpu_task = progress.add_task("CPU Utilization", total=100)
gpu_tasks = []
gpus = GPUtil.getGPUs()
for gpu in gpus:
gpu_task = progress.add_task(f"GPU {gpu.id} Utilization", total=100)
vram_task = progress.add_task(f"GPU {gpu.id} VRAM Usage", total=100)
gpu_tasks.append((gpu.id, gpu_task, vram_task))
with Live(progress, refresh_per_second=10):
try:
while True:
# Update CPU utilization
cpu_utilization = psutil.cpu_percent(interval=None)
progress.update(cpu_task, completed=cpu_utilization)
# Update GPU info
gpus = GPUtil.getGPUs()
for gpu in gpus:
gpu_util = gpu.load * 100
mem_util = gpu.memoryUtil * 100
for gid, gpu_task_id, vram_task_id in gpu_tasks:
if gid == gpu.id:
progress.update(gpu_task_id, completed=gpu_util)
progress.update(vram_task_id, completed=mem_util)
time.sleep(0.1)
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
|