aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/cache-sample.sh2
-rwxr-xr-xbin/disks-sample.sh2
-rw-r--r--lib/card.lua2
-rw-r--r--lib/data.lua28
-rw-r--r--test/render.lua9
-rw-r--r--widgets/gpu.lua4
6 files changed, 33 insertions, 14 deletions
diff --git a/bin/cache-sample.sh b/bin/cache-sample.sh
index cac8911..202bc63 100755
--- a/bin/cache-sample.sh
+++ b/bin/cache-sample.sh
@@ -11,11 +11,11 @@ CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt"
CACHE="$CACHE_DIR/cachesize.txt"
TARGET="${XDG_CACHE_HOME:-$HOME/.cache}"
+umask 077
mkdir -p "$CACHE_DIR"
TMP="$CACHE.tmp.$$"
trap 'rm -f "$TMP"' EXIT
-umask 077
# Total first, then the four largest children. `sort -h` compares human sizes
# numerically; the Lua side converts them again because it needs the ratio to
diff --git a/bin/disks-sample.sh b/bin/disks-sample.sh
index 83b8a62..5291bcf 100755
--- a/bin/disks-sample.sh
+++ b/bin/disks-sample.sh
@@ -16,11 +16,11 @@ CACHE="$CACHE_DIR/disks.txt"
MOUNTS=(/ /home /data /mnt/nfs/Library /mnt/nfs/shared)
+umask 077
mkdir -p "$CACHE_DIR"
TMP="$CACHE.tmp.$$"
trap 'rm -f "$TMP"' EXIT
-umask 077
# /usr/bin/df by absolute path with -P -B1, deliberately:
# - the user's shell aliases df to `df -h`, and an alias or a function would
diff --git a/lib/card.lua b/lib/card.lua
index 48a7f2e..185703c 100644
--- a/lib/card.lua
+++ b/lib/card.lua
@@ -213,7 +213,7 @@ function M.human(bytes)
local units = { 'B', 'K', 'M', 'G', 'T', 'P' }
local i = 1
while n >= 1024 and i < #units do n = n / 1024; i = i + 1 end
- if i == 1 then return string.format('%d%s', n, units[i]) end
+ if i == 1 then return string.format('%d%s', math.floor(n), units[i]) end
if n >= 100 then return string.format('%.0f%s', n, units[i]) end
return string.format('%.1f%s', n, units[i])
end
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.
diff --git a/test/render.lua b/test/render.lua
index 7d48d0e..3ed5f7e 100644
--- a/test/render.lua
+++ b/test/render.lua
@@ -29,7 +29,9 @@ local sw, sh = 2560, 1080
-- The palette, read from the rendered conky.conf exactly as dashboard.lua
-- does, so the PNG uses the real scheme rather than invented colours.
local function config_colors()
- local path = os.getenv('HOME') .. '/.config/conky/conky.conf'
+ local home = os.getenv('HOME')
+ if not home then return {} end
+ local path = home .. '/.config/conky/conky.conf'
local f = io.open(path, 'r')
if not f then return {} end
local src = f:read('*a')
@@ -79,7 +81,10 @@ if not ok then
os.exit(1)
end
local drew, err = pcall(mod.draw, cr, rect, colors)
-if not drew then print('DRAW ERROR: ' .. tostring(err)) end
+if not drew then
+ print('DRAW ERROR: ' .. tostring(err))
+ os.exit(1)
+end
cairo_destroy(cr)
cairo_surface_write_to_png(surf, out)
diff --git a/widgets/gpu.lua b/widgets/gpu.lua
index 5f289a0..87e22f3 100644
--- a/widgets/gpu.lua
+++ b/widgets/gpu.lua
@@ -14,9 +14,9 @@ local data = require 'lib.data'
local M = {}
--- chip, file, label, warn, crit
+-- chip, file, label, warn, crit. Package (temp2) is the headline above, so it
+-- is not repeated here; these are the rows drawn under it.
local TEMPS = {
- { 'xe', 'temp2_input', 'PKG', 75, 85 },
{ 'xe', 'temp3_input', 'VRAM', 80, 90 },
}