mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-25 22:55:04 +02:00
refactoring (addedd display_load + get_turbo func)
This commit is contained in:
parent
d3a767626a
commit
878733a20f
@ -101,6 +101,8 @@ def main(monitor, live, daemon, install, log, debug):
|
|||||||
python_info()
|
python_info()
|
||||||
print("")
|
print("")
|
||||||
sysinfo()
|
sysinfo()
|
||||||
|
display_load()
|
||||||
|
get_turbo()
|
||||||
footer()
|
footer()
|
||||||
elif install:
|
elif install:
|
||||||
if os.getenv('PKG_MARKER') == "SNAP":
|
if os.getenv('PKG_MARKER') == "SNAP":
|
||||||
|
@ -30,10 +30,17 @@ SCRIPTS_DIR = Path("/usr/local/share/auto-cpufreq/scripts/")
|
|||||||
ALL_GOVERNORS = ("performance", "ondemand", "conservative", "schedutil", "userspace", "powersave")
|
ALL_GOVERNORS = ("performance", "ondemand", "conservative", "schedutil", "userspace", "powersave")
|
||||||
CPUS = os.cpu_count()
|
CPUS = os.cpu_count()
|
||||||
|
|
||||||
|
# get system/CPU load
|
||||||
|
load1m, _, _ = os.getloadavg()
|
||||||
|
|
||||||
|
# get CPU utilization as a percentage
|
||||||
|
cpuload = psutil.cpu_percent(interval=1)
|
||||||
|
|
||||||
# ToDo: read version from snap/snapcraft.yaml and write to $SNAP/version for use with snap installs
|
# ToDo: read version from snap/snapcraft.yaml and write to $SNAP/version for use with snap installs
|
||||||
def app_version():
|
def app_version():
|
||||||
print("Build git commit:", check_output(["git", "describe", "--always"]).strip().decode())
|
print("Build git commit:", check_output(["git", "describe", "--always"]).strip().decode())
|
||||||
|
|
||||||
|
# set/change state of turbo
|
||||||
def turbo(value: bool = None):
|
def turbo(value: bool = None):
|
||||||
"""
|
"""
|
||||||
Get and set turbo mode
|
Get and set turbo mode
|
||||||
@ -67,6 +74,14 @@ def turbo(value: bool = None):
|
|||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
# display current state of turbo
|
||||||
|
def get_turbo():
|
||||||
|
|
||||||
|
if turbo():
|
||||||
|
print("Currently turbo boost is: on")
|
||||||
|
else:
|
||||||
|
print("Currently turbo boost is: off")
|
||||||
|
|
||||||
def charging():
|
def charging():
|
||||||
"""
|
"""
|
||||||
get charge state: is battery charging or discharging
|
get charge state: is battery charging or discharging
|
||||||
@ -252,6 +267,10 @@ def countdown(s):
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
# get cpu usage + system load for (last minute)
|
||||||
|
def display_load():
|
||||||
|
print("\nTotal CPU usage:", cpuload, "%")
|
||||||
|
print("Total system load:", load1m, "\n")
|
||||||
|
|
||||||
# set powersave and enable turbo
|
# set powersave and enable turbo
|
||||||
def set_powersave():
|
def set_powersave():
|
||||||
@ -261,13 +280,8 @@ def set_powersave():
|
|||||||
run("cpufreqctl --epp --set=balance_power", shell=True)
|
run("cpufreqctl --epp --set=balance_power", shell=True)
|
||||||
print("Setting to use: \"balance_power\" EPP")
|
print("Setting to use: \"balance_power\" EPP")
|
||||||
|
|
||||||
# get system/CPU load
|
# cpu usage/system load
|
||||||
load1m, _, _ = os.getloadavg()
|
display_load()
|
||||||
# get CPU utilization as a percentage
|
|
||||||
cpuload = psutil.cpu_percent(interval=1)
|
|
||||||
|
|
||||||
print("\nTotal CPU usage:", cpuload, "%")
|
|
||||||
print("Total system load:", load1m, "\n")
|
|
||||||
|
|
||||||
# conditions for setting turbo in powersave
|
# conditions for setting turbo in powersave
|
||||||
if load1m > (15*CPUS)/100:
|
if load1m > (15*CPUS)/100:
|
||||||
@ -285,34 +299,21 @@ def set_powersave():
|
|||||||
|
|
||||||
# make turbo suggestions in powersave
|
# make turbo suggestions in powersave
|
||||||
def mon_powersave():
|
def mon_powersave():
|
||||||
# get system/CPU load
|
|
||||||
load1m, _, _ = os.getloadavg()
|
|
||||||
# get CPU utilization as a percentage
|
|
||||||
cpuload = psutil.cpu_percent(interval=1)
|
|
||||||
|
|
||||||
print("\nTotal CPU usage:", cpuload, "%")
|
# cpu usage/system load
|
||||||
print("Total system load:", load1m, "\n")
|
display_load()
|
||||||
|
|
||||||
if load1m > (15*CPUS)/100:
|
if load1m > (15*CPUS)/100:
|
||||||
print("High load, suggesting to set turbo boost: on")
|
print("High load, suggesting to set turbo boost: on")
|
||||||
if turbo():
|
get_turbo()
|
||||||
print("Currently turbo boost is: on")
|
|
||||||
else:
|
|
||||||
print("Currently turbo boost is: off")
|
|
||||||
footer()
|
footer()
|
||||||
elif psutil.cpu_percent(percpu=False, interval=0.01) >= 25.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100):
|
elif psutil.cpu_percent(percpu=False, interval=0.01) >= 25.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100):
|
||||||
print("High CPU load, suggesting to set turbo boost: on")
|
print("High CPU load, suggesting to set turbo boost: on")
|
||||||
if turbo():
|
get_turbo()
|
||||||
print("Currently turbo boost is: on")
|
|
||||||
else:
|
|
||||||
print("Currently turbo boost is: off")
|
|
||||||
footer()
|
footer()
|
||||||
else:
|
else:
|
||||||
print("Load optimal, suggesting to set turbo boost: off")
|
print("Load optimal, suggesting to set turbo boost: off")
|
||||||
if turbo():
|
get_turbo()
|
||||||
print("Currently turbo boost is: on")
|
|
||||||
else:
|
|
||||||
print("Currently turbo boost is: off")
|
|
||||||
footer()
|
footer()
|
||||||
|
|
||||||
|
|
||||||
@ -324,11 +325,8 @@ def set_performance():
|
|||||||
run("cpufreqctl --epp --set=balance_performance", shell=True)
|
run("cpufreqctl --epp --set=balance_performance", shell=True)
|
||||||
print("Setting to use: \"balance_performance\" EPP")
|
print("Setting to use: \"balance_performance\" EPP")
|
||||||
|
|
||||||
load1m, _, _ = os.getloadavg()
|
# cpu usage/system load
|
||||||
cpuload = psutil.cpu_percent(interval=1)
|
display_load()
|
||||||
|
|
||||||
print("\nTotal CPU usage:", cpuload, "%")
|
|
||||||
print("Total system load:", load1m, "\n")
|
|
||||||
|
|
||||||
if load1m >= (10*CPUS)/100:
|
if load1m >= (10*CPUS)/100:
|
||||||
print("High load, setting turbo boost: on")
|
print("High load, setting turbo boost: on")
|
||||||
@ -345,13 +343,9 @@ def set_performance():
|
|||||||
|
|
||||||
# make turbo suggestions in performance
|
# make turbo suggestions in performance
|
||||||
def mon_performance():
|
def mon_performance():
|
||||||
# get system/CPU load
|
|
||||||
load1m, _, _ = os.getloadavg()
|
|
||||||
# get CPU utilization as a percentage
|
|
||||||
cpuload = psutil.cpu_percent(interval=1)
|
|
||||||
|
|
||||||
print("\nTotal CPU usage:", cpuload, "%")
|
# cpu usage/system load
|
||||||
print("Total system load:", load1m, "\n")
|
display_load()
|
||||||
|
|
||||||
if turbo():
|
if turbo():
|
||||||
print("Currently turbo boost is: on")
|
print("Currently turbo boost is: on")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user