Attempts to cache runs of underlying commands so that e.g. #{gpu_bg_color}#{gpu_percentage} only calls nvidia-smi once per update.
fixes #27
also fixes (maybe) #5
related #15
Notes:
runs cached commands a maximum of once every 2 seconds
caches based on date +%s and basename command, ignoring command arguments. This could be a problem if running the same command with different arguments (not currently a problem)
details
While testing this, I think I've found an upstream problem (with tmux or tpm). Basically
set -g status-right "%H:%M:%S #(sleep 1)"
set -g status-interval 5
will ignore status-interval and result in one update per second (!) which appears to be #15.
15 (status-interval not respected) looks like an upstream bug
each update, commands may be run in parallel? e.g. set -g status-right #(write_hello_to_debug_file) #(write_bye_to_debug_file) won't guarantee hello is written before bye. This means that caching within an update may not work. Needs investigating... it's possible that some higher level code (outside this repo) handles caching of #(external commands)
oddly, before this PR, I get updates more than 1/s, but after it's about once every 5 sec, respecting status-interval. This seems to fix (maybe) #15 but no there's not clear reason why... I suspect some higher level logic may be doing something like:
commands = find_pattern("#(*)", status_right)
while True:
execution_time = exec(commands)
if execution_time < 1:
sleep(status_interval)
debugging
in ~/.tmux.conf:
set -g status-right '#{cpu_bg_color}#{cpu_percentage}#[bg=green][#{ram_bg_color}#{ram_percentage}#[bg=green]] #{gpu_bg_color}#{gpu_percentage}#[bg=green][#{gram_bg_color}#{gram_percentage}#[bg=green]]'
print to a debug file in ~/.tmux/plugins/tmux-cpu/debug.log:
diff --git a/scripts/helpers.sh b/scripts/helpers.sh
index df31cfb..d1e3e84 100644
--- a/scripts/helpers.sh
+++ b/scripts/helpers.sh
@@ -99,7 +99,9 @@ cached_eval(){
local val="$(get_cache_val "$key")"
if [ -z "$val" ]; then
put_cache_val "$key" "$($command "${@:2}")"
+ echo miss "$key" >> ~/.tmux/plugins/tmux-cpu/debug.log
else
echo -n "$val"
+ echo hit "$key" >> ~/.tmux/plugins/tmux-cpu/debug.log
fi
}
observation: will print miss nvidia-smi 4 times in quick succession each update
expected: miss nvidia-smi once, then hit nvidia-smi 3 times
Attempts to cache runs of underlying commands so that e.g.
#{gpu_bg_color}#{gpu_percentage}
only callsnvidia-smi
once per update.Notes:
date +%s
andbasename command
, ignoring command arguments. This could be a problem if running the same command with different arguments (not currently a problem)details
While testing this, I think I've found an upstream problem (with
tmux
ortpm
). Basicallywill ignore
status-interval
and result in one update per second (!) which appears to be #15.15 (
status-interval
not respected) looks like an upstream bugset -g status-right #(write_hello_to_debug_file) #(write_bye_to_debug_file)
won't guaranteehello
is written beforebye
. This means that caching within an update may not work. Needs investigating... it's possible that some higher level code (outside this repo) handles caching of#(external commands)
status-interval
. This seems to fix (maybe) #15 but no there's not clear reason why... I suspect some higher level logic may be doing something like:debugging
in
~/.tmux.conf
:print to a debug file in
~/.tmux/plugins/tmux-cpu/debug.log
:miss nvidia-smi
4 times in quick succession each updatemiss nvidia-smi
once, thenhit nvidia-smi
3 times