From 74d64af9d52e9204f39c097e259df07c709e0f22 Mon Sep 17 00:00:00 2001 From: Mislah Date: Fri, 23 Feb 2024 22:08:17 +0530 Subject: [PATCH 1/7] perf: optimize waybar cpuinfo Optimize cpuinfo to use less resources by minimizing the number of forks as it is called once in every 5 seconds. Revert to the previous icon generation method for faster performance compared to jq after reducing forks. --- Configs/.config/hypr/scripts/cpuinfo.sh | 81 ++++++++++++++++--------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/Configs/.config/hypr/scripts/cpuinfo.sh b/Configs/.config/hypr/scripts/cpuinfo.sh index ac5e2d530e..e081ed62e6 100755 --- a/Configs/.config/hypr/scripts/cpuinfo.sh +++ b/Configs/.config/hypr/scripts/cpuinfo.sh @@ -1,35 +1,58 @@ -#!/usr/bin/env sh +#!/bin/bash -# CPU model -model=$(lscpu | awk -F ':' '/Model name/ {sub(/^ *| *$/,"",$2); print $2}' | awk '{NF-=3}1') +get_icons() { + + # Thee shalt find the greatest one, + # He who not more than the chosen one + map_floor() { -# CPU utilization -utilization=$(top -bn1 | awk '/^%Cpu/ {print 100 - $8}') + # From the depths of the string, words arise, + # Keys in pairs, a treasure in disguise. + IFS=', ' read -r -a pairs <<< "$1" + + # If the final token stands alone and bold, + # Declare it the default, its worth untold. + if [[ ${pairs[-1]} != *":"* ]]; then + def_val="${pairs[-1]}" + unset 'pairs[${#pairs[@]}-1]' + fi + + # Scans the map, a peak it seeks, + # The highest passed, the value speaks. + for pair in "${pairs[@]}"; do + IFS=':' read -r key value <<< "$pair" + + # Behold! Thou holds the secrets they seek, + # Declare it and silence the whispers unique. + if [ ${2%%.*} -gt $key ]; then + echo "$value" + return + fi + done + + # On this lonely shore, where silence dwells + # Even the waves, echoes words unheard + [ -n "$def_val" ] && echo $def_val || echo " " + } -# Clock speed -freqlist=$(cat /proc/cpuinfo | grep "cpu MHz" | awk '{ print $4 }') -maxfreq=$(lscpu | grep "CPU max MHz" | awk -F: '{ print $2}' | sed -e 's/ //g' -e 's/\.[0-9]*//g') -frequency=$(echo $freqlist | tr ' ' '\n' | awk "{ sum+=\$1 } END {printf \"%.0f/$maxfreq MHz\", sum/NR}") - -# CPU temp -temp=$(sensors | awk '/Package id 0/ {print $4}' | awk -F '[+.]' '{print $2}') -if [ -z "$temp" ]; then - temp=$(sensors | awk '/Tctl/ {print $2}' | tr -d '+°C') -fi -if [ -z "$temp" ]; then - temp="N/A" -fi - -# map icons -set_ico="{\"thermo\":{\"0\":\"\",\"45\":\"\",\"65\":\"\",\"85\":\"\"},\"emoji\":{\"0\":\"❄\",\"45\":\"☁\",\"65\":\"\",\"85\":\"\"},\"util\":{\"0\":\"󰾆\",\"30\":\"󰾅\",\"60\":\"󰓅\",\"90\":\"\"}}" -eval_ico() { - map_ico=$(echo "${set_ico}" | jq -r --arg aky "$1" --argjson avl "$2" '.[$aky] | keys_unsorted | map(tonumber) | map(select(. <= $avl)) | max') - echo "${set_ico}" | jq -r --arg aky "$1" --arg avl "$map_ico" '.[$aky] | .[$avl]' + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" + util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" + + echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)" } -thermo=$(eval_ico thermo $temp) -emoji=$(eval_ico emoji $temp) -speedo=$(eval_ico util $utilization) +# Get CPU information +model=$(lscpu | awk -F': ' '/Model name/ {gsub(/^ *| *$| CPU.*/,"",$2); print $2}') +utilization=$(top -bn1 | awk '/^%Cpu/ {print 100 - $8}') +maxfreq=$(lscpu | awk '/CPU max MHz/ { sub(/\..*/,"",$4); print $4}') +frequency=$(cat /proc/cpuinfo | awk '/cpu MHz/{ sum+=$4; c+=1 } END { printf "%.0f", sum/c }') +temperature=$(sensors | awk -F': ' '/Package id 0|Tctl/ { gsub(/^ *\+?|\..*/,"",$2); print $2; f=1; exit} END { if (!f) print "N/A"; }') + +# Get emoji and icons +icons=$(get_icons "$temperature" "$utilization") +speedo=$(echo ${icons:0:1}) +thermo=$(echo ${icons:1:1}) +emoji=$(echo ${icons:2}) -# Print cpu info (json) -echo "{\"text\":\"${thermo} ${temp}°C\", \"tooltip\":\"${model}\n${thermo} Temperature: ${temp}°C ${emoji}\n${speedo} Utilization: ${utilization}%\n Clock Speed: ${frequency}\"}" +# Print the formatted output +echo "{\"text\":\"$thermo $temperature°C\", \"tooltip\":\"$model\n$thermo Temperature: $temperature°C $emoji\n$speedo Utilization: $utilization%\n Clock Speed: $frequency/$maxfreq MHz\"}" \ No newline at end of file From bc4cca341044e38a7a36335f87819ab683b4afcd Mon Sep 17 00:00:00 2001 From: Mislah Date: Fri, 23 Feb 2024 22:27:02 +0530 Subject: [PATCH 2/7] perf: optimize waybar gpuinfo Revise icon generation method to minimize forks, particularly resource intensive calls to awk as the script runs once in every 5 seconds. --- Configs/.config/hypr/scripts/gpuinfo.sh | 76 ++++++++++++------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/Configs/.config/hypr/scripts/gpuinfo.sh b/Configs/.config/hypr/scripts/gpuinfo.sh index ba3ca10c4e..734cd83956 100755 --- a/Configs/.config/hypr/scripts/gpuinfo.sh +++ b/Configs/.config/hypr/scripts/gpuinfo.sh @@ -102,57 +102,53 @@ sed -i "s/^#${next_prioGPU}/${next_prioGPU}/" "${gpuQ}" # Uncomment the next pri sed -i "s/prioGPU=${prioGPU}/prioGPU=${next_prioGPU}/" "${gpuQ}" # Update the prioGPU in the file } -# Thee shalt find the greatest one, -# He who not more than the chosen one -map_floor() { - - # From the depths of the string, words arise, - # Keys in pairs, a treasure in disguise. - IFS=', ' read -r -a pairs <<< "$1" - - # If the final token stands alone and bold, - # Declare it the default, its worth untold. - if [[ ${pairs[-1]} != *":"* ]]; then - def_val="${pairs[-1]}" - unset 'pairs[${#pairs[@]}-1]' - fi +get_icons() { + + # Thee shalt find the greatest one, + # He who not more than the chosen one + map_floor() { + + # From the depths of the string, words arise, + # Keys in pairs, a treasure in disguise. + IFS=', ' read -r -a pairs <<< "$1" - # Scans the map, a peak it seeks, - # The highest passed, the value speaks. - for pair in "${pairs[@]}"; do - IFS=':' read -r key value <<< "$pair" - - # Behold! Thou holds the secrets they seek, - # Declare it and silence the whispers unique. - if awk -v num="$2" -v k="$key" 'BEGIN { exit !(num > k) }'; then - echo "$value" - return + # If the final token stands alone and bold, + # Declare it the default, its worth untold. + if [[ ${pairs[-1]} != *":"* ]]; then + def_val="${pairs[-1]}" + unset 'pairs[${#pairs[@]}-1]' fi - done - # On this lonely shore, where silence dwells - # Even the waves, echoes words unheard - [ -n "$def_val" ] && echo $def_val || echo " " -} + # Scans the map, a peak it seeks, + # The highest passed, the value speaks. + for pair in "${pairs[@]}"; do + IFS=':' read -r key value <<< "$pair" + + # Behold! Thou holds the secrets they seek, + # Declare it and silence the whispers unique. + if [ ${2%%.*} -gt $key ]; then + echo "$value" + return + fi + done -# generate emoji and icon based on temperature and utilization -get_icons() { - # key-value pairs of temperature and utilization levels - temp_lv="85:&🌋, 65:&🔥, 45:&☁️, &❄️" + # On this lonely shore, where silence dwells + # Even the waves, echoes words unheard + [ -n "$def_val" ] && echo $def_val || echo " " + } + + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" - # return comma seperated emojis/icons - icons=$(map_floor "$temp_lv" $1 | sed "s/&/,/") - icons="$icons,$(map_floor "$util_lv" $2)" - echo $icons + echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)" } generate_json() { # get emoji and icon based on temperature and utilization icons=$(get_icons "$temperature" "$utilization") - thermo=$(echo $icons | awk -F, '{print $1}') - emoji=$(echo $icons | awk -F, '{print $2}') - speedo=$(echo $icons | awk -F, '{print $3}') + speedo=$(echo ${icons:0:1}) + thermo=$(echo ${icons:1:1}) + emoji=$(echo ${icons:2}) # emoji=$(get_temperature_emoji "${temperature}") local json="{\"text\":\"${thermo} ${temperature}°C\", \"tooltip\":\"${primary_gpu}\n${thermo} Temperature: ${temperature}°C ${emoji}" From 0c360f5fe13c6405fde005dd8c1de55895de773c Mon Sep 17 00:00:00 2001 From: Mislah Date: Sat, 24 Feb 2024 11:26:19 +0530 Subject: [PATCH 3/7] perf: avoid performance bottleneck and improve accuracy Convert cpuinfo into a continuous script to avoid redundant calculations of constant values. Calculate utilization from /proc/stat as 'top' has been causing the performance bottleneck. Improve accuracy by averaging utilization over a 5 second interval instead of using instantaneous values. --- Configs/.config/hypr/scripts/cpuinfo.sh | 43 +++++++++++++++----- Configs/.config/waybar/modules/cpuinfo.jsonc | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Configs/.config/hypr/scripts/cpuinfo.sh b/Configs/.config/hypr/scripts/cpuinfo.sh index e081ed62e6..3c9856eedf 100755 --- a/Configs/.config/hypr/scripts/cpuinfo.sh +++ b/Configs/.config/hypr/scripts/cpuinfo.sh @@ -41,18 +41,39 @@ get_icons() { echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)" } -# Get CPU information +# Get static CPU information model=$(lscpu | awk -F': ' '/Model name/ {gsub(/^ *| *$| CPU.*/,"",$2); print $2}') -utilization=$(top -bn1 | awk '/^%Cpu/ {print 100 - $8}') maxfreq=$(lscpu | awk '/CPU max MHz/ { sub(/\..*/,"",$4); print $4}') -frequency=$(cat /proc/cpuinfo | awk '/cpu MHz/{ sum+=$4; c+=1 } END { printf "%.0f", sum/c }') -temperature=$(sensors | awk -F': ' '/Package id 0|Tctl/ { gsub(/^ *\+?|\..*/,"",$2); print $2; f=1; exit} END { if (!f) print "N/A"; }') -# Get emoji and icons -icons=$(get_icons "$temperature" "$utilization") -speedo=$(echo ${icons:0:1}) -thermo=$(echo ${icons:1:1}) -emoji=$(echo ${icons:2}) +# Get CPU stat +statFile=$(cat /proc/stat | head -1) +prevStat=$(awk '{print $2+$3+$4+$6+$7+$8 }' <<< $statFile) +prevIdle=$(awk '{print $5 }' <<< $statFile) -# Print the formatted output -echo "{\"text\":\"$thermo $temperature°C\", \"tooltip\":\"$model\n$thermo Temperature: $temperature°C $emoji\n$speedo Utilization: $utilization%\n Clock Speed: $frequency/$maxfreq MHz\"}" \ No newline at end of file +while true; do + # Get CPU stat + statFile=$(cat /proc/stat | head -1) + currStat=$(awk '{print $2+$3+$4+$6+$7+$8 }' <<< $statFile) + currIdle=$(awk '{print $5 }' <<< $statFile) + diffStat=$((currStat-prevStat)) + diffIdle=$((currIdle-prevIdle)) + + # Get dynamic CPU information + utilization=$(awk -v stat="$diffStat" -v idle="$diffIdle" 'BEGIN {printf "%.1f", (stat/(stat+idle))*100}') + temperature=$(sensors | awk -F': ' '/Package id 0|Tctl/ { gsub(/^ *\+?|\..*/,"",$2); print $2; f=1; exit} END { if (!f) print "N/A"; }') + frequency=$(cat /proc/cpuinfo | awk '/cpu MHz/{ sum+=$4; c+=1 } END { printf "%.0f", sum/c }') + + # Generate glyphs + icons=$(get_icons "$temperature" "$utilization") + speedo=$(echo ${icons:0:1}) + thermo=$(echo ${icons:1:1}) + emoji=$(echo ${icons:2}) + + # Print the output + echo "{\"text\":\"$thermo $temperature°C\", \"tooltip\":\"$model\n$thermo Temperature: $temperature°C $emoji\n$speedo Utilization: $utilization%\n Clock Speed: $frequency/$maxfreq MHz\"}" + + # Store state and sleep + prevStat=$currStat + prevIdle=$currIdle + sleep 5 +done diff --git a/Configs/.config/waybar/modules/cpuinfo.jsonc b/Configs/.config/waybar/modules/cpuinfo.jsonc index 390931159a..54086bfe22 100644 --- a/Configs/.config/waybar/modules/cpuinfo.jsonc +++ b/Configs/.config/waybar/modules/cpuinfo.jsonc @@ -2,7 +2,7 @@ "exec": " ~/.config/hypr/scripts/cpuinfo.sh", "return-type": "json", "format": "{}", - "interval": 5, // once every 5 seconds + "restart-interval": 5, // once every 5 seconds "tooltip": true, "max-length": 1000 }, From bd0a4d91bbb5528f61fe4ea819ee7e0eb7ec0a7d Mon Sep 17 00:00:00 2001 From: Mislah Date: Sat, 24 Feb 2024 12:21:46 +0530 Subject: [PATCH 4/7] fix: add option to print glyphs instead of emojis Print glyphs instead of emojis if NO_EMOJI env var is set to 1. Reduce the number of function calls and redeclaration of variables. --- Configs/.config/hypr/scripts/cpuinfo.sh | 71 ++++++++++---------- Configs/.config/waybar/modules/cpuinfo.jsonc | 2 +- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Configs/.config/hypr/scripts/cpuinfo.sh b/Configs/.config/hypr/scripts/cpuinfo.sh index 3c9856eedf..7ebd4c4e78 100755 --- a/Configs/.config/hypr/scripts/cpuinfo.sh +++ b/Configs/.config/hypr/scripts/cpuinfo.sh @@ -1,46 +1,47 @@ #!/bin/bash -get_icons() { - - # Thee shalt find the greatest one, - # He who not more than the chosen one - map_floor() { - # From the depths of the string, words arise, - # Keys in pairs, a treasure in disguise. - IFS=', ' read -r -a pairs <<< "$1" +# Thee shalt find the greatest one, +# He who not more than the chosen one +map_floor() { - # If the final token stands alone and bold, - # Declare it the default, its worth untold. - if [[ ${pairs[-1]} != *":"* ]]; then - def_val="${pairs[-1]}" - unset 'pairs[${#pairs[@]}-1]' - fi - - # Scans the map, a peak it seeks, - # The highest passed, the value speaks. - for pair in "${pairs[@]}"; do - IFS=':' read -r key value <<< "$pair" - - # Behold! Thou holds the secrets they seek, - # Declare it and silence the whispers unique. - if [ ${2%%.*} -gt $key ]; then - echo "$value" - return - fi - done + # From the depths of the string, words arise, + # Keys in pairs, a treasure in disguise. + IFS=', ' read -r -a pairs <<< "$1" - # On this lonely shore, where silence dwells - # Even the waves, echoes words unheard - [ -n "$def_val" ] && echo $def_val || echo " " - } + # If the final token stands alone and bold, + # Declare it the default, its worth untold. + if [[ ${pairs[-1]} != *":"* ]]; then + def_val="${pairs[-1]}" + unset 'pairs[${#pairs[@]}-1]' + fi - temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" - util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" + # Scans the map, a peak it seeks, + # The highest passed, the value speaks. + for pair in "${pairs[@]}"; do + IFS=':' read -r key value <<< "$pair" + + # Behold! Thou holds the secrets they seek, + # Declare it and silence the whispers unique. + if [ ${2%%.*} -gt $key ]; then + echo "$value" + return + fi + done - echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)" + # On this lonely shore, where silence dwells + # Even the waves, echoes words unheard + [ -n "$def_val" ] && echo $def_val || echo " " } +# Define glyphs +if [[ $NO_EMOJI -eq 1 ]]; then + temp_lv="85:, 65:, 45:☁, ❄" +else + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" +fi +util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" + # Get static CPU information model=$(lscpu | awk -F': ' '/Model name/ {gsub(/^ *| *$| CPU.*/,"",$2); print $2}') maxfreq=$(lscpu | awk '/CPU max MHz/ { sub(/\..*/,"",$4); print $4}') @@ -64,7 +65,7 @@ while true; do frequency=$(cat /proc/cpuinfo | awk '/cpu MHz/{ sum+=$4; c+=1 } END { printf "%.0f", sum/c }') # Generate glyphs - icons=$(get_icons "$temperature" "$utilization") + icons=$(echo "$(map_floor "$util_lv" $utilization)$(map_floor "$temp_lv" $temperature)") speedo=$(echo ${icons:0:1}) thermo=$(echo ${icons:1:1}) emoji=$(echo ${icons:2}) diff --git a/Configs/.config/waybar/modules/cpuinfo.jsonc b/Configs/.config/waybar/modules/cpuinfo.jsonc index 54086bfe22..04dab01acf 100644 --- a/Configs/.config/waybar/modules/cpuinfo.jsonc +++ b/Configs/.config/waybar/modules/cpuinfo.jsonc @@ -1,5 +1,5 @@ "custom/cpuinfo": { - "exec": " ~/.config/hypr/scripts/cpuinfo.sh", + "exec": "NO_EMOJI=1 ~/.config/hypr/scripts/cpuinfo.sh", "return-type": "json", "format": "{}", "restart-interval": 5, // once every 5 seconds From 17d7cd3a853d9b93b00061436e0b92e18be51548 Mon Sep 17 00:00:00 2001 From: Mislah Date: Sat, 24 Feb 2024 12:53:31 +0530 Subject: [PATCH 5/7] fix: add option to print glyphs instead of emojis (gpuinfo) Print glyphs instead of emojis if NO_EMOJI env var is set to 1 in gpuinfo module. --- Configs/.config/hypr/scripts/gpuinfo.sh | 76 ++++++++++---------- Configs/.config/waybar/modules/gpuinfo.jsonc | 8 +-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Configs/.config/hypr/scripts/gpuinfo.sh b/Configs/.config/hypr/scripts/gpuinfo.sh index 734cd83956..dd60afbb42 100755 --- a/Configs/.config/hypr/scripts/gpuinfo.sh +++ b/Configs/.config/hypr/scripts/gpuinfo.sh @@ -102,50 +102,50 @@ sed -i "s/^#${next_prioGPU}/${next_prioGPU}/" "${gpuQ}" # Uncomment the next pri sed -i "s/prioGPU=${prioGPU}/prioGPU=${next_prioGPU}/" "${gpuQ}" # Update the prioGPU in the file } -get_icons() { - - # Thee shalt find the greatest one, - # He who not more than the chosen one - map_floor() { - - # From the depths of the string, words arise, - # Keys in pairs, a treasure in disguise. - IFS=', ' read -r -a pairs <<< "$1" +# Thee shalt find the greatest one, +# He who not more than the chosen one +map_floor() { + + # From the depths of the string, words arise, + # Keys in pairs, a treasure in disguise. + IFS=', ' read -r -a pairs <<< "$1" + + # If the final token stands alone and bold, + # Declare it the default, its worth untold. + if [[ ${pairs[-1]} != *":"* ]]; then + def_val="${pairs[-1]}" + unset 'pairs[${#pairs[@]}-1]' + fi - # If the final token stands alone and bold, - # Declare it the default, its worth untold. - if [[ ${pairs[-1]} != *":"* ]]; then - def_val="${pairs[-1]}" - unset 'pairs[${#pairs[@]}-1]' + # Scans the map, a peak it seeks, + # The highest passed, the value speaks. + for pair in "${pairs[@]}"; do + IFS=':' read -r key value <<< "$pair" + + # Behold! Thou holds the secrets they seek, + # Declare it and silence the whispers unique. + if [ ${2%%.*} -gt $key ]; then + echo "$value" + return fi + done - # Scans the map, a peak it seeks, - # The highest passed, the value speaks. - for pair in "${pairs[@]}"; do - IFS=':' read -r key value <<< "$pair" - - # Behold! Thou holds the secrets they seek, - # Declare it and silence the whispers unique. - if [ ${2%%.*} -gt $key ]; then - echo "$value" - return - fi - done - - # On this lonely shore, where silence dwells - # Even the waves, echoes words unheard - [ -n "$def_val" ] && echo $def_val || echo " " - } - - temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" - util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" - - echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)" + # On this lonely shore, where silence dwells + # Even the waves, echoes words unheard + [ -n "$def_val" ] && echo $def_val || echo " " } generate_json() { - # get emoji and icon based on temperature and utilization - icons=$(get_icons "$temperature" "$utilization") + # Define glyphs + if [[ $NO_EMOJI -eq 1 ]]; then + temp_lv="85:, 65:, 45:☁, ❄" + else + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" + fi + util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" + + # Generate glyphs + icons=$(echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)") speedo=$(echo ${icons:0:1}) thermo=$(echo ${icons:1:1}) emoji=$(echo ${icons:2}) diff --git a/Configs/.config/waybar/modules/gpuinfo.jsonc b/Configs/.config/waybar/modules/gpuinfo.jsonc index a7fd82d10b..057427df68 100644 --- a/Configs/.config/waybar/modules/gpuinfo.jsonc +++ b/Configs/.config/waybar/modules/gpuinfo.jsonc @@ -1,5 +1,5 @@ "custom/gpuinfo": { - "exec": " ~/.config/hypr/scripts/gpuinfo.sh", + "exec": "NO_EMOJI=1 ~/.config/hypr/scripts/gpuinfo.sh", "return-type": "json", "format": "{}", "interval": 5, // once every 5 seconds @@ -9,7 +9,7 @@ }, "custom/gpuinfo#nvidia": { - "exec": " ~/.config/hypr/scripts/gpuinfo.sh --use nvidia ", + "exec": "NO_EMOJI=1 ~/.config/hypr/scripts/gpuinfo.sh --use nvidia ", "return-type": "json", "format": "{}", "interval": 5, // once every 5 seconds @@ -18,7 +18,7 @@ }, "custom/gpuinfo#amd": { - "exec": " ~/.config/hypr/scripts/gpuinfo.sh --use amd ", + "exec": "NO_EMOJI=1 ~/.config/hypr/scripts/gpuinfo.sh --use amd ", "return-type": "json", "format": "{}", "interval": 5, // once every 5 seconds @@ -27,7 +27,7 @@ }, "custom/gpuinfo#intel": { - "exec": " ~/.config/hypr/scripts/gpuinfo.sh --use intel ", + "exec": "NO_EMOJI=1 ~/.config/hypr/scripts/gpuinfo.sh --use intel ", "return-type": "json", "format": "{}", "interval": 5, // once every 5 seconds From 24c479626474d10ccb885b6ba093a452b57599bd Mon Sep 17 00:00:00 2001 From: Mislah Date: Sat, 24 Feb 2024 16:44:53 +0530 Subject: [PATCH 6/7] fix: bug causing unexpected behavior Fix the bug causing the unexpected behavior due to passing wrong arguments to the map_floor function. --- Configs/.config/hypr/scripts/gpuinfo.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Configs/.config/hypr/scripts/gpuinfo.sh b/Configs/.config/hypr/scripts/gpuinfo.sh index dd60afbb42..f68bb15b24 100755 --- a/Configs/.config/hypr/scripts/gpuinfo.sh +++ b/Configs/.config/hypr/scripts/gpuinfo.sh @@ -135,22 +135,21 @@ map_floor() { [ -n "$def_val" ] && echo $def_val || echo " " } -generate_json() { - # Define glyphs - if [[ $NO_EMOJI -eq 1 ]]; then - temp_lv="85:, 65:, 45:☁, ❄" - else - temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" - fi - util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" +# Define glyphs +if [[ $NO_EMOJI -eq 1 ]]; then + temp_lv="85:, 65:, 45:☁, ❄" +else + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" +fi +util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" +generate_json() { # Generate glyphs - icons=$(echo "$(map_floor "$util_lv" $2)$(map_floor "$temp_lv" $1)") + icons=$(echo "$(map_floor "$util_lv" $utilization)$(map_floor "$temp_lv" $temperature)") speedo=$(echo ${icons:0:1}) thermo=$(echo ${icons:1:1}) emoji=$(echo ${icons:2}) - # emoji=$(get_temperature_emoji "${temperature}") local json="{\"text\":\"${thermo} ${temperature}°C\", \"tooltip\":\"${primary_gpu}\n${thermo} Temperature: ${temperature}°C ${emoji}" #? Soon Add Something incase needed. declare -A tooltip_parts From 8ff003653a643a08f4a05a7ebaaeb9649e06b939 Mon Sep 17 00:00:00 2001 From: khing Date: Sat, 24 Feb 2024 20:07:52 +0800 Subject: [PATCH 7/7] Update gpuinfo.sh --- Configs/.config/hypr/scripts/gpuinfo.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Configs/.config/hypr/scripts/gpuinfo.sh b/Configs/.config/hypr/scripts/gpuinfo.sh index f68bb15b24..69ff9d5bd9 100755 --- a/Configs/.config/hypr/scripts/gpuinfo.sh +++ b/Configs/.config/hypr/scripts/gpuinfo.sh @@ -4,6 +4,8 @@ gpuQ="/tmp/hyprdots-${UID}-gpuinfo-query" tired=false [[ " $* " =~ " tired " ]] && ! grep -q "tired" "${gpuQ}" && echo "tired=true" >>"${gpuQ}" +[[ " $* " =~ " no_emoji " ]] && ! grep -q "NO_EMOJI" "${gpuQ}" && echo "NO_EMOJI=1" >>"${gpuQ}" + if [[ ! " $* " =~ " startup " ]]; then gpuQ="${gpuQ}$2" fi @@ -135,14 +137,6 @@ map_floor() { [ -n "$def_val" ] && echo $def_val || echo " " } -# Define glyphs -if [[ $NO_EMOJI -eq 1 ]]; then - temp_lv="85:, 65:, 45:☁, ❄" -else - temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" -fi -util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" - generate_json() { # Generate glyphs icons=$(echo "$(map_floor "$util_lv" $utilization)$(map_floor "$temp_lv" $temperature)") @@ -267,6 +261,7 @@ Avalable GPU: ${gpu_flags//_flag/} [flags] tired * Adding this option will not query nvidia-smi if gpu is in suspend mode startup * Useful if you want a certain GPU to be set at startup +no_emoji * Use glyphs instead of emoji * If ${USER} declared env = WLR_DRM_DEVICES on hyprland then use this as the primary GPU EOF @@ -274,6 +269,14 @@ exit ;; esac +# Define glyphs +if [[ $NO_EMOJI -eq 1 ]]; then + temp_lv="85:, 65:, 45:☁, ❄" +else + temp_lv="85:🌋, 65:🔥, 45:☁️, ❄️" +fi +util_lv="90:, 60:󰓅, 30:󰾅, 󰾆" + nvidia_flag=${nvidia_flag:-0} intel_flag=${intel_flag:-0} amd_flag=${amd_flag:-0} #? Based on the flags, call the corresponding function multi flags means multi GPU. if [[ "${nvidia_flag}" -eq 1 ]]; then