Add tweak-cpu-usage script.
This limits CPU usage of firefox and vencord to avoid unnecessary excess CPU heat.master
parent
f76a3bec5b
commit
1c9bbb7559
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Tweak CPU usage
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=%h/.local/bin/tweak-cpu-usage
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
set -u
|
||||
|
||||
cores=$(nproc)
|
||||
|
||||
limits=(
|
||||
# process_name:limit%
|
||||
firefox:$(( 50 * cores ))
|
||||
vesktop:$(( 20 * cores ))
|
||||
)
|
||||
|
||||
# check for cpulimit command
|
||||
if ! command -v cpulimit 2>/dev/null >/dev/null; then
|
||||
echo "ERROR: need cpulimit command" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
limit_process() {
|
||||
local process_name="$1"
|
||||
local limit_percentage="${2%%.}"
|
||||
|
||||
cpulimit -i -e "$process_name" -l "$limit_percentage"
|
||||
}
|
||||
|
||||
limit_processes() {
|
||||
local pids
|
||||
pids=()
|
||||
for limit in "${limits[@]}"; do
|
||||
IFS=: read process_name limit_percentage <<<"$limit"
|
||||
limit_process "$process_name" "$limit_percentage" & pids+=($!)
|
||||
done
|
||||
wait "${pids[@]}"
|
||||
}
|
||||
|
||||
limit_processes
|
|
@ -61,3 +61,9 @@ install_files "/etc" etc
|
|||
if command -v fc-cache >/dev/null 2>&1; then
|
||||
fc-cache -f
|
||||
fi
|
||||
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable tweak-cpu-usage
|
||||
systemctl --user restart tweak-cpu-usage
|
||||
fi
|
||||
|
|
|
@ -111,6 +111,7 @@ if has_tags pm:pacman; then
|
|||
# from here on we should have yay available
|
||||
yay_install \
|
||||
bat \
|
||||
cpulimit \
|
||||
customizepkg-git \
|
||||
zsh \
|
||||
zsh-syntax-highlighting \
|
||||
|
@ -155,6 +156,7 @@ if has_tags pm:apt; then
|
|||
zsh \
|
||||
zsh-syntax-highlighting \
|
||||
bat \
|
||||
cpulimit \
|
||||
jq \
|
||||
git \
|
||||
gnupg2
|
||||
|
|
Loading…
Reference in New Issue