fix(api/device): add extra 0.25s timestamp margin for GPU process utilization

This commit is contained in:
Xuehai Pan 2023-08-04 16:36:41 +08:00
parent b99d90544d
commit 27d22cae37

View file

@ -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):