最近想实现一个用java监控GPU的使用情况,但是java没有直接提供相关的api,在网上搜了好多帖子,最终参考了一篇实现了相关功能:参考文献
下面展示整个实现过程
package com.zyh.auto_tool.business.util;
import com.zyh.auto_tool.business.SystemTest.GpuInfo;
import com.zyh.auto_tool.business.execption.BizException;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* @author Jdb
* @date 2022/1/21 16:00
* @desc
*/
@Slf4j
public class GetGpu {
public static List<GpuInfo> getGPUUsagePercentage() throws IOException {
Process process = null;
try {
if (JudgeSystem.isWindows()){
long l = System.currentTimeMillis();
process = Runtime.getRuntime().exec("nvidia-smi.exe");
long l1 = System.currentT