From 27d22cae37408644d29c4b97cc79eef5233654a0 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Fri, 4 Aug 2023 16:36:41 +0800 Subject: [PATCH] fix(api/device): add extra 0.25s timestamp margin for GPU process utilization --- nvitop/api/device.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nvitop/api/device.py b/nvitop/api/device.py index def080c..5d3b92a 100644 --- a/nvitop/api/device.py +++ b/nvitop/api/device.py @@ -1700,7 +1700,10 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me samples = libnvml.nvmlQuery( 'nvmlDeviceGetProcessUtilization', self.handle, - time.time_ns() // 1000, + # Only utilization samples that were recorded after this timestamp will be returned. + # The CPU timestamp, i.e. absolute Unix epoch timestamp (in microseconds), is used. + # Here we use the timestamp 1/4 second ago to ensure the record buffer is not empty. + time.time_ns() // 1000 - 250_000, default=(), ) for s in sorted(samples, key=lambda s: s.timeStamp):