Skip to content

Instantly share code, notes, and snippets.

@CounterPillow
Last active April 17, 2022 07:50
Show Gist options
  • Save CounterPillow/0b764ed14c609024c9188383f7dce033 to your computer and use it in GitHub Desktop.
Save CounterPillow/0b764ed14c609024c9188383f7dce033 to your computer and use it in GitHub Desktop.
mpv script to show GPU frequencies on Linux.

This script shows the current frequency and max frequency of a Linux DRM GPU.

To use it, bind script-message show-gpu-freq "cardnamehere" to a key, e.g. U script-message show-gpu-freq "card0".

Check /sys/class/drm/ for available cards.

function get_sys_value(variable)
local f = assert(io.open(variable, "r"))
local val = string.gsub(f:read("*all"), "\n", "")
f:close()
return val
end
function show_gpu_freq(card)
local freq_cur = get_sys_value("/sys/class/drm/" .. card .. "/gt_act_freq_mhz")
local freq_max = get_sys_value("/sys/class/drm/" .. card .. "/gt_max_freq_mhz")
local freq_req = get_sys_value("/sys/class/drm/" .. card .. "/gt_cur_freq_mhz")
mp.osd_message(freq_cur .. "/" .. freq_max .. " MHz (requested " .. freq_req .. " MHz)")
end
mp.register_script_message("show-gpu-freq", show_gpu_freq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment