forked from Shmuma/gpu_mon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpu_mon.py
executable file
·42 lines (31 loc) · 1.11 KB
/
gpu_mon.py
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
#!/usr/bin/env python3
import time
import argparse
import logging
from gpu_mon import config
from gpu_mon import proc
from gpu_mon import gpu
from gpu_mon import tty
log = logging.getLogger("gpu_mon")
DEFAULT_CONFIG = "~/.config/gpu_mon.conf"
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)-15s %(levelname)s %(name)-14s %(message)s", level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--conf", default=DEFAULT_CONFIG,
help="Configuration file to use, default=" + DEFAULT_CONFIG)
args = parser.parse_args()
conf = config.Configuration.read(args.conf)
gpus = gpu.detect_gpus()
log.info("GPUs detected: ")
for g in gpus:
log.info(g)
proc_tracker = proc.ProcessTracker(conf)
try:
while True:
processes = proc.get_processes(gpus)
active_users = tty.active_users(conf.tty_conf)
proc_tracker.check(gpus, processes, active_users)
time.sleep(conf.interval_seconds)
except KeyboardInterrupt:
log.info("Interrupt received, exit gracefully")
pass