fflewddur / tophat

View CPU, memory, disk, and network activity in the GNOME top bar.
https://extensions.gnome.org/extension/5219/tophat/
GNU General Public License v3.0
334 stars 26 forks source link

List GPU memory and usage #80

Open vadi2 opened 1 year ago

vadi2 commented 1 year ago

Hey! I love TopHat for its powerful but simple design. Would you consider adding GPU memory and usage as stats? It wasn't really necessary before with gaming (the game covered the full screen anyway), but all of the AI-based workloads are putting a fair bit of stress on the GPU now - and it would be nice to see what's going on with your hardware at a glance, just like with cpu/ram/disk.

tumist commented 1 year ago

There is currently no unified API to get these measurements. Ideally they would come from libgtop, and although there was an attempt to add GPU usage to libgtop it was not merged.

My computer has an AMD graphics card and it's rather easy to get measurements from the amdgpu driver through sysfs. I don't have access to a computer with an nvidia graphics card (and even so there are at least two different drivers, no?) so I can't work on that.

sansmoraxz commented 11 months ago

You may take a look at this repo for Nvidia implementation: https://github.com/UshakovVasilii/gnome-shell-extension-freon/blob/55bcd7c48181c8c18a9210828b8723ac3fe1d4c7/freon%40UshakovVasilii_Github.yahoo.com/nvidiaUtil.js#L142

Although there are no standard tooling I think you can probably call libgtop for the gpu vendor info. Or just check for availability of GPU specific CLI tools. Next call the corresponding tools for info.

sansmoraxz commented 11 months ago

Also I got an NVIDIA driver here's all the GPU info options you can poll:

https://gist.github.com/sansmoraxz/8a98d987f12d7edc983d611b8326fc67

Hope it helps.

sansmoraxz commented 9 months ago

glxinfo from mesa-utils appears to provide the GPU memory at least.

> glxinfo -B
name of display: :1
display: :1  screen: 0
direct rendering: Yes
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 4096 MB
    Total available memory: 4096 MB
    Currently available dedicated video memory: 3105 MB
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVIDIA GeForce GTX 1050 Ti/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 535.129.03
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.6.0 NVIDIA 535.129.03
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)

OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 535.129.03
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

I don't have an AMD GPU to test this out. @tumist could you confirm if the tool works in AMD too? Also if someone got intel graphics to compare too, would be helpful.

If it works I can open a PR regarding this.

getlogname commented 8 months ago

It works with an AMD GPU too, here is what I got:

> glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: AMD (0x1002)
    Device: AMD Radeon RX 7900 XT (gfx1100, LLVM 16.0.6, DRM 3.54, 6.6.7-100.fc38.x86_64) (0x744c)
    Version: 23.1.9
    Accelerated: yes
    Video memory: 20480MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 4.6
    Max compat profile version: 4.6
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
    VBO free memory - total: 19821 MB, largest block: 19821 MB
    VBO free aux. memory - total: 15932 MB, largest block: 15932 MB
    Texture free memory - total: 19821 MB, largest block: 19821 MB
    Texture free aux. memory - total: 15932 MB, largest block: 15932 MB
    Renderbuffer free memory - total: 19821 MB, largest block: 19821 MB
    Renderbuffer free aux. memory - total: 15932 MB, largest block: 15932 MB
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 20480 MB
    Total available memory: 36486 MB
    Currently available dedicated video memory: 19821 MB
OpenGL vendor string: AMD
OpenGL renderer string: AMD Radeon RX 7900 XT (gfx1100, LLVM 16.0.6, DRM 3.54, 6.6.7-100.fc38.x86_64)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 23.1.9
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.6 (Compatibility Profile) Mesa 23.1.9
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 23.1.9
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20