From b809fe570d7b8d67c76149eb4df183babbca43ef Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 4 Jun 2020 18:37:51 -0500 Subject: [PATCH] Conky: Add graphs for more CPUs as needed --- .config/conky/gen.sh | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/.config/conky/gen.sh b/.config/conky/gen.sh index e817580a..011e1a7d 100755 --- a/.config/conky/gen.sh +++ b/.config/conky/gen.sh @@ -150,6 +150,7 @@ EOF } step_text() { local -r topitems=4 + local -r nproc="$(nproc)" # Generate our actual functional Conky stuff # Header cat <<- 'EOF' >> "$_optout" @@ -163,9 +164,44 @@ step_text() { cat <<- 'EOF' >> "$_optout" ${color3}$hr$color ${font Roboto:style=Medium:size=9}CPU$font: $freq_g GHz$alignr$cpu% - ${color8}${cpugraph cpu1 36,200} ${cpugraph cpu2 36,200} - ${cpugraph cpu3 36,200} ${cpugraph cpu4 36,200}$color EOF + local gpl=1 + if (( nproc <= 2 )); then + gpl=1 + elif (( nproc <= 4 )); then + gpl=2 + elif (( nproc <= 8 )); then + gpl=4 + else + gpl=8 + fi + local width=$(( 400 / gpl )) + log "Generating $gpl graphs per row of CPU core stats" 1 + log "Graphs will be $width wide" 2 + local cpuinfo + for i in $(seq 1 "$gpl" "$nproc"); do + # Generate lines + local line="\${color8}" + for j in $(seq 0 $(( gpl - 1 ))); do + # Generate graphs + local cpu=$(( i + j )) + log "Generating graph for CPU $cpu" 2 + if [ -z "$line" ]; then + line="\${cpugraph cpu$cpu 36,$width}" + else + line="$line \${cpugraph cpu$cpu 36,$width}" + fi + done + # Trim whitespace + line="${line%" "}$color" + log "Appending line: $line" 2 + cpuinfo="$cpuinfo$line\n" + unset line + done + while [ "$cpuinfo" != "${cpuinfo%\\n}" ]; do + cpuinfo="${cpuinfo%\\n}" + done + echo -e "$cpuinfo" >> "$_optout" for i in $(seq $topitems); do echo "\${color8}\${top name $i}\$color\$alignr\${top cpu $i}%" >> "$_optout" done