NVIDIAのGPUを使っていて、温度が気になったのでJavaから取ってみることにした。
nvcpl.dllのNvCplGetThermalSettingsを使えばとれるらしい。
DLLのアクセスにはJNAを使う。
<dependencies> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.5.0</version> </dependency> </dependencies>
で、こんな感じのコードを書く。
package kis.gputhermo; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; public class Main { public interface Nvcpl extends Library { Nvcpl INSTANCE = (Nvcpl)Native.load("nvcpl", Nvcpl.class); boolean NvCplGetThermalSettings(int number, IntByReference coreTemp, IntByReference ambientTemp, IntByReference upperLimit); String NvGetErrorMessageA(); } public static void main(String[] args) { var d = Nvcpl.INSTANCE; var core = new IntByReference(); var ambient = new IntByReference(); var limit = new IntByReference(); System.out.println(d.NvCplGetThermalSettings(0, core, ambient, limit)); System.out.printf("core:%d ambient:%d limit:%d%n", core.getValue(), ambient.getValue(), limit.getValue()); System.out.println(d.NvGetErrorMessageA()); } }
結果
false core:0 ambient:0 limit:0 NV_NOTIMPLEMENTED
実装されてないっぽい。。。