mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-27 07:34:25 +02:00
got rid of cpuinfo + distro libraries (drastic speed improvements)
This commit is contained in:
parent
2932c28f44
commit
c31aeaebfe
@ -15,11 +15,13 @@ import click
|
|||||||
# ToDo:
|
# ToDo:
|
||||||
# - check if debian based + first time setup (install necessary packages)
|
# - check if debian based + first time setup (install necessary packages)
|
||||||
# - add option to run as daemon on boot (systemd)
|
# - add option to run as daemon on boot (systemd)
|
||||||
|
# - in case of daemon deploy check if it's already running/daemon script exists
|
||||||
|
# - add option to disable bluetooth (only in daemon mode)
|
||||||
# - add revert/uninstall options for ^
|
# - add revert/uninstall options for ^
|
||||||
# - sort out imports
|
# - sort out imports
|
||||||
# - add option to enable turbo in powersave
|
# - add option to enable turbo in powersave
|
||||||
# - go thru all other ToDo's
|
# - go thru all other ToDo's
|
||||||
# - in case of daemon deploy check if it's already running/daemon script exists
|
# - make shortcut for platform
|
||||||
|
|
||||||
# global var
|
# global var
|
||||||
p = psutil
|
p = psutil
|
||||||
@ -36,8 +38,7 @@ gov_state = get_cur_gov.split()[0]
|
|||||||
# get battery state
|
# get battery state
|
||||||
bat_state = p.sensors_battery().power_plugged
|
bat_state = p.sensors_battery().power_plugged
|
||||||
|
|
||||||
# ToDo: duplicate + replace with psutil.getloadavg()? (available in 5.6.2)
|
# get CPU utilization as a percentage
|
||||||
load1m, _, _ = os.getloadavg()
|
|
||||||
cpuload = p.cpu_percent(interval=1)
|
cpuload = p.cpu_percent(interval=1)
|
||||||
|
|
||||||
def cpufreqctl_deploy():
|
def cpufreqctl_deploy():
|
||||||
@ -107,7 +108,7 @@ def set_powersave():
|
|||||||
|
|
||||||
# set performance
|
# set performance
|
||||||
def set_performance():
|
def set_performance():
|
||||||
print("Using \"performance\" governor\n")
|
print("Using \"performance\" governor")
|
||||||
s.run("cpufreqctl --governor --set=performance", shell=True)
|
s.run("cpufreqctl --governor --set=performance", shell=True)
|
||||||
|
|
||||||
# enable turbo boost
|
# enable turbo boost
|
||||||
@ -116,15 +117,20 @@ def set_performance():
|
|||||||
# set turbo
|
# set turbo
|
||||||
def set_turbo():
|
def set_turbo():
|
||||||
|
|
||||||
|
print("\n" + "-" * 5 + "\n")
|
||||||
|
|
||||||
|
# ToDo: duplicate + replace with psutil.getloadavg()? (available in 5.6.2)
|
||||||
|
load1m, _, _ = os.getloadavg()
|
||||||
|
|
||||||
print("Total CPU usage:", cpuload, "%")
|
print("Total CPU usage:", cpuload, "%")
|
||||||
print("Total system load:", load1m, "\n")
|
print("Total system load:", load1m, "\n")
|
||||||
|
|
||||||
if load1m > 2:
|
if load1m > 1:
|
||||||
print("High load, turbo boost: on")
|
print("High load, turbo boost: on")
|
||||||
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
||||||
footer(79)
|
footer(79)
|
||||||
|
|
||||||
elif cpuload > 25:
|
elif cpuload > 20:
|
||||||
print("High CPU load, turbo boost: on")
|
print("High CPU load, turbo boost: on")
|
||||||
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
||||||
#print("\n" + "-" * 60 + "\n")
|
#print("\n" + "-" * 60 + "\n")
|
||||||
@ -140,6 +146,9 @@ def mon_turbo():
|
|||||||
|
|
||||||
print("\n" + "-" * 5 + "\n")
|
print("\n" + "-" * 5 + "\n")
|
||||||
|
|
||||||
|
# ToDo: duplicate + replace with psutil.getloadavg()? (available in 5.6.2)
|
||||||
|
load1m, _, _ = os.getloadavg()
|
||||||
|
|
||||||
print("Total CPU usage:", cpuload, "%")
|
print("Total CPU usage:", cpuload, "%")
|
||||||
print("Total system load:", load1m, "\n")
|
print("Total system load:", load1m, "\n")
|
||||||
|
|
||||||
@ -203,18 +212,29 @@ def sysinfo():
|
|||||||
print("\n" + "-" * 29 + " System information " + "-" * 30 + "\n")
|
print("\n" + "-" * 29 + " System information " + "-" * 30 + "\n")
|
||||||
|
|
||||||
# get info about linux distro
|
# get info about linux distro
|
||||||
fdist = distro.linux_distribution()
|
# ToDo: use or get rid of
|
||||||
|
#fdist = distro.linux_distribution()
|
||||||
|
fdist = platform.linux_distribution()
|
||||||
dist = " ".join(x for x in fdist)
|
dist = " ".join(x for x in fdist)
|
||||||
print("Linux distro: " + dist)
|
print("Linux distro: " + dist)
|
||||||
print("Linux kernel: " + platform.release())
|
print("Linux kernel: " + platform.release())
|
||||||
|
|
||||||
# get cpu info brand/architecture/cores count
|
# get cpu architecture
|
||||||
cpu_brand = cpuinfo.get_cpu_info()['brand']
|
cpu_arch = platform.processor()
|
||||||
cpu_arch = cpuinfo.get_cpu_info()['arch']
|
|
||||||
cpu_count = cpuinfo.get_cpu_info()['count']
|
# get number of cores/logical CPU's
|
||||||
|
cpu_count = p.cpu_count()
|
||||||
|
|
||||||
print("Architecture:", cpu_arch)
|
print("Architecture:", cpu_arch)
|
||||||
print("Processor:", cpu_brand)
|
|
||||||
|
# get processor
|
||||||
|
with open("/proc/cpuinfo", "r") as f:
|
||||||
|
line = f.readline()
|
||||||
|
while line:
|
||||||
|
if "model name" in line:
|
||||||
|
print("Processor:" + line.split(':')[1].rstrip())
|
||||||
|
break
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
# print cpu max frequency
|
# print cpu max frequency
|
||||||
max_cpu_freq = p.cpu_freq().max
|
max_cpu_freq = p.cpu_freq().max
|
||||||
@ -223,7 +243,6 @@ def sysinfo():
|
|||||||
|
|
||||||
print("\n" + "-" * 30 + " Current CPU state " + "-" * 30 + "\n")
|
print("\n" + "-" * 30 + " Current CPU state " + "-" * 30 + "\n")
|
||||||
|
|
||||||
|
|
||||||
# get current cpu frequency per core
|
# get current cpu frequency per core
|
||||||
core_usage = p.cpu_freq(percpu=True)
|
core_usage = p.cpu_freq(percpu=True)
|
||||||
|
|
||||||
@ -251,6 +270,16 @@ def sysinfo():
|
|||||||
current_fans = p.sensors_fans()['thinkpad'][0].current
|
current_fans = p.sensors_fans()['thinkpad'][0].current
|
||||||
print("\nCPU fan speed:", current_fans, "RPM")
|
print("\nCPU fan speed:", current_fans, "RPM")
|
||||||
|
|
||||||
|
def get_processor_info():
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
return platform.processor()
|
||||||
|
elif platform.system() == "Darwin":
|
||||||
|
return subprocess.check_output(['/usr/sbin/sysctl', "-n", "machdep.cpu.brand_string"]).strip()
|
||||||
|
elif platform.system() == "Linux":
|
||||||
|
command = "cat /proc/cpuinfo"
|
||||||
|
return subprocess.check_output(command, shell=True).strip()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
# cli
|
# cli
|
||||||
@click.command()
|
@click.command()
|
||||||
@ -279,18 +308,20 @@ def cli(monitor, live, daemon):
|
|||||||
mon_autofreq()
|
mon_autofreq()
|
||||||
mon_turbo()
|
mon_turbo()
|
||||||
#autofreq()
|
#autofreq()
|
||||||
countdown(15)
|
countdown(10)
|
||||||
#time.sleep(1)
|
#time.sleep(1)
|
||||||
subprocess.call("clear")
|
subprocess.call("clear")
|
||||||
elif live:
|
elif live:
|
||||||
while True:
|
while True:
|
||||||
root_check()
|
root_check()
|
||||||
|
get_processor_info()
|
||||||
driver_check()
|
driver_check()
|
||||||
gov_check()
|
gov_check()
|
||||||
cpufreqctl_deploy()
|
cpufreqctl_deploy()
|
||||||
sysinfo()
|
sysinfo()
|
||||||
set_autofreq()
|
set_autofreq()
|
||||||
countdown(15)
|
#set_turbo()
|
||||||
|
countdown(10)
|
||||||
#time.sleep(1)
|
#time.sleep(1)
|
||||||
subprocess.call("clear")
|
subprocess.call("clear")
|
||||||
elif daemon:
|
elif daemon:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user