Skip to content

Commit aba85f8

Browse files
wookayinStonesjtu
andauthored
Do not list the same GPU process more than once (wookayin#84)
* Do not list the same GPU process more than once A single process might appear in both of graphics and compute running processes list (wookayin#18). In such cases, the same process (same PID) would appear appearing twice. We fix this bug: list a process only once. * Add comments for seen_pids Co-authored-by: Kaiyu Shi <[email protected]>
1 parent 5c8898e commit aba85f8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

gpustat/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ def get_process_info(nv_process):
376376
GPUStatCollection.global_processes[nv_process.pid] = \
377377
psutil.Process(pid=nv_process.pid)
378378
ps_process = GPUStatCollection.global_processes[nv_process.pid]
379+
380+
# TODO: ps_process is being cached, but the dict below is not.
379381
process['username'] = ps_process.username()
380382
# cmdline returns full path;
381383
# as in `ps -o comm`, get short cmdnames.
@@ -461,7 +463,13 @@ def get_process_info(nv_process):
461463
processes = []
462464
nv_comp_processes = nv_comp_processes or []
463465
nv_graphics_processes = nv_graphics_processes or []
466+
# A single process might run in both of graphics and compute mode,
467+
# However we will display the process only once
468+
seen_pids = set()
464469
for nv_process in nv_comp_processes + nv_graphics_processes:
470+
if nv_process.pid in seen_pids:
471+
continue
472+
seen_pids.add(nv_process.pid)
465473
try:
466474
process = get_process_info(nv_process)
467475
processes.append(process)

gpustat/test_gpustat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _callable(*args, **kwargs):
129129

130130
when(N).nvmlDeviceGetGraphicsRunningProcesses(handle)\
131131
.thenAnswer(_return_or_raise({
132-
0: [],
132+
0: [mock_process_t(48448, 4000*MB)],
133133
1: [],
134134
2: N.NVMLError_NotSupported(),
135135
}[i]))

0 commit comments

Comments
 (0)