diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 12:40:10 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 12:40:10 +0200 |
| commit | 32e10b1d6962afd04a209f300ebb8ab9ee29f070 (patch) | |
| tree | 9b8e711f00b4ebdb3a6652aef4ffc54a1f36b50a /lib/data.lua | |
| parent | f0638bc45a939b28fb32d46e9bbbd8fc2e8cf223 (diff) | |
| download | conky-theme-udt-32e10b1d6962afd04a209f300ebb8ab9ee29f070.tar.gz conky-theme-udt-32e10b1d6962afd04a209f300ebb8ab9ee29f070.zip | |
fix: stop the widgets from stalling or raising the draw
Memoize hwmon_dir by chip name so sensor reads no longer popen grep on
every frame, cache misses included. Floor fractional byte counts in
card.human so it cannot raise. Drop the GPU package-temperature row,
which duplicated the headline. Set umask before mkdir in both samplers
so a fresh cache directory is not world-readable. Make render.lua exit
non-zero on a draw error and tolerate an unset HOME.
Diffstat (limited to 'lib/data.lua')
| -rw-r--r-- | lib/data.lua | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/data.lua b/lib/data.lua index acf7a0f..2047ef8 100644 --- a/lib/data.lua +++ b/lib/data.lua @@ -62,14 +62,28 @@ end -- Globbing by name, never by a fixed hwmon index: indices drift across kernel -- and hardware reorders, and a stale index silently reports a different chip. -- Carried over from the previous conky config, where this was the hard-won bit. +-- +-- The result is memoized per chip name, hits and misses alike. A chip's hwmon +-- directory is stable for the process's life, and the draw hook calls this +-- several times per frame: without the cache every sensor read popens grep, +-- which is exactly the subprocess-per-draw the samplers exist to avoid. A miss +-- is cached too, so an absent chip is not re-globbed on every frame. +local hwmon_cache = {} + function M.hwmon_dir(name) - local p = io.popen('grep -lx ' .. ("%q"):format(name) - .. ' /sys/class/hwmon/hwmon*/name 2>/dev/null') - if not p then return nil end - local hit = p:read('*l') - p:close() - if not hit then return nil end - return hit:match('^(.*)/name$') + if type(name) ~= 'string' then return nil end + if hwmon_cache[name] == nil then + local p = io.popen('grep -lx ' .. ("%q"):format(name) + .. ' /sys/class/hwmon/hwmon*/name 2>/dev/null') + local dir = false + if p then + local hit = p:read('*l') + p:close() + if hit then dir = hit:match('^(.*)/name$') end + end + hwmon_cache[name] = dir + end + return hwmon_cache[name] or nil end -- A stateful CPU-load counter. |
