Class WindowsGpuStats
- All Implemented Interfaces:
AutoCloseable, GpuStats
GpuStats implementation. Subclasses provide platform-specific native dispatch.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWindowsGpuStats(String luidPrefix, String lhmParent, int pciBusNumber, String pciBusId, String cardName) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intadlFindAdapterIndex(int pciBusNumber) Finds an ADL adapter index by PCI bus number.protected abstract longadlGetCoreClockMhz(int adapterIndex) Gets the GPU core clock via ADL.protected abstract doubleadlGetFanSpeedPercent(int adapterIndex) Gets the GPU fan speed via ADL.protected abstract longadlGetMemoryClockMhz(int adapterIndex) Gets the GPU memory clock via ADL.protected abstract doubleadlGetPowerDraw(int adapterIndex) Gets the GPU power draw via ADL.protected abstract doubleadlGetTemperature(int adapterIndex) Gets the GPU temperature via ADL.voidclose()Releases any native resources held by this session.longReturns the current GPU core clock speed.doubleReturns the GPU fan speed as a percentage of maximum.Returns a snapshot of cumulative GPU active and idle ticks in opaque, platform-native units.doubleReturns the instantaneous GPU core utilization as a percentage, computed internally as a delta between the current sample and the previous one recorded by this session.longReturns the current GPU memory clock speed.doubleReturns the GPU power consumption.longReturns the amount of shared system memory currently used by this GPU.doubleReturns the GPU temperature.longReturns the amount of dedicated VRAM currently in use.protected abstract booleanChecks whether the ADL library is available.booleanisClosed()ReturnstrueifGpuStats.close()has been called on this session.protected abstract booleanChecks whether the NVML library is available.protected abstract StringnvmlFindDevice(String pciBusId) Finds an NVML device by PCI bus ID.protected abstract StringnvmlFindDeviceByName(String gpuName) Finds an NVML device by name.protected abstract longnvmlGetCoreClockMhz(String device) Gets the GPU core clock via NVML.protected abstract doublenvmlGetFanSpeedPercent(String device) Gets the GPU fan speed via NVML.protected abstract longnvmlGetMemoryClockMhz(String device) Gets the GPU memory clock via NVML.protected abstract doublenvmlGetPowerDraw(String device) Gets the GPU power draw via NVML.protected abstract doublenvmlGetTemperature(String device) Gets the GPU temperature via NVML.Queries GPU adapter memory performance counters.Queries GPU engine performance counters.protected abstract WmiResult<LhmSensor.LhmSensorProperty> queryLhmSensors(String parent, String sensorType) Queries LHM sensors.
-
Constructor Details
-
WindowsGpuStats
protected WindowsGpuStats(String luidPrefix, String lhmParent, int pciBusNumber, String pciBusId, String cardName) Constructor.- Parameters:
luidPrefix- the LUID prefix for PDH counter matchinglhmParent- the LHM parent identifierpciBusNumber- the PCI bus numberpciBusId- the PCI bus ID stringcardName- the card name
-
-
Method Details
-
queryGpuEngineCounters
-
queryGpuAdapterMemoryCounters
-
queryLhmSensors
protected abstract WmiResult<LhmSensor.LhmSensorProperty> queryLhmSensors(String parent, String sensorType) Queries LHM sensors.- Parameters:
parent- the parent identifiersensorType- the sensor type- Returns:
- the WMI result
-
isNvmlAvailable
protected abstract boolean isNvmlAvailable()Checks whether the NVML library is available.- Returns:
- whether NVML is available
-
nvmlFindDevice
-
nvmlFindDeviceByName
-
nvmlGetTemperature
Gets the GPU temperature via NVML.- Parameters:
device- the NVML device handle- Returns:
- temperature in degrees C, or negative if unavailable
-
nvmlGetPowerDraw
Gets the GPU power draw via NVML.- Parameters:
device- the NVML device handle- Returns:
- power draw in watts, or negative if unavailable
-
nvmlGetCoreClockMhz
Gets the GPU core clock via NVML.- Parameters:
device- the NVML device handle- Returns:
- core clock in MHz, or negative if unavailable
-
nvmlGetMemoryClockMhz
Gets the GPU memory clock via NVML.- Parameters:
device- the NVML device handle- Returns:
- memory clock in MHz, or negative if unavailable
-
nvmlGetFanSpeedPercent
Gets the GPU fan speed via NVML.- Parameters:
device- the NVML device handle- Returns:
- fan speed percent, or negative if unavailable
-
isAdlAvailable
protected abstract boolean isAdlAvailable()Checks whether the ADL library is available.- Returns:
- whether ADL is available
-
adlFindAdapterIndex
protected abstract int adlFindAdapterIndex(int pciBusNumber) Finds an ADL adapter index by PCI bus number.- Parameters:
pciBusNumber- the PCI bus number- Returns:
- the adapter index, or -1 if not found
-
adlGetTemperature
protected abstract double adlGetTemperature(int adapterIndex) Gets the GPU temperature via ADL.- Parameters:
adapterIndex- the ADL adapter index- Returns:
- temperature in degrees C, or negative if unavailable
-
adlGetPowerDraw
protected abstract double adlGetPowerDraw(int adapterIndex) Gets the GPU power draw via ADL.- Parameters:
adapterIndex- the ADL adapter index- Returns:
- power draw in watts, or negative if unavailable
-
adlGetCoreClockMhz
protected abstract long adlGetCoreClockMhz(int adapterIndex) Gets the GPU core clock via ADL.- Parameters:
adapterIndex- the ADL adapter index- Returns:
- core clock in MHz, or negative if unavailable
-
adlGetMemoryClockMhz
protected abstract long adlGetMemoryClockMhz(int adapterIndex) Gets the GPU memory clock via ADL.- Parameters:
adapterIndex- the ADL adapter index- Returns:
- memory clock in MHz, or negative if unavailable
-
adlGetFanSpeedPercent
protected abstract double adlGetFanSpeedPercent(int adapterIndex) Gets the GPU fan speed via ADL.- Parameters:
adapterIndex- the ADL adapter index- Returns:
- fan speed percent, or negative if unavailable
-
close
public void close()Description copied from interface:GpuStatsReleases any native resources held by this session. Safe to call multiple times; subsequent calls after the first are no-ops. Does not throw checked exceptions.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGpuStats
-
isClosed
public boolean isClosed()Description copied from interface:GpuStatsReturnstrueifGpuStats.close()has been called on this session. Does not throw. -
getGpuTicks
Description copied from interface:GpuStatsReturns a snapshot of cumulative GPU active and idle ticks in opaque, platform-native units. The counters are monotonically increasing; diff two snapshots to compute utilization:long dActive = curr.getActiveTicks() - prev.getActiveTicks(); long dIdle = curr.getIdleTicks() - prev.getIdleTicks(); long dTotal = dActive + dIdle; double utilPct = dTotal > 0 ? dActive * 100.0 / dTotal : -1d;Both counters are
0on platforms where tick-level GPU metrics are not available (seeGpuTicksfor the sentinel semantics). UseGpuStats.getGpuUtilization()as an alternative.- Specified by:
getGpuTicksin interfaceGpuStats- Returns:
- a
GpuTickssnapshot; never null
-
getGpuUtilization
public double getGpuUtilization()Description copied from interface:GpuStatsReturns the instantaneous GPU core utilization as a percentage, computed internally as a delta between the current sample and the previous one recorded by this session.Behaviour on the first call is implementation-dependent. Backends that derive utilization from an energy or residency counter record an initial baseline on the first call and return
-1; subsequent calls return the utilization computed over the elapsed interval. Backends that read an instantaneous hardware register may return a valid value immediately. To ensure the first polling iteration returns a valid value on delta-based backends, call this method once as a priming step before the polling loop begins:stats.getGpuUtilization(); // prime — may return -1 on delta-based backends Thread.sleep(intervalMs); double util = stats.getGpuUtilization(); // valid on all backends- Specified by:
getGpuUtilizationin interfaceGpuStats- Returns:
- utilization in the range 0.0 to 100.0, or -1 if not available or not yet primed
-
getVramUsed
public long getVramUsed()Description copied from interface:GpuStatsReturns the amount of dedicated VRAM currently in use.- Specified by:
getVramUsedin interfaceGpuStats- Returns:
- bytes of VRAM in use, or -1 if unavailable
-
getTemperature
public double getTemperature()Description copied from interface:GpuStatsReturns the GPU temperature.- Specified by:
getTemperaturein interfaceGpuStats- Returns:
- temperature in degrees Celsius, or -1 if unavailable
-
getPowerDraw
public double getPowerDraw()Description copied from interface:GpuStatsReturns the GPU power consumption. On backends that derive power from an energy counter (e.g. macOS Apple Silicon via IOReport), this is computed as a delta between the current sample and the previous one; the first call records the initial baseline and returns-1. On backends that read an instantaneous hardware sensor (e.g. Windows via NVML/ADL/LHM), a valid value may be returned immediately.To ensure the first polling iteration returns a valid value on delta-based backends, call this method once as a priming step before the polling loop begins:
stats.getPowerDraw(); // prime — may return -1 on delta-based backends Thread.sleep(intervalMs); double watts = stats.getPowerDraw(); // valid on all backends- Specified by:
getPowerDrawin interfaceGpuStats- Returns:
- power draw in watts, or -1 if unavailable or not yet primed
-
getCoreClockMhz
public long getCoreClockMhz()Description copied from interface:GpuStatsReturns the current GPU core clock speed.- Specified by:
getCoreClockMhzin interfaceGpuStats- Returns:
- core clock in MHz, or -1 if unavailable
-
getMemoryClockMhz
public long getMemoryClockMhz()Description copied from interface:GpuStatsReturns the current GPU memory clock speed.- Specified by:
getMemoryClockMhzin interfaceGpuStats- Returns:
- memory clock in MHz, or -1 if unavailable
-
getFanSpeedPercent
public double getFanSpeedPercent()Description copied from interface:GpuStatsReturns the GPU fan speed as a percentage of maximum.- Specified by:
getFanSpeedPercentin interfaceGpuStats- Returns:
- fan speed in the range 0.0 to 100.0, or -1 if unavailable
-