I wrote a simple GPU status widget for the Awesome window manager last week so I could keep an eye on the temperature and memory usage in the hope it might help diagnose the lockups I’ve been having. Currently I’m in the process of cleaning up and improving it with the intention of publishing it.
The first attempt parsed the output of nvidia-smi to get the GPU status but I decided to switch to nvidia-settings as the latter offers more information for my GPU such as clock speeds (and I think supports a wider range of GPUs as well).
The new code is successfully fetching the available GPUs, fans and thermal sensors and reading the properties I need in all cases execpt one. I want to be able to show details of the available and currently selected performance profiles for each GPU in a tooltip on the widget, so I’m fetching GPUPerfModes for each of the enumerated GPUs. Unfortunately nvidia-settings insists on inserting a line break in the value, which throws off reading the output from the command which is otherwise one value per line.
I wrote a minimal test Lua script (Awesome extensions are written in Lua) which runs nvidia-settings in a subprocess and reads the output
f = io.popen("nvidia-settings -t -q [gpu:0]/GPUPerfModes") for l in f:lines() do print(l) end f:close();
which I ran under strace to see what nvidia-settings was doing. As I expected it fetches the terminal size before writing, though it’s sending the ioctl to stderr, not stdout which seems odd. The output is wrapped to the width of my terminal even though the output isn’t sent to it. If I modify the script so stderr is redirected to stdout the ioctl fails with ENOTTY, and the output is wrapped to 80 chars (presumably a hardcoded default).
The -t flag looks like it’s meant for use in scripts, nvidia-settings should be changed so it either doesn’t wrap values at all if -t is specfied or disables wrapping if it’s set and stdout isn’t a TTY.