1

I am looking to monitor hardware usage overtime and have came across OpenGL as multiple people have said this is a possible solution.

I am struggling to find examples or resources of how OpenGL can be used to obtain GPU information.

Can it be done in Java? And how?

Or is there any alternatives?

4
  • What kind of information do you want to retrieve? Commented Nov 5, 2018 at 15:02
  • memory and memory in use Commented Nov 5, 2018 at 15:22
  • I'm afraid you'll need to look for OpenGL extensions in order to achieve that (so each GPU vendor should provide it for you). It doesn't look like out of the box feature of the OpenGL API. Commented Nov 5, 2018 at 15:26
  • Possible duplicate of JOGL - monitor GPU memory Commented Nov 5, 2018 at 16:11

2 Answers 2

1

OpenGL is predominantly GPU-agnostic API, so it doesn't have exact information of the GPU performance characteristics, doesn't provide temperature of something. On the other hand you are able to retrieve some info that may help you to get better idea of what kind of GPU you are dealing with using the glGetString function. Combination of the values GL_VENDOR and GL_RENDERER is unique for a platform.

For Java any OpenGL wrapper should be suitable, probably JOGL is the most famous one.


Edit.

Althought it's not common, but various vendors provide the information you are looking for. I was able to find only some insights about GPU memory, but it gives a hope that there others: http://nasutechtips.blogspot.com/2011/02/how-to-get-gpu-memory-size-and-usage-in.html

Sign up to request clarification or add additional context in comments.

Comments

-1

If anyone is wondering how to get GPU usage i found a way using nvidia-smi command then reading the output. Only works for nvidia gpus tho and you can change the command to get other information like memory or whatever with the query command

/**
* Returns current GPU usage percentage for NVIDIA GPU's
*/
public static int getGPUUsagePercentage() {
    try {
        Process process = Runtime.getRuntime().exec("nvidia-smi --query-gpu=utilization.gpu --format=csv");
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
        stdInput.readLine();
        return Integer.parseInt(stdInput.readLine().replace(" %", ""));
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.