testsAndMisc/linux_configuration/i3-configuration/i3blocks/config
Krzysztof kuhy Rudnicki c8c727e9d5 i3blocks: eliminate fork-storm with persist mode + zero-fork sysfs reads
Resource-usage report showed ~29 cores of average load coming from i3blocks
helper scripts forking awk/tr/grep/bc/sensors/nvidia-smi every tick. Rewrite
all five hot-path scripts to eliminate forks:

- volume.sh: persist mode, blocks on 'pactl subscribe' event stream.
  No polling, no sleep, no fork per tick.
- gpu_monitor.sh: persist mode, single long-lived 'nvidia-smi --loop=5'
  feeds a bash 'while read' loop. Falls back to /sys for amdgpu.
- battery_status.sh: reads /sys/class/power_supply/BAT*/ directly.
  Zero forks; replaces 'acpi | awk' pipeline.
- cpu_monitor.sh: reads /proc/loadavg and k10temp/coretemp /sys/class/hwmon.
  Zero forks; replaces 'sensors | awk | tr' + bc arithmetic.
- motherboard_temp.sh: reads nct*/it*/f71* Super-I/O hwmon node directly.
  Zero forks.

Configure volume + gpu_monitor with interval=persist so i3blocks keeps
one long-lived producer each instead of forking per tick.

Also add:
- kill_stale_recorders.sh -- kill stray ffmpeg x11grab / dotnet-trace /
  dotnet-monitor processes left running after sessions.
- monitors.slice -- resource-capped user slice (CPUQuota=50%,
  MemoryMax=512M, MemorySwapMax=0 for zram safety, TasksMax=256) to
  bound future monitoring regressions.
- efficient-polling-scripts SKILL -- rules for writing status-bar and
  polling scripts without forks; fork-pipeline to bash-builtin translation
  table; verification checklist.

Verified live: strace -c on cpu_monitor.sh shows 1 execve / 0 clones;
persist producers (pactl subscribe, nvidia-smi --loop) show 0 CPU ticks
over a 3s idle sample. Per-invocation timing 1.6-1.9 ms (was 30-80 ms).
2026-04-20 21:54:29 +02:00

94 lines
1.4 KiB
Plaintext

[cpu_monitor]
command=~/.config/i3blocks/cpu_monitor.sh
interval=5
markup=pango
[gpu_monitor]
command=~/.config/i3blocks/gpu_monitor.sh
interval=persist
markup=pango
[motherboard_temperature]
command=~/.config/i3blocks/motherboard_temp.sh
interval=5
[memory]
command=free -h | awk '/^Mem:/ {print " " $3 "/" $2}' #  for RAM
interval=5
color=#50FA7B
[disk]
command=df -h / | awk '/\// {print " " $3 "/" $2}' #  for disk
interval=60
color=#50FA7B
[volume]
command=~/.config/i3blocks/volume.sh
interval=persist
[bluetooth]
command=~/.config/i3blocks/bluetooth.sh
interval=5
color=#FFFFFF
[battery]
command=~/.config/i3blocks/battery_status.sh
interval=1
[ethernet]
command=ip -o -4 addr show | grep -E 'enp6s0|eth0' | awk '{print " "$4}' || echo " down" #  for Ethernet
interval=10
color=#FFFFFF
[wifi]
command=~/.config/i3blocks/wifi_monitor.sh
interval=10
color=#FFFFFF
#[network_monitor]
#command=~/.config/i3blocks/network_monitor.sh
#interval=1
#color=#FFFFFF
[warp]
command=~/.config/i3blocks/warp_status.sh
interval=60
[activitywatch]
command=~/.config/i3blocks/activitywatch_status.sh
interval=10
color=#FFFFFF
[pc_startup]
command=~/.config/i3blocks/pc_startup_status.sh
interval=30
color=#FFFFFF
[shutdown_countdown]
command=~/.config/i3blocks/shutdown_countdown.sh
interval=60
markup=pango
[time]
command=echo " $(date '+%Y-%m-%d %H:%M')" #  for time (Font Awesome icon)
interval=1
color=#50FA7B