2021-01-21 07:55:23 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# auto-cpufreq - core functionality
|
|
|
|
|
|
|
|
import os
|
|
|
|
import platform as pl
|
|
|
|
import shutil
|
|
|
|
import sys
|
2021-02-06 20:08:15 +01:00
|
|
|
import psutil
|
|
|
|
import distro
|
2021-01-21 07:55:23 +01:00
|
|
|
import time
|
2021-02-06 20:08:15 +01:00
|
|
|
import click
|
2023-02-01 16:39:14 +01:00
|
|
|
import pickle
|
2021-01-21 07:55:23 +01:00
|
|
|
import warnings
|
2023-10-13 08:04:49 +02:00
|
|
|
# import pkg_resources
|
|
|
|
import importlib.metadata
|
2021-01-21 07:55:23 +01:00
|
|
|
from math import isclose
|
|
|
|
from pathlib import Path
|
2021-11-04 08:32:50 +01:00
|
|
|
from shutil import which
|
2021-01-24 13:14:11 +01:00
|
|
|
from subprocess import getoutput, call, run, check_output, DEVNULL
|
2023-07-15 21:32:23 +02:00
|
|
|
import requests
|
|
|
|
import re
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2022-06-05 17:41:59 +02:00
|
|
|
# execution timestamp used in countdown func
|
|
|
|
from datetime import datetime
|
|
|
|
|
2021-12-22 08:28:08 +01:00
|
|
|
sys.path.append("../")
|
2021-12-04 15:40:03 +01:00
|
|
|
from auto_cpufreq.power_helper import *
|
2024-04-30 08:35:53 +02:00
|
|
|
from auto_cpufreq.utils.config import config
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
warnings.filterwarnings("ignore")
|
|
|
|
|
Gtk Application for auto-cpufreq (#486)
* Squashed commit of the following:
commit ec7e087b343f33af7a92b190ed666845dab60f20
Merge: 32b6e63 9912f9d
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Mon Feb 13 14:11:21 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit 32b6e632830fe8a7c3a3ce601ef2ba5b254572d7
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 13 14:10:34 2023 -0600
increase MenuButton size
commit 12a2cda82a5f56bfbb532c893d822341e9b2d7cb
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 23:35:33 2023 -0600
set app icon
commit d170d07e866644bcb662bf342530c497390f0303
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 23:35:15 2023 -0600
remove unused pixbuf
commit 993333fb5aad448103e24e38bc85fb04e7e4dd0c
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 22:43:56 2023 -0600
fix MenuButton icon
commit d1b8bd74caab2cf216bf40bdfc35ef3520e891c7
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 17:19:32 2023 -0600
add icon
commit 13f43fa0c7d59b2405bac688119690d01a7ec019
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 17:19:10 2023 -0600
add pkexec policy and change wrapper for gui
commit 4ddbb9c6667aa97bb7cd242fb4a376e061c9b308
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 14:09:35 2023 -0600
add icon to destop entry and about dialog
commit 9912f9d80935bb51c9cb759ab95c9ba7fde15524
Author: Siddharth Kumar Jha <101443068+siddharthkumarjha@users.noreply.github.com>
Date: Sun Feb 12 12:55:14 2023 +0530
Update Readme for issue of auto-cpufreq not autostarting on AUR (#485)
* Updated Readme for issue auto-cpufreq not autostarting
Added solution to issue https://github.com/AdnanHodzic/auto-cpufreq/issues/463
* Fixed minor errors
* Fixed auto-cpufreq.serivce Typo
* Reprashed text as per suggestion
commit 4379024adab282fcdb58a7091df2a6adf833e700
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Tue Feb 7 19:06:59 2023 -0600
add removal of gui and desktop entry
commit 42693703324762418a7f810f04a3d77803afa236
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 6 23:28:44 2023 -0600
CPU stats refresh and style stuff
commit 7149db72c0bb39af57ceccb16df8e9164c77fae3
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 6 23:10:29 2023 -0600
daemon detection, daemon install/removal, and layout stuff
commit f7e03c9bcc2e2578703807ceeb7a652903571b71
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 19:26:42 2023 -0600
improve AboutDialog
Please enter the commit message for your changes. Lines starting
commit cb8cfe7b3194273dea229fe550fdf66cd6af82fa
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 18:28:19 2023 -0600
add dropdown menu and (not completed) about dialog
commit ade1fed790f2ebbaae4e92ce8879ab812c9b2850
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 15:57:17 2023 -0600
actually fix css
commit 67c8c97bcf2f2f408431bc162c38dee5c278ed0b
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 15:54:47 2023 -0600
fix css
commit c65eac3472f724bed10a0f530b2a828463bbe7fe
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Sun Feb 5 09:29:19 2023 +0100
Update readme, install psutil lib for power_helper
commit bd3feae38824764155d31ccd6debc1fcf18830da
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 00:42:52 2023 -0600
add desktop entry for gui
commit 5426a6a443c90a9d65b858ae1951219898cba332
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 00:33:08 2023 -0600
add gui to install file, update required packages, and create wrapper script
commit 84124dfa605b930b3722ed852486cbe11c254092
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 23:28:24 2023 -0600
create system tray
commit 7b0d46d8ddafdeff9006a1ad10ccd99c24b9eb1e
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 23:28:01 2023 -0600
small changes to layout
commit cd51ea317085ac6ea5b4918ef057ad4c19a71640
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 00:44:08 2023 -0600
css styling support
commit 136b449febece04c036b72b4a14ccceb422f62dd
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 00:14:52 2023 -0600
several improvements
commit f9f7170391e1abc1499b7d5ae93327999e013730
Merge: 242a8d0 8f343df
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Fri Feb 3 22:44:01 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit 8f343df8b8b82846364fbc14b2fc2e5144abebaa
Merge: dadfae0 b38919f
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Fri Feb 3 14:54:11 2023 -0600
Merge pull request #481 from shadeyg56/master
Fix uncaught error in checking for snap
commit b38919f56b6329c81c4c96eabe9bfd27d590d16e
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Fri Feb 3 14:48:01 2023 -0600
fix uncaught error in checking for snap
commit 242a8d0401d1ffd00c982aa731c04ef7ea726fee
Merge: f50b982 dadfae0
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Fri Feb 3 14:19:01 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit dadfae087f102c0f69329d5ad79e3a648c35b459
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Fri Feb 3 20:02:03 2023 +0100
Update README with new config options
commit 471611de7da97b7da8580646612d4f910311e16e
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Fri Feb 3 18:44:33 2023 +0100
Remove GNOME Power Profiles Daemon performance install
commit f574257dc475f942fa39179787acf09c567e76dd
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Fri Feb 3 18:32:04 2023 +0100
Remove install_performance flag
commit 04b878360c7dff4b0e44fc8935e9667a597806b4
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Fri Feb 3 17:52:20 2023 +0100
Snap tag 2.0-beta + governor_override improvements
commit fe21ddf24585164ed0f8cfa8f9ad7d3db627ab79
Author: Adnan Hodzic <adnan@hodzic.org>
Date: Fri Feb 3 17:28:12 2023 +0100
Working governor override on Snap package
commit f50b9829e5438bb96ded73775668fa048fcd3951
Merge: a98225e 69ef913
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Thu Feb 2 18:19:10 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit a98225e7280802c2fb09a9a52a40f7e55b26b3b1
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 18:18:43 2023 -0600
Revert "basic GUI"
This reverts commit d2610c921b7209fde7d7be13f187510631cc33b3.
commit 9606472fdbbff6dd551cd291b37349df17098d2e
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 18:13:41 2023 -0600
basic gui
commit d2610c921b7209fde7d7be13f187510631cc33b3
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 17:47:55 2023 -0600
basic GUI
commit bdbe12018b380ed70f100729c9ea3732ba24f572
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 15:21:42 2023 -0600
rename folder
commit 31095c472e4af734a3a601f804787de89ad47964
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Wed Jan 25 23:39:52 2023 -0600
add tray
* Squashed commit of the following:
commit e2eaffc32b382f67f97d2e25858b5b5a4abffeae
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 20 23:08:57 2023 -0600
move text to be inline with menu
commit e1dae9d9de25f13c51dd983f5b4b0fbdf1bf0349
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 19 17:50:26 2023 -0600
move distro info to top of system stats box
commit 959405bedc52dce14f5fd70d2fcd5fbee57e59a5
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 19 17:49:15 2023 -0600
fix app name on GNOME
commit 346093dfce6ce0bfa1954ed3bb6f5364250d05b7
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 19 17:01:03 2023 -0600
fix snap dependencies
commit ec7e087b343f33af7a92b190ed666845dab60f20
Merge: 32b6e63 9912f9d
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Mon Feb 13 14:11:21 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit 32b6e632830fe8a7c3a3ce601ef2ba5b254572d7
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 13 14:10:34 2023 -0600
increase MenuButton size
commit 12a2cda82a5f56bfbb532c893d822341e9b2d7cb
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 23:35:33 2023 -0600
set app icon
commit d170d07e866644bcb662bf342530c497390f0303
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 23:35:15 2023 -0600
remove unused pixbuf
commit 993333fb5aad448103e24e38bc85fb04e7e4dd0c
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 22:43:56 2023 -0600
fix MenuButton icon
commit d1b8bd74caab2cf216bf40bdfc35ef3520e891c7
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 17:19:32 2023 -0600
add icon
commit 13f43fa0c7d59b2405bac688119690d01a7ec019
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 17:19:10 2023 -0600
add pkexec policy and change wrapper for gui
commit 4ddbb9c6667aa97bb7cd242fb4a376e061c9b308
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 12 14:09:35 2023 -0600
add icon to destop entry and about dialog
commit 4379024adab282fcdb58a7091df2a6adf833e700
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Tue Feb 7 19:06:59 2023 -0600
add removal of gui and desktop entry
commit 42693703324762418a7f810f04a3d77803afa236
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 6 23:28:44 2023 -0600
CPU stats refresh and style stuff
commit 7149db72c0bb39af57ceccb16df8e9164c77fae3
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Mon Feb 6 23:10:29 2023 -0600
daemon detection, daemon install/removal, and layout stuff
commit f7e03c9bcc2e2578703807ceeb7a652903571b71
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 19:26:42 2023 -0600
improve AboutDialog
Please enter the commit message for your changes. Lines starting
commit cb8cfe7b3194273dea229fe550fdf66cd6af82fa
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 18:28:19 2023 -0600
add dropdown menu and (not completed) about dialog
commit ade1fed790f2ebbaae4e92ce8879ab812c9b2850
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 15:57:17 2023 -0600
actually fix css
commit 67c8c97bcf2f2f408431bc162c38dee5c278ed0b
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 15:54:47 2023 -0600
fix css
commit bd3feae38824764155d31ccd6debc1fcf18830da
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 00:42:52 2023 -0600
add desktop entry for gui
commit 5426a6a443c90a9d65b858ae1951219898cba332
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sun Feb 5 00:33:08 2023 -0600
add gui to install file, update required packages, and create wrapper script
commit 84124dfa605b930b3722ed852486cbe11c254092
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 23:28:24 2023 -0600
create system tray
commit 7b0d46d8ddafdeff9006a1ad10ccd99c24b9eb1e
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 23:28:01 2023 -0600
small changes to layout
commit cd51ea317085ac6ea5b4918ef057ad4c19a71640
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 00:44:08 2023 -0600
css styling support
commit 136b449febece04c036b72b4a14ccceb422f62dd
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Sat Feb 4 00:14:52 2023 -0600
several improvements
commit f9f7170391e1abc1499b7d5ae93327999e013730
Merge: 242a8d0 8f343df
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Fri Feb 3 22:44:01 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit 242a8d0401d1ffd00c982aa731c04ef7ea726fee
Merge: f50b982 dadfae0
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Fri Feb 3 14:19:01 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit f50b9829e5438bb96ded73775668fa048fcd3951
Merge: a98225e 69ef913
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date: Thu Feb 2 18:19:10 2023 -0600
Merge branch 'AdnanHodzic:master' into gui
commit a98225e7280802c2fb09a9a52a40f7e55b26b3b1
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 18:18:43 2023 -0600
Revert "basic GUI"
This reverts commit d2610c921b7209fde7d7be13f187510631cc33b3.
commit 9606472fdbbff6dd551cd291b37349df17098d2e
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 18:13:41 2023 -0600
basic gui
commit d2610c921b7209fde7d7be13f187510631cc33b3
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 17:47:55 2023 -0600
basic GUI
commit bdbe12018b380ed70f100729c9ea3732ba24f572
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Thu Feb 2 15:21:42 2023 -0600
rename folder
commit 31095c472e4af734a3a601f804787de89ad47964
Author: shadeyg56 <shadeyg56@gmail.com>
Date: Wed Jan 25 23:39:52 2023 -0600
add tray
* fix undefined var
* app no longer needs root to start, only asks when needed
* fix wmclass
* create file in /bin for gui
* fix bug with radio buttons and pkexec
* snap: update snap to package GTK gui
* update setup.py
* requirements.txt: fix conflict
* Merge master into dev
* gui: fix pkexec on launch
2023-08-15 17:58:16 +02:00
|
|
|
# add path to auto-cpufreq executables for GUI
|
|
|
|
os.environ["PATH"] += ":/usr/local/bin"
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# ToDo:
|
|
|
|
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2)
|
|
|
|
|
|
|
|
SCRIPTS_DIR = Path("/usr/local/share/auto-cpufreq/scripts/")
|
|
|
|
|
|
|
|
# from the highest performance to the lowest
|
2021-03-11 18:29:20 +01:00
|
|
|
ALL_GOVERNORS = (
|
|
|
|
"performance",
|
|
|
|
"ondemand",
|
|
|
|
"conservative",
|
|
|
|
"schedutil",
|
|
|
|
"userspace",
|
|
|
|
"powersave",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
CPUS = os.cpu_count()
|
|
|
|
|
2021-12-24 20:21:40 +01:00
|
|
|
# ignore these devices under /sys/class/power_supply/
|
|
|
|
POWER_SUPPLY_IGNORELIST = ["hidpp_battery"]
|
|
|
|
|
2021-01-24 13:14:11 +01:00
|
|
|
# Note:
|
2021-01-21 07:55:23 +01:00
|
|
|
# "load1m" & "cpuload" can't be global vars and to in order to show correct data must be
|
|
|
|
# decraled where their execution takes place
|
|
|
|
|
|
|
|
# powersave/performance system load thresholds
|
2021-03-11 18:29:20 +01:00
|
|
|
powersave_load_threshold = (75 * CPUS) / 100
|
|
|
|
performance_load_threshold = (50 * CPUS) / 100
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
# auto-cpufreq stats file path
|
|
|
|
auto_cpufreq_stats_path = None
|
|
|
|
auto_cpufreq_stats_file = None
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2023-02-01 16:39:14 +01:00
|
|
|
# track governor override
|
2023-02-03 17:28:12 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
|
|
|
governor_override_state = Path("/var/snap/auto-cpufreq/current/override.pickle")
|
|
|
|
else:
|
2023-02-03 17:52:20 +01:00
|
|
|
governor_override_state = Path("/opt/auto-cpufreq/override.pickle")
|
2023-02-01 16:39:14 +01:00
|
|
|
|
2021-01-24 13:14:11 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
2021-02-02 21:40:55 +01:00
|
|
|
auto_cpufreq_stats_path = Path("/var/snap/auto-cpufreq/current/auto-cpufreq.stats")
|
2021-01-24 13:14:11 +01:00
|
|
|
else:
|
2021-02-02 21:40:55 +01:00
|
|
|
auto_cpufreq_stats_path = Path("/var/run/auto-cpufreq.stats")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# daemon check
|
|
|
|
dcheck = getoutput("snapctl get daemon")
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
def file_stats():
|
|
|
|
global auto_cpufreq_stats_file
|
|
|
|
auto_cpufreq_stats_file = open(auto_cpufreq_stats_path, "w")
|
|
|
|
sys.stdout = auto_cpufreq_stats_file
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2023-02-01 16:39:14 +01:00
|
|
|
def get_override():
|
2023-02-03 17:28:12 +01:00
|
|
|
if os.path.isfile(governor_override_state):
|
|
|
|
with open(governor_override_state, "rb") as store:
|
2023-02-01 16:39:14 +01:00
|
|
|
return pickle.load(store)
|
|
|
|
else:
|
|
|
|
return "default"
|
|
|
|
|
|
|
|
def set_override(override):
|
|
|
|
if override in ["powersave", "performance"]:
|
2023-02-03 17:28:12 +01:00
|
|
|
with open(governor_override_state, "wb") as store:
|
2023-02-01 16:39:14 +01:00
|
|
|
pickle.dump(override, store)
|
|
|
|
print(f"Set governor override to {override}")
|
|
|
|
elif override == "reset":
|
2023-02-03 17:28:12 +01:00
|
|
|
if os.path.isfile(governor_override_state):
|
|
|
|
os.remove(governor_override_state)
|
2023-02-01 16:39:14 +01:00
|
|
|
print("Governor override removed")
|
|
|
|
elif override is not None:
|
|
|
|
print("Invalid option.\nUse force=performance, force=powersave, or force=reset")
|
|
|
|
|
|
|
|
|
2021-12-22 08:28:08 +01:00
|
|
|
|
2021-02-04 23:27:19 +01:00
|
|
|
# get distro name
|
2021-12-19 09:20:09 +01:00
|
|
|
try:
|
|
|
|
dist_name = distro.id()
|
|
|
|
except PermissionError:
|
2021-12-23 19:22:46 +01:00
|
|
|
# Current work-around for Pop!_OS where symlink causes permission issues
|
|
|
|
print("[!] Warning: Cannot get distro name")
|
2021-12-19 09:20:09 +01:00
|
|
|
if os.path.exists("/etc/pop-os/os-release"):
|
2024-05-06 13:58:38 +02:00
|
|
|
# Check if using a Snap
|
2021-12-23 19:22:46 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
2024-05-06 13:58:38 +02:00
|
|
|
print("[!] Snap install on PopOS detected, you must manually run the following"
|
|
|
|
" commands in another terminal:\n")
|
2021-12-23 19:22:46 +01:00
|
|
|
print("[!] Backup the /etc/os-release file:")
|
2024-05-06 13:58:38 +02:00
|
|
|
print("sudo mv /etc/os-release /etc/os-release-backup\n")
|
2021-12-23 19:22:46 +01:00
|
|
|
print("[!] Create hardlink to /etc/os-release:")
|
2024-05-06 13:58:38 +02:00
|
|
|
print("sudo ln /etc/pop-os/os-release /etc/os-release\n")
|
2021-12-23 19:22:46 +01:00
|
|
|
print("[!] Aborting. Restart auto-cpufreq when you created the hardlink")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
# This should not be the case. But better be sure.
|
|
|
|
print("[!] Check /etc/os-release permissions and make sure it is not a symbolic link")
|
|
|
|
print("[!] Aborting...")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-12-19 09:20:09 +01:00
|
|
|
else:
|
2021-12-23 19:22:46 +01:00
|
|
|
print("[!] Check /etc/os-release permissions and make sure it is not a symbolic link")
|
|
|
|
print("[!] Aborting...")
|
2021-12-19 09:20:09 +01:00
|
|
|
sys.exit(1)
|
2021-02-04 23:27:19 +01:00
|
|
|
|
|
|
|
# display running version of auto-cpufreq
|
2021-01-21 07:55:23 +01:00
|
|
|
def app_version():
|
2021-02-04 23:27:19 +01:00
|
|
|
|
2022-01-09 13:49:41 +01:00
|
|
|
print("auto-cpufreq version: ", end="")
|
2021-02-06 20:41:06 +01:00
|
|
|
|
2021-02-04 23:27:19 +01:00
|
|
|
# snap package
|
2021-03-11 18:29:20 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
2023-10-12 00:16:51 +02:00
|
|
|
print(getoutput(r"echo \(Snap\) $SNAP_VERSION"))
|
2021-02-04 23:27:19 +01:00
|
|
|
# aur package
|
|
|
|
elif dist_name in ["arch", "manjaro", "garuda"]:
|
2021-02-07 19:26:34 +01:00
|
|
|
aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True)
|
2021-02-06 20:41:06 +01:00
|
|
|
if aur_pkg_check == 1:
|
2022-01-09 13:49:41 +01:00
|
|
|
print(get_formatted_version())
|
2021-02-06 20:41:06 +01:00
|
|
|
else:
|
2021-02-07 19:25:08 +01:00
|
|
|
print(getoutput("pacman -Qi auto-cpufreq | grep Version"))
|
2021-03-11 18:29:20 +01:00
|
|
|
else:
|
2021-02-04 23:27:19 +01:00
|
|
|
# source code (auto-cpufreq-installer)
|
|
|
|
try:
|
2022-01-09 13:49:41 +01:00
|
|
|
print(get_formatted_version())
|
2021-03-11 18:29:20 +01:00
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
2021-02-04 23:27:19 +01:00
|
|
|
pass
|
2023-10-27 11:38:42 +02:00
|
|
|
|
|
|
|
def check_for_update():
|
|
|
|
# returns True if a new release is available from the GitHub repo
|
|
|
|
|
2023-07-15 21:32:23 +02:00
|
|
|
# Specify the repository and package name
|
|
|
|
# IT IS IMPORTANT TO THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY
|
|
|
|
# Fetch the latest release information from GitHub API
|
|
|
|
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
|
2023-09-18 21:09:56 +02:00
|
|
|
try:
|
2024-02-26 02:40:04 +01:00
|
|
|
response = requests.get(latest_release_url)
|
|
|
|
if response.status_code == 200:
|
|
|
|
latest_release = response.json()
|
|
|
|
else:
|
|
|
|
message = response.json().get("message")
|
|
|
|
print("Error fetching recent release!")
|
|
|
|
if message is not None and message.startswith("API rate limit exceeded"):
|
|
|
|
print("GitHub Rate limit exceeded. Please try again later within 1 hour or use different network/VPN.")
|
2024-05-06 13:58:38 +02:00
|
|
|
else:
|
2024-02-26 02:40:04 +01:00
|
|
|
print("Unexpected status code:", response.status_code)
|
|
|
|
return False
|
2023-09-18 21:09:56 +02:00
|
|
|
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
|
|
|
|
requests.exceptions.RequestException, requests.exceptions.HTTPError) as err:
|
2024-02-26 02:40:04 +01:00
|
|
|
print("Error Connecting to server!")
|
2024-01-21 13:08:31 +01:00
|
|
|
return False
|
2023-09-18 21:09:56 +02:00
|
|
|
|
2024-02-26 02:40:04 +01:00
|
|
|
latest_version = latest_release.get("tag_name")
|
2023-07-15 21:32:23 +02:00
|
|
|
|
2024-02-26 02:40:04 +01:00
|
|
|
if latest_version is not None:
|
|
|
|
# Get the current version of auto-cpufreq
|
|
|
|
# Extract version number from the output string
|
|
|
|
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
|
|
|
|
try:
|
|
|
|
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
|
|
|
|
except AttributeError:
|
|
|
|
print("Error Retrieving Current Version!")
|
|
|
|
exit(1)
|
|
|
|
installed_version = "v" + version_line
|
|
|
|
#Check whether the same is installed or not
|
|
|
|
# Compare the latest version with the installed version and perform update if necessary
|
|
|
|
if latest_version == installed_version:
|
|
|
|
print("auto-cpufreq is up to date")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
|
|
|
|
print("Note that your previous custom settings might be erased with the following update")
|
|
|
|
return True
|
2023-07-15 21:32:23 +02:00
|
|
|
else:
|
2024-02-26 02:40:04 +01:00
|
|
|
# Handle the case where "tag_name" key doesn't exist
|
|
|
|
print("Malformed Released data!\nReinstall manually or Open an issue on GitHub for help!")
|
|
|
|
|
2024-05-06 13:58:38 +02:00
|
|
|
|
|
|
|
|
2023-09-18 19:59:46 +02:00
|
|
|
def new_update(custom_dir):
|
|
|
|
os.chdir(custom_dir)
|
|
|
|
print(f"Cloning the latest release to {custom_dir}")
|
2023-07-15 21:32:23 +02:00
|
|
|
run(["git", "clone", "https://github.com/AdnanHodzic/auto-cpufreq.git"])
|
|
|
|
os.chdir("auto-cpufreq")
|
2023-09-18 19:59:46 +02:00
|
|
|
print(f"package cloned to directory {custom_dir}")
|
2023-07-15 21:32:23 +02:00
|
|
|
run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8')
|
2023-09-18 21:09:56 +02:00
|
|
|
|
2023-10-13 08:04:49 +02:00
|
|
|
def get_literal_version(package_name):
|
|
|
|
try:
|
|
|
|
package_metadata = importlib.metadata.metadata(package_name)
|
|
|
|
|
|
|
|
package_name = package_metadata['Name']
|
|
|
|
metadata_version = package_metadata['Version']
|
|
|
|
|
|
|
|
numbered_version, _, git_version = metadata_version.partition("+")
|
|
|
|
|
|
|
|
# Construct the literal version string
|
|
|
|
literal_version = f"{numbered_version}+{git_version}"
|
|
|
|
|
|
|
|
return literal_version
|
|
|
|
|
|
|
|
except importlib.metadata.PackageNotFoundError:
|
|
|
|
return f"Package '{package_name}' not found"
|
|
|
|
|
2022-01-09 13:49:41 +01:00
|
|
|
# return formatted version for a better readability
|
|
|
|
def get_formatted_version():
|
2023-10-13 08:04:49 +02:00
|
|
|
literal_version = get_literal_version("auto-cpufreq")
|
2022-01-09 13:49:41 +01:00
|
|
|
splitted_version = literal_version.split("+")
|
|
|
|
formatted_version = splitted_version[0]
|
2024-05-06 13:58:38 +02:00
|
|
|
|
2022-01-09 13:49:41 +01:00
|
|
|
if len(splitted_version) > 1:
|
|
|
|
formatted_version += " (git: " + splitted_version[1] + ")"
|
|
|
|
|
|
|
|
return formatted_version
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def app_res_use():
|
|
|
|
p = psutil.Process()
|
|
|
|
print("auto-cpufreq system resource consumption:")
|
|
|
|
print("cpu usage:", p.cpu_percent(), "%")
|
2021-03-11 18:29:20 +01:00
|
|
|
print("memory use:", round(p.memory_percent(), 2), "%")
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# set/change state of turbo
|
|
|
|
def turbo(value: bool = None):
|
|
|
|
"""
|
|
|
|
Get and set turbo mode
|
|
|
|
"""
|
|
|
|
p_state = Path("/sys/devices/system/cpu/intel_pstate/no_turbo")
|
|
|
|
cpufreq = Path("/sys/devices/system/cpu/cpufreq/boost")
|
2024-04-09 21:28:56 +02:00
|
|
|
amd_pstate = Path("/sys/devices/system/cpu/amd_pstate/status")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
if p_state.exists():
|
|
|
|
inverse = True
|
|
|
|
f = p_state
|
|
|
|
elif cpufreq.exists():
|
|
|
|
f = cpufreq
|
|
|
|
inverse = False
|
2024-04-09 21:28:56 +02:00
|
|
|
elif amd_pstate.exists():
|
|
|
|
amd_value = amd_pstate.read_text().strip()
|
|
|
|
if amd_value == "active":
|
|
|
|
print("CPU turbo is controlled by amd-pstate-epp driver")
|
|
|
|
# Basically, no other value should exist.
|
|
|
|
return False
|
2021-01-21 07:55:23 +01:00
|
|
|
else:
|
|
|
|
print("Warning: CPU turbo is not available")
|
|
|
|
return False
|
|
|
|
|
|
|
|
if value is not None:
|
|
|
|
if inverse:
|
|
|
|
value = not value
|
|
|
|
|
|
|
|
try:
|
|
|
|
f.write_text(str(int(value)) + "\n")
|
|
|
|
except PermissionError:
|
|
|
|
print("Warning: Changing CPU turbo is not supported. Skipping.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
value = bool(int(f.read_text().strip()))
|
|
|
|
if inverse:
|
|
|
|
value = not value
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
|
|
|
# display current state of turbo
|
2021-01-21 07:55:23 +01:00
|
|
|
def get_turbo():
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
if turbo():
|
|
|
|
print("Currently turbo boost is: on")
|
|
|
|
else:
|
|
|
|
print("Currently turbo boost is: off")
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def charging():
|
|
|
|
"""
|
|
|
|
get charge state: is battery charging or discharging
|
|
|
|
"""
|
2021-12-16 08:04:24 +01:00
|
|
|
power_supply_path = "/sys/class/power_supply/"
|
|
|
|
power_supplies = os.listdir(Path(power_supply_path))
|
2021-12-24 20:21:40 +01:00
|
|
|
# sort it so AC is 'always' first
|
|
|
|
power_supplies = sorted(power_supplies)
|
2021-12-16 08:04:24 +01:00
|
|
|
|
|
|
|
# check if we found power supplies. on a desktop these are not found
|
|
|
|
# and we assume we are on a powercable.
|
|
|
|
if len(power_supplies) == 0:
|
|
|
|
# nothing found found, so nothing to check
|
|
|
|
return True
|
|
|
|
# we found some power supplies, lets check their state
|
2021-02-02 21:21:51 +01:00
|
|
|
else:
|
2021-12-16 08:04:24 +01:00
|
|
|
for supply in power_supplies:
|
2021-12-24 20:21:40 +01:00
|
|
|
# Check if supply is in ignore list
|
|
|
|
ignore_supply = any(item in supply for item in POWER_SUPPLY_IGNORELIST)
|
|
|
|
# If found in ignore list, skip it.
|
|
|
|
if ignore_supply:
|
2021-12-21 18:25:46 +01:00
|
|
|
continue
|
2021-12-24 20:21:40 +01:00
|
|
|
|
2021-12-16 08:04:24 +01:00
|
|
|
try:
|
|
|
|
with open(Path(power_supply_path + supply + "/type")) as f:
|
|
|
|
supply_type = f.read()[:-1]
|
|
|
|
if supply_type == "Mains":
|
|
|
|
# we found an AC
|
|
|
|
try:
|
|
|
|
with open(Path(power_supply_path + supply + "/online")) as f:
|
|
|
|
val = int(f.read()[:-1])
|
|
|
|
if val == 1:
|
|
|
|
# we are definitely charging
|
|
|
|
return True
|
|
|
|
except FileNotFoundError:
|
|
|
|
# we could not find online, check next item
|
|
|
|
continue
|
|
|
|
elif supply_type == "Battery":
|
|
|
|
# we found a battery, check if its being discharged
|
|
|
|
try:
|
|
|
|
with open(Path(power_supply_path + supply + "/status")) as f:
|
|
|
|
val = str(f.read()[:-1])
|
|
|
|
if val == "Discharging":
|
|
|
|
# we found a discharging battery
|
|
|
|
return False
|
|
|
|
except FileNotFoundError:
|
|
|
|
# could not find status, check the next item
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# continue to next item because current is not
|
|
|
|
# "Mains" or "Battery"
|
|
|
|
continue
|
|
|
|
except FileNotFoundError:
|
|
|
|
# could not find type, check the next item
|
|
|
|
continue
|
|
|
|
|
|
|
|
# we cannot determine discharging state, assume we are on powercable
|
|
|
|
return True
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
def get_avail_gov():
|
|
|
|
f = Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors")
|
|
|
|
return f.read_text().strip().split(" ")
|
|
|
|
|
|
|
|
|
|
|
|
def get_avail_powersave():
|
|
|
|
"""
|
|
|
|
Iterate over ALL_GOVERNORS in reverse order: from powersave to performance
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
for g in ALL_GOVERNORS[::-1]:
|
|
|
|
if g in get_avail_gov():
|
|
|
|
return g
|
|
|
|
|
|
|
|
|
|
|
|
def get_avail_performance():
|
|
|
|
for g in ALL_GOVERNORS:
|
|
|
|
if g in get_avail_gov():
|
|
|
|
return g
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_gov():
|
2021-03-11 18:29:20 +01:00
|
|
|
return print(
|
|
|
|
"Currently using:",
|
|
|
|
getoutput("cpufreqctl.auto-cpufreq --governor").strip().split(" ")[0],
|
|
|
|
"governor",
|
|
|
|
)
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
def cpufreqctl():
|
|
|
|
"""
|
|
|
|
deploy cpufreqctl script
|
|
|
|
"""
|
|
|
|
|
|
|
|
# detect if running on a SNAP
|
2021-03-11 18:29:20 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
2021-01-21 07:55:23 +01:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# deploy cpufreqctl.auto-cpufreq script
|
2022-11-24 17:44:57 +01:00
|
|
|
if not os.path.isfile("/usr/local/bin/cpufreqctl.auto-cpufreq"):
|
|
|
|
shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/local/bin/cpufreqctl.auto-cpufreq")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
def cpufreqctl_restore():
|
|
|
|
"""
|
|
|
|
remove cpufreqctl.auto-cpufreq script
|
|
|
|
"""
|
|
|
|
# detect if running on a SNAP
|
2021-03-11 18:29:20 +01:00
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
2021-01-21 07:55:23 +01:00
|
|
|
pass
|
|
|
|
else:
|
2022-11-24 17:44:57 +01:00
|
|
|
if os.path.isfile("/usr/local/bin/cpufreqctl.auto-cpufreq"):
|
|
|
|
os.remove("/usr/local/bin/cpufreqctl.auto-cpufreq")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def footer(l=79):
|
|
|
|
print("\n" + "-" * l + "\n")
|
|
|
|
|
|
|
|
|
|
|
|
def deploy_complete_msg():
|
2021-12-22 08:28:08 +01:00
|
|
|
print("\n" + "-" * 17 + " auto-cpufreq daemon installed and running " + "-" * 17 + "\n")
|
2021-02-02 21:40:55 +01:00
|
|
|
print("To view live stats, run:\nauto-cpufreq --stats")
|
2021-12-22 08:28:08 +01:00
|
|
|
print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove")
|
2021-01-21 07:55:23 +01:00
|
|
|
footer()
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
def deprecated_log_msg():
|
2021-02-02 22:10:42 +01:00
|
|
|
print("\n" + "-" * 24 + " auto-cpufreq log file renamed " + "-" * 24 + "\n")
|
|
|
|
print("The --log flag has been renamed to --stats\n")
|
2021-02-02 21:40:55 +01:00
|
|
|
print("To view live stats, run:\nauto-cpufreq --stats")
|
|
|
|
footer()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def remove_complete_msg():
|
|
|
|
print("\n" + "-" * 25 + " auto-cpufreq daemon removed " + "-" * 25 + "\n")
|
|
|
|
print("auto-cpufreq successfully removed.")
|
2021-02-02 20:56:56 +01:00
|
|
|
footer()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def deploy_daemon():
|
|
|
|
print("\n" + "-" * 21 + " Deploying auto-cpufreq as a daemon " + "-" * 22 + "\n")
|
|
|
|
|
|
|
|
# deploy cpufreqctl script func call
|
|
|
|
cpufreqctl()
|
|
|
|
|
2021-12-04 18:32:50 +01:00
|
|
|
# turn off bluetooth on boot
|
|
|
|
bluetooth_disable()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
auto_cpufreq_stats_path.touch(exist_ok=True)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
print("\n* Deploy auto-cpufreq install script")
|
2022-11-24 17:44:57 +01:00
|
|
|
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/local/bin/auto-cpufreq-install")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
print("\n* Deploy auto-cpufreq remove script")
|
2022-11-24 17:44:57 +01:00
|
|
|
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-remove.sh", "/usr/local/bin/auto-cpufreq-remove")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-04 10:02:19 +01:00
|
|
|
# output warning if gnome power profile is running
|
2021-12-04 20:56:50 +01:00
|
|
|
gnome_power_detect_install()
|
|
|
|
gnome_power_svc_disable()
|
2021-12-04 10:02:19 +01:00
|
|
|
|
2021-12-11 11:59:41 +01:00
|
|
|
# output warning if TLP service is detected
|
|
|
|
tlp_service_detect()
|
2022-02-19 14:48:17 +01:00
|
|
|
|
2022-11-24 17:44:57 +01:00
|
|
|
call("/usr/local/bin/auto-cpufreq-install", shell=True)
|
2022-02-19 14:48:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def deploy_daemon_performance():
|
2022-02-19 15:21:51 +01:00
|
|
|
print("\n" + "-" * 21 + " Deploying auto-cpufreq as a daemon (performance) " + "-" * 22 + "\n")
|
|
|
|
|
|
|
|
# check that performance is in scaling_available_governors
|
|
|
|
with open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") as available_governors:
|
|
|
|
if "performance" not in available_governors.read():
|
2022-07-31 08:14:27 +02:00
|
|
|
print("\"performance\" governor is unavailable on this system, run:\n"
|
2022-02-19 15:21:51 +01:00
|
|
|
"sudo sudo auto-cpufreq --install\n\n"
|
|
|
|
"to install auto-cpufreq using default \"balanced\" governor.\n")
|
2022-02-19 14:48:17 +01:00
|
|
|
|
|
|
|
# deploy cpufreqctl script func call
|
|
|
|
cpufreqctl()
|
|
|
|
|
|
|
|
# turn off bluetooth on boot
|
|
|
|
bluetooth_disable()
|
|
|
|
|
|
|
|
auto_cpufreq_stats_path.touch(exist_ok=True)
|
|
|
|
|
|
|
|
print("\n* Deploy auto-cpufreq install script")
|
2022-11-24 17:44:57 +01:00
|
|
|
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/local/bin/auto-cpufreq-install")
|
2022-02-19 14:48:17 +01:00
|
|
|
|
|
|
|
print("\n* Deploy auto-cpufreq remove script")
|
2022-11-24 17:44:57 +01:00
|
|
|
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-remove.sh", "/usr/local/bin/auto-cpufreq-remove")
|
2022-02-19 14:48:17 +01:00
|
|
|
|
|
|
|
# output warning if gnome power profile is running
|
|
|
|
gnome_power_detect_install()
|
2023-07-15 21:32:23 +02:00
|
|
|
#"gnome_power_svc_disable_performance" is not defined
|
|
|
|
#gnome_power_svc_disable_performance()
|
2022-02-19 14:48:17 +01:00
|
|
|
|
|
|
|
# output warning if TLP service is detected
|
|
|
|
tlp_service_detect()
|
2021-12-11 11:59:41 +01:00
|
|
|
|
2022-11-24 17:44:57 +01:00
|
|
|
call("/usr/local/bin/auto-cpufreq-install", shell=True)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-22 08:28:08 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# remove auto-cpufreq daemon
|
2023-02-01 16:39:14 +01:00
|
|
|
def remove_daemon():
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# check if auto-cpufreq is installed
|
2022-11-24 17:44:57 +01:00
|
|
|
if not os.path.exists("/usr/local/bin/auto-cpufreq-remove"):
|
2021-01-21 07:55:23 +01:00
|
|
|
print("\nauto-cpufreq daemon is not installed.\n")
|
|
|
|
sys.exit(1)
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
print("\n" + "-" * 21 + " Removing auto-cpufreq daemon " + "-" * 22 + "\n")
|
|
|
|
|
2021-12-04 18:32:50 +01:00
|
|
|
# turn on bluetooth on boot
|
|
|
|
bluetooth_enable()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-04 10:02:19 +01:00
|
|
|
# output warning if gnome power profile is stopped
|
|
|
|
gnome_power_rm_reminder()
|
2021-12-04 20:56:50 +01:00
|
|
|
gnome_power_svc_enable()
|
2021-11-21 09:22:22 +01:00
|
|
|
|
2021-12-04 10:02:19 +01:00
|
|
|
# run auto-cpufreq daemon remove script
|
2022-11-24 17:44:57 +01:00
|
|
|
call("/usr/local/bin/auto-cpufreq-remove", shell=True)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# remove auto-cpufreq-remove
|
2022-11-24 17:44:57 +01:00
|
|
|
os.remove("/usr/local/bin/auto-cpufreq-remove")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2023-02-01 16:39:14 +01:00
|
|
|
# delete override pickle if it exists
|
2023-02-03 17:28:12 +01:00
|
|
|
if os.path.exists(governor_override_state):
|
|
|
|
os.remove(governor_override_state)
|
2023-02-01 16:39:14 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
# delete stats file
|
|
|
|
if auto_cpufreq_stats_path.exists():
|
|
|
|
if auto_cpufreq_stats_file is not None:
|
|
|
|
auto_cpufreq_stats_file.close()
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
auto_cpufreq_stats_path.unlink()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# restore original cpufrectl script
|
|
|
|
cpufreqctl_restore()
|
|
|
|
|
2021-12-22 08:28:08 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def gov_check():
|
|
|
|
for gov in get_avail_gov():
|
|
|
|
if gov not in ALL_GOVERNORS:
|
2021-12-22 08:28:08 +01:00
|
|
|
print("\n" + "-" * 18 + " Checking for necessary scaling governors " + "-" * 19 + "\n")
|
|
|
|
sys.exit("ERROR:\n\nCouldn't find any of the necessary scaling governors.\n")
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# root check func
|
|
|
|
def root_check():
|
|
|
|
if not os.geteuid() == 0:
|
|
|
|
print("\n" + "-" * 33 + " Root check " + "-" * 34 + "\n")
|
2021-11-28 14:06:46 +01:00
|
|
|
print("ERROR:\n\nMust be run root for this functionality to work, i.e: \nsudo " + app_name)
|
2021-01-21 07:55:23 +01:00
|
|
|
footer()
|
|
|
|
exit(1)
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# refresh countdown
|
|
|
|
def countdown(s):
|
2021-02-02 21:40:55 +01:00
|
|
|
# Fix for wrong stats output and "TERM environment variable not set"
|
2021-03-11 18:29:20 +01:00
|
|
|
os.environ["TERM"] = "xterm"
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2022-06-05 17:41:59 +02:00
|
|
|
print("\t\t\"auto-cpufreq\" is about to refresh ", end = "")
|
2024-05-06 13:58:38 +02:00
|
|
|
|
2022-06-05 19:34:14 +02:00
|
|
|
# empty log file if size is larger then 10mb
|
|
|
|
if auto_cpufreq_stats_file is not None:
|
|
|
|
log_size = os.path.getsize(auto_cpufreq_stats_path)
|
|
|
|
if log_size >= 1e+7:
|
|
|
|
auto_cpufreq_stats_file.seek(0)
|
|
|
|
auto_cpufreq_stats_file.truncate(0)
|
|
|
|
|
|
|
|
# auto-refresh counter
|
2022-06-05 17:41:59 +02:00
|
|
|
for remaining in range(s, -1, -1):
|
|
|
|
|
|
|
|
if remaining <= 3 and remaining >= 0:
|
|
|
|
print(".", end="", flush=True)
|
2022-06-05 19:34:14 +02:00
|
|
|
time.sleep(0.75)
|
2021-02-04 20:25:17 +01:00
|
|
|
|
2022-06-05 19:34:14 +02:00
|
|
|
now = datetime.now()
|
|
|
|
current_time = now.strftime("%B %d (%A) - %H:%M:%S")
|
|
|
|
print("\n\t\tExecuted on:", current_time)
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# get cpu usage + system load for (last minute)
|
|
|
|
def display_load():
|
|
|
|
|
|
|
|
# get CPU utilization as a percentage
|
|
|
|
cpuload = psutil.cpu_percent(interval=1)
|
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
|
|
|
print("\nTotal CPU usage:", cpuload, "%")
|
2022-05-23 05:37:49 +02:00
|
|
|
print("Total system load: {:.2f}".format(load1m))
|
|
|
|
print("Average temp. of all cores: {:.2f} °C \n".format(avg_all_core_temp))
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2022-11-12 06:02:26 +01:00
|
|
|
# get system load average 1m, 5m, 15m (equivalent to uptime)
|
|
|
|
def display_system_load_avg():
|
|
|
|
|
|
|
|
load1m, load5m, load15m = os.getloadavg()
|
|
|
|
|
2022-11-12 06:16:38 +01:00
|
|
|
print(f" (load average: {load1m:.2f}, {load5m:.2f}, {load15m:.2f})")
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
# set minimum and maximum CPU frequencies
|
|
|
|
def set_frequencies():
|
2021-12-30 13:29:14 +01:00
|
|
|
"""
|
|
|
|
Sets frequencies:
|
|
|
|
- if option is used in auto-cpufreq.conf: use configured value
|
|
|
|
- if option is disabled/no conf file used: set default frequencies
|
|
|
|
Frequency setting is performed only once on power supply change
|
|
|
|
"""
|
|
|
|
power_supply = "charger" if charging() else "battery"
|
|
|
|
|
|
|
|
# don't do anything if the power supply hasn't changed
|
|
|
|
if (
|
|
|
|
hasattr(set_frequencies, "prev_power_supply")
|
|
|
|
and power_supply == set_frequencies.prev_power_supply
|
|
|
|
):
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
set_frequencies.prev_power_supply = power_supply
|
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
frequency = {
|
|
|
|
"scaling_max_freq": {
|
|
|
|
"cmdargs": "--frequency-max",
|
|
|
|
"minmax": "maximum",
|
|
|
|
},
|
|
|
|
"scaling_min_freq": {
|
|
|
|
"cmdargs": "--frequency-min",
|
|
|
|
"minmax": "minimum",
|
|
|
|
},
|
|
|
|
}
|
2021-12-30 13:29:14 +01:00
|
|
|
if not hasattr(set_frequencies, "max_limit"):
|
|
|
|
set_frequencies.max_limit = int(getoutput(f"cpufreqctl.auto-cpufreq --frequency-max-limit"))
|
|
|
|
if not hasattr(set_frequencies, "min_limit"):
|
|
|
|
set_frequencies.min_limit = int(getoutput(f"cpufreqctl.auto-cpufreq --frequency-min-limit"))
|
2021-12-26 11:01:32 +01:00
|
|
|
|
2024-04-30 08:35:53 +02:00
|
|
|
conf = config.get_config()
|
2021-12-26 11:01:32 +01:00
|
|
|
|
|
|
|
for freq_type in frequency.keys():
|
2021-12-30 13:29:14 +01:00
|
|
|
value = None
|
|
|
|
if not conf.has_option(power_supply, freq_type):
|
|
|
|
# fetch and use default frequencies
|
|
|
|
if freq_type == "scaling_max_freq":
|
|
|
|
curr_freq = int(getoutput(f"cpufreqctl.auto-cpufreq --frequency-max"))
|
|
|
|
value = set_frequencies.max_limit
|
|
|
|
else:
|
|
|
|
curr_freq = int(getoutput(f"cpufreqctl.auto-cpufreq --frequency-min"))
|
|
|
|
value = set_frequencies.min_limit
|
|
|
|
if curr_freq == value:
|
|
|
|
continue
|
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
try:
|
2021-12-30 13:29:14 +01:00
|
|
|
frequency[freq_type]["value"] = (
|
|
|
|
value if value else int(conf[power_supply][freq_type].strip())
|
|
|
|
)
|
2021-12-26 11:01:32 +01:00
|
|
|
except ValueError:
|
|
|
|
print(f"Invalid value for '{freq_type}': {frequency[freq_type]['value']}")
|
|
|
|
exit(1)
|
|
|
|
|
2021-12-30 13:29:14 +01:00
|
|
|
if not (
|
|
|
|
set_frequencies.min_limit <= frequency[freq_type]["value"] <= set_frequencies.max_limit
|
|
|
|
):
|
2021-12-26 11:01:32 +01:00
|
|
|
print(
|
2021-12-30 13:29:14 +01:00
|
|
|
f"Given value for '{freq_type}' is not within the allowed frequencies {set_frequencies.min_limit}-{set_frequencies.max_limit} kHz"
|
2021-12-26 11:01:32 +01:00
|
|
|
)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
args = f"{frequency[freq_type]['cmdargs']} --set={frequency[freq_type]['value']}"
|
|
|
|
message = f'Setting {frequency[freq_type]["minmax"]} CPU frequency to {round(frequency[freq_type]["value"]/1000)} Mhz'
|
|
|
|
|
|
|
|
# set the frequency
|
|
|
|
print(message)
|
|
|
|
run(f"cpufreqctl.auto-cpufreq {args}", shell=True)
|
|
|
|
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# set powersave and enable turbo
|
|
|
|
def set_powersave():
|
2024-04-30 08:35:53 +02:00
|
|
|
conf = config.get_config()
|
2021-12-26 11:01:32 +01:00
|
|
|
if conf.has_option("battery", "governor"):
|
|
|
|
gov = conf["battery"]["governor"]
|
2021-10-10 08:11:45 +02:00
|
|
|
else:
|
|
|
|
gov = get_avail_powersave()
|
|
|
|
print(f'Setting to use: "{gov}" governor')
|
2023-02-01 16:39:14 +01:00
|
|
|
if get_override() != "default":
|
|
|
|
print("Warning: governor overwritten using `--force` flag.")
|
2021-10-10 08:11:45 +02:00
|
|
|
run(f"cpufreqctl.auto-cpufreq --governor --set={gov}", shell=True)
|
2024-01-24 05:33:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() is False:
|
2023-12-29 08:11:27 +01:00
|
|
|
print('Not setting EPP (not supported by system)')
|
2024-01-24 05:33:24 +01:00
|
|
|
else:
|
|
|
|
dynboost_enabled = Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists()
|
|
|
|
|
|
|
|
if dynboost_enabled:
|
|
|
|
dynboost_enabled = bool(int(
|
|
|
|
os.popen("cat /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").read()
|
|
|
|
))
|
|
|
|
|
|
|
|
if dynboost_enabled:
|
|
|
|
print('Not setting EPP (dynamic boosting is enabled)')
|
|
|
|
else:
|
|
|
|
if conf.has_option("battery", "energy_performance_preference"):
|
|
|
|
epp = conf["battery"]["energy_performance_preference"]
|
|
|
|
run(f"cpufreqctl.auto-cpufreq --epp --set={epp}", shell=True)
|
|
|
|
print(f'Setting to use: "{epp}" EPP')
|
|
|
|
else:
|
|
|
|
run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True)
|
|
|
|
print('Setting to use: "balance_power" EPP')
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
# set frequencies
|
|
|
|
set_frequencies()
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# get CPU utilization as a percentage
|
|
|
|
cpuload = psutil.cpu_percent(interval=1)
|
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
|
|
|
print("\nTotal CPU usage:", cpuload, "%")
|
2022-05-23 05:37:49 +02:00
|
|
|
print("Total system load: {:.2f}".format(load1m))
|
|
|
|
print("Average temp. of all cores: {:.2f} °C \n".format(avg_all_core_temp))
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# conditions for setting turbo in powersave
|
2021-12-26 11:01:32 +01:00
|
|
|
if conf.has_option("battery", "turbo"):
|
|
|
|
auto = conf["battery"]["turbo"]
|
2021-01-21 07:55:23 +01:00
|
|
|
else:
|
2021-10-10 08:11:45 +02:00
|
|
|
auto = "auto"
|
|
|
|
|
|
|
|
if auto == "always":
|
|
|
|
print("Configuration file enforces turbo boost")
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
elif auto == "never":
|
|
|
|
print("Configuration file disables turbo boost")
|
|
|
|
print("setting turbo boost: off")
|
2021-10-17 16:29:16 +02:00
|
|
|
turbo(False)
|
2021-10-10 08:11:45 +02:00
|
|
|
else:
|
|
|
|
if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(
|
|
|
|
max(psutil.cpu_percent(percpu=True, interval=0.01)), 100
|
|
|
|
):
|
2022-11-12 06:02:26 +01:00
|
|
|
print("High CPU load", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 70:
|
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
|
|
|
|
elif load1m > powersave_load_threshold:
|
2022-11-13 19:17:35 +01:00
|
|
|
print("High system load", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 65:
|
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
else:
|
2022-11-12 06:02:26 +01:00
|
|
|
print("Load optimal", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 60:
|
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
footer()
|
|
|
|
|
|
|
|
|
|
|
|
# make turbo suggestions in powersave
|
|
|
|
def mon_powersave():
|
|
|
|
|
|
|
|
# get CPU utilization as a percentage
|
|
|
|
cpuload = psutil.cpu_percent(interval=1)
|
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
|
|
|
print("\nTotal CPU usage:", cpuload, "%")
|
2022-05-23 05:37:49 +02:00
|
|
|
print("Total system load: {:.2f}".format(load1m))
|
|
|
|
print("Average temp. of all cores: {:.2f} °C \n".format(avg_all_core_temp))
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(
|
|
|
|
max(psutil.cpu_percent(percpu=True, interval=0.01)), 100
|
|
|
|
):
|
2022-11-12 06:02:26 +01:00
|
|
|
print("High CPU load", end=""), display_system_load_avg()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 70:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
elif load1m > powersave_load_threshold:
|
2022-11-13 19:17:35 +01:00
|
|
|
print("High system load", end=""), display_system_load_avg()
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 65:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
else:
|
2022-11-12 06:02:26 +01:00
|
|
|
print("Load optimal", end=""), display_system_load_avg()
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 20 and avg_all_core_temp >= 60:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
footer()
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# set performance and enable turbo
|
|
|
|
def set_performance():
|
2024-04-30 08:35:53 +02:00
|
|
|
conf = config.get_config()
|
2021-12-26 11:01:32 +01:00
|
|
|
if conf.has_option("charger", "governor"):
|
|
|
|
gov = conf["charger"]["governor"]
|
2021-10-10 08:11:45 +02:00
|
|
|
else:
|
|
|
|
gov = get_avail_performance()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-10-10 08:11:45 +02:00
|
|
|
print(f'Setting to use: "{gov}" governor')
|
2023-02-01 16:39:14 +01:00
|
|
|
if get_override() != "default":
|
|
|
|
print("Warning: governor overwritten using `--force` flag.")
|
2021-03-11 18:29:20 +01:00
|
|
|
run(
|
2021-10-10 08:11:45 +02:00
|
|
|
f"cpufreqctl.auto-cpufreq --governor --set={gov}",
|
2021-03-11 18:29:20 +01:00
|
|
|
shell=True,
|
|
|
|
)
|
2024-01-24 05:33:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() is False:
|
2023-12-29 08:11:27 +01:00
|
|
|
print('Not setting EPP (not supported by system)')
|
2024-01-24 05:33:24 +01:00
|
|
|
else:
|
|
|
|
dynboost_enabled = Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists()
|
|
|
|
|
|
|
|
if dynboost_enabled:
|
|
|
|
dynboost_enabled = bool(int(
|
|
|
|
os.popen("cat /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").read()
|
|
|
|
))
|
|
|
|
|
|
|
|
if dynboost_enabled:
|
|
|
|
print('Not setting EPP (dynamic boosting is enabled)')
|
|
|
|
else:
|
2024-05-06 13:58:38 +02:00
|
|
|
intel_pstate_status_path = "/sys/devices/system/cpu/intel_pstate/status"
|
|
|
|
|
2024-01-24 05:33:24 +01:00
|
|
|
if conf.has_option("charger", "energy_performance_preference"):
|
|
|
|
epp = conf["charger"]["energy_performance_preference"]
|
2024-05-06 13:58:38 +02:00
|
|
|
|
|
|
|
if Path(intel_pstate_status_path).exists() and open(intel_pstate_status_path, 'r').read().strip() == "active" and epp != "performance":
|
|
|
|
print(f'Warning "{epp}" EPP is not allowed in Intel CPU')
|
|
|
|
print('Overriding EPP to "performance"')
|
|
|
|
epp = "performance"
|
|
|
|
|
2024-01-24 05:33:24 +01:00
|
|
|
run(f"cpufreqctl.auto-cpufreq --epp --set={epp}", shell=True)
|
|
|
|
print(f'Setting to use: "{epp}" EPP')
|
|
|
|
else:
|
2024-05-06 13:58:38 +02:00
|
|
|
if Path(intel_pstate_status_path).exists() and open(intel_pstate_status_path, 'r').read().strip() == "active":
|
|
|
|
run("cpufreqctl.auto-cpufreq --epp --set=performance", shell=True)
|
|
|
|
print('Setting to use: "performance" EPP')
|
|
|
|
else:
|
|
|
|
run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True)
|
|
|
|
print('Setting to use: "balance_performance" EPP')
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
# set frequencies
|
|
|
|
set_frequencies()
|
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# get CPU utilization as a percentage
|
|
|
|
cpuload = psutil.cpu_percent(interval=1)
|
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
|
|
|
print("\nTotal CPU usage:", cpuload, "%")
|
2022-05-23 05:37:49 +02:00
|
|
|
print("Total system load: {:.2f}".format(load1m))
|
|
|
|
print("Average temp. of all cores: {:.2f} °C \n".format(avg_all_core_temp))
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-26 11:01:32 +01:00
|
|
|
if conf.has_option("charger", "turbo"):
|
|
|
|
auto = conf["charger"]["turbo"]
|
2021-01-21 07:55:23 +01:00
|
|
|
else:
|
2021-10-10 08:11:45 +02:00
|
|
|
auto = "auto"
|
|
|
|
|
|
|
|
if auto == "always":
|
|
|
|
print("Configuration file enforces turbo boost")
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
elif auto == "never":
|
|
|
|
print("Configuration file disables turbo boost")
|
|
|
|
print("setting turbo boost: off")
|
2022-11-12 06:23:45 +01:00
|
|
|
turbo(False)
|
2021-10-10 08:11:45 +02:00
|
|
|
else:
|
|
|
|
if (
|
|
|
|
psutil.cpu_percent(percpu=False, interval=0.01) >= 20.0
|
|
|
|
or max(psutil.cpu_percent(percpu=True, interval=0.01)) >= 75
|
|
|
|
):
|
2022-11-12 06:02:26 +01:00
|
|
|
print("High CPU load", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
2021-10-17 16:35:55 +02:00
|
|
|
elif avg_all_core_temp >= 70:
|
2021-10-10 08:11:45 +02:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
elif load1m >= performance_load_threshold:
|
2022-11-13 19:17:35 +01:00
|
|
|
print("High system load", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
2021-10-17 16:35:55 +02:00
|
|
|
elif avg_all_core_temp >= 65:
|
2021-10-10 08:11:45 +02:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
else:
|
2022-11-12 06:02:26 +01:00
|
|
|
print("Load optimal", end=""), display_system_load_avg()
|
2021-10-10 08:11:45 +02:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("setting turbo boost: on")
|
|
|
|
turbo(True)
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
2021-10-17 16:35:55 +02:00
|
|
|
elif avg_all_core_temp >= 60:
|
2021-10-10 08:11:45 +02:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
|
|
|
else:
|
|
|
|
print("setting turbo boost: off")
|
|
|
|
turbo(False)
|
2021-01-24 13:14:11 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
footer()
|
|
|
|
|
|
|
|
|
|
|
|
# make turbo suggestions in performance
|
|
|
|
def mon_performance():
|
|
|
|
|
|
|
|
# get CPU utilization as a percentage
|
|
|
|
cpuload = psutil.cpu_percent(interval=1)
|
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
|
|
|
print("\nTotal CPU usage:", cpuload, "%")
|
2022-05-23 05:37:49 +02:00
|
|
|
print("Total system load: {:.2f}".format(load1m))
|
|
|
|
print("Average temp. of all cores: {:.2f} °C \n".format(avg_all_core_temp))
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# get system/CPU load
|
|
|
|
load1m, _, _ = os.getloadavg()
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
if (
|
|
|
|
psutil.cpu_percent(percpu=False, interval=0.01) >= 20.0
|
|
|
|
or max(psutil.cpu_percent(percpu=True, interval=0.01)) >= 75
|
|
|
|
):
|
2022-11-12 06:02:26 +01:00
|
|
|
print("High CPU load", end=""), display_system_load_avg()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 25 and avg_all_core_temp >= 70:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
elif load1m > performance_load_threshold:
|
2022-11-13 19:17:35 +01:00
|
|
|
print("High system load", end=""), display_system_load_avg()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 25 and avg_all_core_temp >= 65:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
else:
|
2022-11-12 06:02:26 +01:00
|
|
|
print("Load optimal", end=""), display_system_load_avg()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
# high cpu usage trigger
|
|
|
|
if cpuload >= 20:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
# set turbo state based on average of all core temperatures
|
|
|
|
elif cpuload <= 25 and avg_all_core_temp >= 60:
|
2021-03-11 18:29:20 +01:00
|
|
|
print(
|
|
|
|
"Optimal total CPU usage:",
|
|
|
|
cpuload,
|
|
|
|
"%, high average core temp:",
|
|
|
|
avg_all_core_temp,
|
|
|
|
"°C",
|
|
|
|
)
|
2021-01-21 07:55:23 +01:00
|
|
|
print("suggesting to set turbo boost: off")
|
|
|
|
get_turbo()
|
|
|
|
else:
|
|
|
|
print("suggesting to set turbo boost: on")
|
|
|
|
get_turbo()
|
|
|
|
|
|
|
|
footer()
|
|
|
|
|
|
|
|
|
|
|
|
def set_autofreq():
|
|
|
|
"""
|
|
|
|
set cpufreq governor based if device is charging
|
|
|
|
"""
|
|
|
|
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
|
|
|
|
|
|
|
|
# determine which governor should be used
|
2023-02-01 16:39:14 +01:00
|
|
|
override = get_override()
|
|
|
|
if override == "powersave":
|
|
|
|
set_powersave()
|
|
|
|
elif override == "performance":
|
|
|
|
set_performance()
|
|
|
|
elif charging():
|
2022-11-17 20:06:34 +01:00
|
|
|
print("Battery is: charging\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
set_performance()
|
|
|
|
else:
|
2022-11-17 20:06:34 +01:00
|
|
|
print("Battery is: discharging\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
set_powersave()
|
|
|
|
|
|
|
|
|
|
|
|
def mon_autofreq():
|
|
|
|
"""
|
|
|
|
make cpufreq suggestions
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
|
|
|
|
|
|
|
|
# determine which governor should be used
|
|
|
|
if charging():
|
2022-11-17 20:06:34 +01:00
|
|
|
print("Battery is: charging\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
get_current_gov()
|
2021-03-11 18:29:20 +01:00
|
|
|
print(f'Suggesting use of "{get_avail_performance()}" governor')
|
2021-01-21 07:55:23 +01:00
|
|
|
mon_performance()
|
|
|
|
else:
|
2022-11-17 20:06:34 +01:00
|
|
|
print("Battery is: discharging\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
get_current_gov()
|
2021-03-11 18:29:20 +01:00
|
|
|
print(f'Suggesting use of "{get_avail_powersave()}" governor')
|
2021-01-21 07:55:23 +01:00
|
|
|
mon_powersave()
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def python_info():
|
|
|
|
print("Python:", pl.python_version())
|
|
|
|
print("psutil package:", psutil.__version__)
|
|
|
|
print("platform package:", pl.__version__)
|
|
|
|
print("click package:", click.__version__)
|
2022-01-08 15:55:56 +01:00
|
|
|
print("distro package:", distro.__version__)
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-02-04 08:06:41 +01:00
|
|
|
def device_info():
|
2021-03-11 18:29:20 +01:00
|
|
|
print("Computer type:", getoutput("dmidecode --string chassis-type"))
|
2021-02-04 08:06:41 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
def distro_info():
|
|
|
|
dist = "UNKNOWN distro"
|
|
|
|
version = "UNKNOWN version"
|
|
|
|
|
|
|
|
# get distro information in snap env.
|
|
|
|
if os.getenv("PKG_MARKER") == "SNAP":
|
|
|
|
try:
|
|
|
|
with open("/var/lib/snapd/hostfs/etc/os-release", "r") as searchfile:
|
|
|
|
for line in searchfile:
|
2021-03-11 18:29:20 +01:00
|
|
|
if line.startswith("NAME="):
|
2021-12-22 08:28:08 +01:00
|
|
|
dist = line[5 : line.find("$")].strip('"')
|
2021-01-21 07:55:23 +01:00
|
|
|
continue
|
2021-03-11 18:29:20 +01:00
|
|
|
elif line.startswith("VERSION="):
|
2021-12-22 08:28:08 +01:00
|
|
|
version = line[8 : line.find("$")].strip('"')
|
2021-01-21 07:55:23 +01:00
|
|
|
continue
|
2021-03-11 18:29:20 +01:00
|
|
|
except PermissionError as e:
|
|
|
|
print(repr(e))
|
2021-01-21 07:55:23 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
dist = f"{dist} {version}"
|
|
|
|
else:
|
|
|
|
# get distro information
|
|
|
|
fdist = distro.linux_distribution()
|
|
|
|
dist = " ".join(x for x in fdist)
|
|
|
|
|
|
|
|
print("Linux distro: " + dist)
|
|
|
|
print("Linux kernel: " + pl.release())
|
|
|
|
|
2021-03-11 18:29:20 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
def sysinfo():
|
|
|
|
"""
|
|
|
|
get system information
|
|
|
|
"""
|
|
|
|
|
|
|
|
# processor_info
|
2022-09-10 08:37:19 +02:00
|
|
|
model_name = getoutput("grep -E 'model name' /proc/cpuinfo -m 1").split(":")[-1]
|
2021-01-21 07:55:23 +01:00
|
|
|
print(f"Processor:{model_name}")
|
|
|
|
|
|
|
|
# get core count
|
2022-08-22 16:42:09 +02:00
|
|
|
total_cpu_count = int(getoutput("nproc"))
|
2021-01-21 07:55:23 +01:00
|
|
|
print("Cores:", total_cpu_count)
|
|
|
|
|
|
|
|
# get architecture
|
|
|
|
cpu_arch = pl.machine()
|
|
|
|
print("Architecture:", cpu_arch)
|
|
|
|
|
|
|
|
# get driver
|
|
|
|
driver = getoutput("cpufreqctl.auto-cpufreq --driver")
|
|
|
|
print("Driver: " + driver)
|
|
|
|
|
|
|
|
# get usage and freq info of cpus
|
|
|
|
usage_per_cpu = psutil.cpu_percent(interval=1, percpu=True)
|
|
|
|
# psutil current freq not used, gives wrong values with offline cpu's
|
|
|
|
minmax_freq_per_cpu = psutil.cpu_freq(percpu=True)
|
|
|
|
|
2022-07-31 08:14:27 +02:00
|
|
|
# max and min freqs, psutil reports wrong max/min freqs with offline cores with percpu=False
|
2021-01-21 07:55:23 +01:00
|
|
|
max_freq = max([freq.max for freq in minmax_freq_per_cpu])
|
|
|
|
min_freq = min([freq.min for freq in minmax_freq_per_cpu])
|
2021-02-02 21:40:55 +01:00
|
|
|
print("\n" + "-" * 30 + " Current CPU stats " + "-" * 30 + "\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
print(f"CPU max frequency: {max_freq:.0f} MHz")
|
|
|
|
print(f"CPU min frequency: {min_freq:.0f} MHz\n")
|
|
|
|
|
|
|
|
# get coreid's and frequencies of online cpus by parsing /proc/cpuinfo
|
2022-09-10 08:37:19 +02:00
|
|
|
coreid_info = getoutput("grep -E 'processor|cpu MHz|core id' /proc/cpuinfo").split("\n")
|
2021-01-21 07:55:23 +01:00
|
|
|
cpu_core = dict()
|
|
|
|
freq_per_cpu = []
|
|
|
|
for i in range(0, len(coreid_info), 3):
|
2023-05-21 14:03:29 +02:00
|
|
|
# ensure that indices are within the valid range, before accessing the corresponding elements
|
|
|
|
if i + 1 < len(coreid_info):
|
|
|
|
freq_per_cpu.append(float(coreid_info[i + 1].split(":")[-1]))
|
|
|
|
else:
|
|
|
|
# handle the case where the index is out of range
|
|
|
|
continue
|
|
|
|
# ensure that indices are within the valid range, before accessing the corresponding elements
|
2021-03-11 18:29:20 +01:00
|
|
|
cpu = int(coreid_info[i].split(":")[-1])
|
2023-05-21 14:03:29 +02:00
|
|
|
if i + 2 < len(coreid_info):
|
|
|
|
core = int(coreid_info[i + 2].split(":")[-1])
|
|
|
|
cpu_core[cpu] = core
|
|
|
|
else:
|
|
|
|
# handle the case where the index is out of range
|
|
|
|
continue
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
online_cpu_count = len(cpu_core)
|
|
|
|
offline_cpus = [str(cpu) for cpu in range(total_cpu_count) if cpu not in cpu_core]
|
|
|
|
|
|
|
|
# temperatures
|
2023-09-07 18:24:49 +02:00
|
|
|
temp_sensors = psutil.sensors_temperatures()
|
2021-01-21 07:55:23 +01:00
|
|
|
temp_per_cpu = [float("nan")] * online_cpu_count
|
|
|
|
try:
|
2023-09-07 18:24:49 +02:00
|
|
|
# the priority for CPU temp is as follows: coretemp sensor -> sensor with CPU in the label -> acpi -> k10temp
|
|
|
|
if "coretemp" in temp_sensors:
|
2021-01-21 07:55:23 +01:00
|
|
|
# list labels in 'coretemp'
|
2023-09-07 18:24:49 +02:00
|
|
|
core_temp_labels = [temp.label for temp in temp_sensors["coretemp"]]
|
2021-01-21 07:55:23 +01:00
|
|
|
for i, cpu in enumerate(cpu_core):
|
2023-09-07 18:24:49 +02:00
|
|
|
# get correct index in temp_sensors
|
2021-01-21 07:55:23 +01:00
|
|
|
core = cpu_core[cpu]
|
|
|
|
cpu_temp_index = core_temp_labels.index(f"Core {core}")
|
2023-09-07 18:24:49 +02:00
|
|
|
temp_per_cpu[i] = temp_sensors["coretemp"][cpu_temp_index].current
|
2022-09-10 14:02:17 +02:00
|
|
|
else:
|
2023-05-21 12:31:39 +02:00
|
|
|
# iterate over all sensors
|
2023-09-07 18:24:49 +02:00
|
|
|
for sensor in temp_sensors:
|
2023-05-21 12:31:39 +02:00
|
|
|
# iterate over all temperatures in the current sensor
|
2023-09-07 18:24:49 +02:00
|
|
|
for temp in temp_sensors[sensor]:
|
|
|
|
if 'CPU' in temp.label:
|
2023-10-24 04:19:45 +02:00
|
|
|
if temp.current != 0:
|
|
|
|
temp_per_cpu = [temp.current] * online_cpu_count
|
|
|
|
break
|
2023-05-21 12:31:39 +02:00
|
|
|
else:
|
|
|
|
continue
|
|
|
|
break
|
2023-09-07 18:24:49 +02:00
|
|
|
else:
|
2023-11-03 07:40:37 +01:00
|
|
|
for sensor in ["acpitz", "k10temp", "zenpower"]:
|
2023-10-24 04:19:45 +02:00
|
|
|
if sensor in temp_sensors:
|
|
|
|
if temp_sensors[sensor][0].current != 0:
|
|
|
|
temp_per_cpu = [temp_sensors[sensor][0].current] * online_cpu_count
|
|
|
|
break;
|
2021-03-11 18:29:20 +01:00
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
2021-01-21 07:55:23 +01:00
|
|
|
pass
|
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
print("Core\tUsage\tTemperature\tFrequency")
|
2021-12-22 08:28:08 +01:00
|
|
|
for (cpu, usage, freq, temp) in zip(cpu_core, usage_per_cpu, freq_per_cpu, temp_per_cpu):
|
2023-05-21 13:10:44 +02:00
|
|
|
print(f"CPU{cpu} {usage:>5.1f}% {temp:>3.0f} °C {freq:>5.0f} MHz")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
if offline_cpus:
|
|
|
|
print(f"\nDisabled CPUs: {','.join(offline_cpus)}")
|
|
|
|
|
|
|
|
# get average temperature of all cores
|
|
|
|
avg_cores_temp = sum(temp_per_cpu)
|
|
|
|
global avg_all_core_temp
|
2021-03-11 18:29:20 +01:00
|
|
|
avg_all_core_temp = float(avg_cores_temp / online_cpu_count)
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2022-09-08 07:46:34 +02:00
|
|
|
# print current fan speed
|
|
|
|
current_fans = list(psutil.sensors_fans())
|
|
|
|
for current_fan in current_fans:
|
|
|
|
print("\nCPU fan speed:", psutil.sensors_fans()[current_fan][0].current, "RPM")
|
2021-01-21 07:55:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-02 21:40:55 +01:00
|
|
|
# read stats func
|
|
|
|
def read_stats():
|
|
|
|
# read stats
|
|
|
|
if os.path.isfile(auto_cpufreq_stats_path):
|
|
|
|
call(["tail", "-n 50", "-f", str(auto_cpufreq_stats_path)], stderr=DEVNULL)
|
2021-01-21 07:55:23 +01:00
|
|
|
footer()
|
|
|
|
|
|
|
|
|
|
|
|
# check if program (argument) is running
|
|
|
|
def is_running(program, argument):
|
2021-12-21 20:14:02 +01:00
|
|
|
# iterate over all processes found by psutil
|
|
|
|
# and find the one with name and args passed to the function
|
|
|
|
for p in psutil.process_iter():
|
2022-08-10 14:23:58 +02:00
|
|
|
try:
|
|
|
|
cmd = p.cmdline();
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
for s in filter(lambda x: program in x, cmd):
|
|
|
|
if argument in cmd:
|
2021-12-21 20:14:02 +01:00
|
|
|
return True
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2021-12-22 08:28:08 +01:00
|
|
|
|
2021-10-17 17:52:15 +02:00
|
|
|
def daemon_running_msg():
|
|
|
|
print("\n" + "-" * 24 + " auto-cpufreq running " + "-" * 30 + "\n")
|
|
|
|
print(
|
2022-07-28 09:35:52 +02:00
|
|
|
"ERROR: auto-cpufreq is running in daemon mode.\n\nMake sure to stop the daemon before running with --live or --monitor mode"
|
2021-10-17 17:52:15 +02:00
|
|
|
)
|
2021-12-04 18:32:50 +01:00
|
|
|
footer()
|
2021-01-21 07:55:23 +01:00
|
|
|
|
2023-02-01 16:39:14 +01:00
|
|
|
def daemon_not_running_msg():
|
|
|
|
print("\n" + "-" * 24 + " auto-cpufreq not running " + "-" * 30 + "\n")
|
|
|
|
print(
|
|
|
|
"ERROR: auto-cpufreq is not running in daemon mode.\n\nMake sure to run \"sudo auto-cpufreq --install\" first"
|
|
|
|
)
|
|
|
|
footer()
|
2021-12-22 08:28:08 +01:00
|
|
|
|
2021-01-21 07:55:23 +01:00
|
|
|
# check if auto-cpufreq --daemon is running
|
2023-02-01 16:39:14 +01:00
|
|
|
def running_daemon_check():
|
2021-03-11 18:29:20 +01:00
|
|
|
if is_running("auto-cpufreq", "--daemon"):
|
2021-10-17 17:52:15 +02:00
|
|
|
daemon_running_msg()
|
2021-01-21 07:55:23 +01:00
|
|
|
exit(1)
|
|
|
|
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
|
2021-10-17 17:52:15 +02:00
|
|
|
daemon_running_msg()
|
2021-12-19 09:20:09 +01:00
|
|
|
exit(1)
|
2023-02-01 16:39:14 +01:00
|
|
|
|
|
|
|
# check if auto-cpufreq --daemon is not running
|
|
|
|
def not_running_daemon_check():
|
|
|
|
if not is_running("auto-cpufreq", "--daemon"):
|
|
|
|
daemon_not_running_msg()
|
|
|
|
exit(1)
|
|
|
|
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled":
|
|
|
|
daemon_not_running_msg()
|
2023-05-21 12:31:39 +02:00
|
|
|
exit(1)
|