# Monitoring Graphics Processing Unit (GPU) with Processing 3

**URL:** <https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860>\
**Category:** Libraries\
**Created:** [November 27, 2019, 9:50am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860 "2019-11-27T09:50:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [November 27, 2019, 9:50am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/1 "2019-11-27T09:50:57Z")

</div>

Hello,

Using the: java.lang.management.ManagementFactory and com.sun.management.OperatingSystemMXBean libraries, I was able to read the CPU and RAM usage of my pc. Now I would like to be able to read the Graphics Processing Unit (GPU) usage as well. I would like it to work with NVIDIA and Intel GPUs. Is this possible in Processing? Does anyone have an example on how to do this?

Thanks in advance,  
Thomas

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [November 27, 2019, 11:10am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/2 "2019-11-27T11:10:03Z")

</div>

[This](https://github.com/profesorfalken/jSensors) looks like a promising library. Add it to your sketch and go from there.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [November 27, 2019, 3:39pm UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/3 "2019-11-27T15:39:01Z")

</div>

Thank you @micycle for the reply.

> [@micycle](#):
>
> Add it to your sketch and go from there.

I have tried to make it work with the jSensors library, but I’m not experienced enough to know how to import the library in my sketch. The readme file it not very clear about this either.

For the CPU usage, everything worked rightaway, I could just do:

```auto
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
OperatingSystemMXBean osBean;

void setup(){
    size(800, 600);
    osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
}

void draw(){
    println((float)osBean.getSystemCpuLoad());
}

```

Although I get the warning “No library found for com.sun.management”, everything seems to work just fine. Now, how would I achieve the same for GPU? How to import the library?

Thank you in advance.

Kind regards,  
Thomas

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [November 28, 2019, 9:33am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/4 "2019-11-28T09:33:16Z")

</div>

It appears that there used to be a .jar download but the URL is no longer working. Otherwise, you could drag-and-drop the library’s .jar onto your sketch.

The library’s README suggests adding it as a maven dependency – this is wholly possible but you’ll need to migrate your project to an IDE (other than the PDE) (which I recommend anyway), and create a Maven project there.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [November 28, 2019, 10:50am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/5 "2019-11-28T10:50:28Z")

</div>

Thanks for the reply @micycle, I appreciate any help.

> [@micycle](#):
>
> migrate your project to an IDE (other than the PDE)

I am using Atom in combination with the ‘processing’ package from ‘bleikamp’ to compile my project in Windows 10.

> [@micycle](#):
>
> drag-and-drop the library’s .jar onto your sketch

I can’t seem to find the .jar file and I’m not sure how to create a Maven dependency. Would you be so kind to help me with that? Do I have to copy this file to the same folder as my .pde files?

I’m making a project which is rendered using the OPENGL renderer of processing, making use of my GPU. I would like to be able to keep track of my hardware usage.

Thank you in advance,  
Thomas

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 28, 2019, 11:18am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/6 "2019-11-28T11:18:32Z")

</div>

A link I found:

> <https://stackoverflow.com/questions/53156437/how-to-use-opengl-to-monitor-gpu-usage-in-java>

Istead of doing it in Java, you could also find a command line program that provides this information and execute that program and get its output from Processing. For example [https://medium.com/@george.seif94/the-4-best-command-line-tools-for-monitoring-your-cpu-ram-and-gpu-usage-692e3053000f](https://medium.com/@george.seif94/the-4-best-command-line-tools-for-monitoring-your-cpu-ram-and-gpu-usage-692e3053000f) shows a program called `nvidia-smi` that gives a lot of data. I just tried `intel_gpu_top` mentioned at [https://awesomedetect.com/how-to-monitor-intel-integrated-gpu-usage-in-linux/](https://awesomedetect.com/how-to-monitor-intel-integrated-gpu-usage-in-linux/) .

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [November 28, 2019, 2:04pm UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/7 "2019-11-28T14:04:26Z")

</div>

As I said about the .jar, the URL on the github is no longer working so you can’t access it.

Atom (since it isn’t an IDE) doesn’t support Maven projects (at least natively). It might be possible to install an extension…

Otherwise, it’s easier to use an IDE (see [Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)).

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [November 29, 2019, 9:40am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/8 "2019-11-29T09:40:23Z")

</div>

The jar is there, it just changed the name:

> **[profesorfalken/profesorfalken.github.io](https://github.com/profesorfalken/profesorfalken.github.io/tree/master/files)**
>
> Profesor Falken projects pages. Contribute to profesorfalken/profesorfalken.github.io development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [December 2, 2019, 9:58am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/9 "2019-12-02T09:58:17Z")

</div>

As @hamoid mentioned, the jar file is there. I downloaded ‘jSensors-2.1.1-jar-with-dependencies.jar’ and put it in my sketch’s ‘libraries’ folder, which I just created. I renamed to file to ‘jSensors.jar’, but when I try to ‘import jSensors.jar’ at the beginning of my sketch (called Testproject.pde), I get the following error:

_"_  
_No library found for jSensors_

_Libraries must be installed in a folder named ‘libraries’ inside the sketchbook folder (see the Preferences window). Testproject.pde:0:0:0:0: The package �jSensors� does not exist. You might be missing a library._  
_"_

What am I doing wrong here?

Thanks in advance.  
Thomas

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 2, 2019, 10:19am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/10 "2019-12-02T10:19:54Z")

</div>

Hi, inside your sketch folder, create a folder called `code` and place the jar file there. No need to rename it. The processing IDE automatically creates this folder when you drop a jar file into the IDE.

Then, based on [one of the files of the project](https://github.com/profesorfalken/jSensors/blob/master/src/test/java/com/profesorfalken/jsensors/integration/JSensorsIntegrationTest.java) the imports seem to be

```
import com.profesorfalken.jsensors.JSensors;
import com.profesorfalken.jsensors.model.components.Components;

```

You can maybe explore the other files in that repo to figure out how it is used.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [December 2, 2019, 11:42am UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/11 "2019-12-02T11:42:46Z")

</div>

> [@hamoid](#):
>
> create a folder called `code`

Thank you @hamoid , that works. I had to import the java.util.List librart as well. Now I can print the cpu model name, like this:

```auto
import com.profesorfalken.jsensors.model.components.Components;
import java.util.List;

Components components;

void setup(){
    components = JSensors.get.components();
    size(1000, 600, OPENGL);
}

void draw(){
    background(80);

    List<Cpu> cpus = components.cpus; // works
    for (final Cpu cpu : cpus) {
        println(cpu.name);
    }

    List<Gpu> gpus = components.gpus; // doesn't work
    for (final Gpu gpu : gpus) {
        println(gpu.name);
    }
}

```

But I cannot print the load of the cpu. How do I do that? Also, when I try to print the name of the gpu, it is not detected but doesn’t give an error either. Do you know what the problem is?

Thanks.

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 2, 2019, 1:28pm UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/12 "2019-12-02T13:28:19Z")

</div>

I get the same result: zero gpus. I guess the library does not detect it.

This is the output of the command line tool `nvidia-smi` before and after loading shadertoy:

```bash
a@b ~> nvidia-smi 
Mon Dec 2 14:23:27 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56 Driver Version: 418.56 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1060 Off | 00000000:01:00.0 On | N/A |
| N/A 53C P0 27W / N/A | 353MiB / 6077MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1246 G /usr/lib/xorg/Xorg 18MiB |
| 0 1280 G /usr/bin/gnome-shell 48MiB |
| 0 2189 G /usr/lib/xorg/Xorg 102MiB |
| 0 2333 G /usr/bin/gnome-shell 181MiB |
+-----------------------------------------------------------------------------+
a@b ~> nvidia-smi
Mon Dec 2 14:24:35 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56 Driver Version: 418.56 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1060 Off | 00000000:01:00.0 On | N/A |
| N/A 57C P0 46W / N/A | 549MiB / 6077MiB | 25% Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1246 G /usr/lib/xorg/Xorg 18MiB |
| 0 1280 G /usr/bin/gnome-shell 48MiB |
| 0 2189 G /usr/lib/xorg/Xorg 103MiB |
| 0 2333 G /usr/bin/gnome-shell 186MiB |
| 0 12806 G /usr/lib/firefox/firefox 189MiB |
+-----------------------------------------------------------------------------+

```

It shows power consumption, ram and GPU usage.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 2, 2019, 3:06pm UTC](https://discourse.processing.org/t/monitoring-graphics-processing-unit-gpu-with-processing-3/15860/13 "2019-12-02T15:06:07Z")

</div>

> [@micycle](#):
>
> The library’s README suggests adding it as a maven dependency – this is wholly possible but you’ll need to migrate your project to an IDE (other than the PDE) (which I recommend anyway), and create a Maven project there.

JFTR you never need to use Maven as a build system to use a JAR from Maven. Simply search for what you want at [https://search.maven.org](https://search.maven.org) and choose the download JAR option (being careful to look for any additional dependencies as well). There is also a download JAR with dependencies option but I’d be careful with that.
