mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-03 03:44:33 +02:00
aligned all text to 80 char + disabled cpu temp sensor
This commit is contained in:
parent
852c2f7171
commit
2a9ecdc2d2
@ -20,18 +20,22 @@ import click
|
|||||||
# - 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
|
||||||
# - copy cpufreqctl script if it doesn't exist
|
# - copy cpufreqctl script if it doesn't exist
|
||||||
|
# - write whole output to log, read live data from log
|
||||||
|
|
||||||
# global var
|
# global var
|
||||||
p = psutil
|
p = psutil
|
||||||
s = subprocess
|
s = subprocess
|
||||||
tool_run = "python3 auto-cpufreq.py"
|
tool_run = "python3 auto-cpufreq.py"
|
||||||
|
|
||||||
|
def footer(l):
|
||||||
|
print("\n" + "-" * l + "\n")
|
||||||
|
|
||||||
# check for necessary driver
|
# check for necessary driver
|
||||||
def driver_check():
|
def driver_check():
|
||||||
driver = s.getoutput("cpufreqctl --driver")
|
driver = s.getoutput("cpufreqctl --driver")
|
||||||
if driver != "intel_pstate":
|
if driver != "intel_pstate":
|
||||||
print("\n" + "-" * 23 + " Driver check " + "-" * 23 + "\n")
|
print("\n" + "-" * 32 + " Driver check " + "-" * 33 + "\n")
|
||||||
sys.exit("ERROR:\n\n\"intel_pstate\" CPU Performance Scaling Driver is not enabled.\n")
|
sys.exit("ERROR:\n\n\"intel_pstate\" CPU Performance Scaling Driver is not enabled.\n")
|
||||||
|
|
||||||
# check for necessary scaling governors
|
# check for necessary scaling governors
|
||||||
def gov_check():
|
def gov_check():
|
||||||
@ -44,13 +48,13 @@ def gov_check():
|
|||||||
if keyword in line:
|
if keyword in line:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print("\n" + "-" * 9 + " Checking for necessary scaling governors " + "-" * 9 + "\n")
|
print("\n" + "-" * 18 + " Checking for necessary scaling governors " + "-" * 19 + "\n")
|
||||||
sys.exit("ERROR:\n\nCouldn't find any of the necessary scaling governors.\n")
|
sys.exit("ERROR:\n\nCouldn't find any of the necessary scaling governors.\n")
|
||||||
|
|
||||||
# root check func
|
# root check func
|
||||||
def root_check():
|
def root_check():
|
||||||
if not os.geteuid() == 0:
|
if not os.geteuid() == 0:
|
||||||
print("\n" + "-" * 23 + " Root check " + "-" * 24 + "\n")
|
print("\n" + "-" * 33 + " Root check " + "-" * 34 + "\n")
|
||||||
sys.exit(f"Must be run as root, i.e: \"sudo {tool_run}\"\n")
|
sys.exit(f"Must be run as root, i.e: \"sudo {tool_run}\"\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@ -58,7 +62,7 @@ def root_check():
|
|||||||
def countdown(s):
|
def countdown(s):
|
||||||
for remaining in range(s, 0, -1):
|
for remaining in range(s, 0, -1):
|
||||||
sys.stdout.write("\r")
|
sys.stdout.write("\r")
|
||||||
sys.stdout.write("\"auto-cpufreq\" refresh in:{:2d}".format(remaining))
|
sys.stdout.write("\t\t\t\"auto-cpufreq\" refresh in:{:2d}".format(remaining))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
@ -92,22 +96,25 @@ def set_turbo():
|
|||||||
if load1m > 2:
|
if load1m > 2:
|
||||||
print("High load, turbo bost: on")
|
print("High load, turbo bost: 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")
|
||||||
|
footer(79)
|
||||||
|
|
||||||
# print("High load:", load1m)
|
# print("High load:", load1m)
|
||||||
# print("CPU load:", cpuload, "%")
|
# print("CPU load:", cpuload, "%")
|
||||||
elif cpuload > 25:
|
elif cpuload > 25:
|
||||||
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")
|
||||||
|
footer(79)
|
||||||
else:
|
else:
|
||||||
print("Load optimal, turbo boost: off")
|
print("Load optimal, turbo boost: off")
|
||||||
s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
|
||||||
print("\n" + "-" * 60 + "\n")
|
#print("\n" + "-" * 60 + "\n")
|
||||||
|
footer(79)
|
||||||
|
|
||||||
def autofreq():
|
def autofreq():
|
||||||
|
|
||||||
print("\n" + "-" * 18 + " CPU frequency scaling " + "-" * 19 + "\n")
|
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
|
||||||
|
|
||||||
# ToDo: make a function and more generic (move to psutil)
|
# ToDo: make a function and more generic (move to psutil)
|
||||||
# check battery status
|
# check battery status
|
||||||
@ -126,7 +133,7 @@ def autofreq():
|
|||||||
|
|
||||||
def sysinfo():
|
def sysinfo():
|
||||||
|
|
||||||
print("\n" + "-" * 20 + " System information " + "-" * 20 + "\n")
|
print("\n" + "-" * 29 + " System information " + "-" * 30 + "\n")
|
||||||
core_usage = p.cpu_freq(percpu=True)
|
core_usage = p.cpu_freq(percpu=True)
|
||||||
cpu_brand = cpuinfo.get_cpu_info()['brand']
|
cpu_brand = cpuinfo.get_cpu_info()['brand']
|
||||||
cpu_arch = cpuinfo.get_cpu_info()['arch']
|
cpu_arch = cpuinfo.get_cpu_info()['arch']
|
||||||
@ -141,7 +148,7 @@ def sysinfo():
|
|||||||
print("Processor:", cpu_brand)
|
print("Processor:", cpu_brand)
|
||||||
print("Cores:", cpu_count)
|
print("Cores:", cpu_count)
|
||||||
|
|
||||||
print("\n" + "-" * 20 + " Current CPU state " + "-" * 21 + "\n")
|
print("\n" + "-" * 30 + " Current CPU state " + "-" * 30 + "\n")
|
||||||
print("CPU frequency for each core:\n")
|
print("CPU frequency for each core:\n")
|
||||||
core_num = 0
|
core_num = 0
|
||||||
while core_num < cpu_count:
|
while core_num < cpu_count:
|
||||||
@ -149,9 +156,8 @@ def sysinfo():
|
|||||||
core_num += 1
|
core_num += 1
|
||||||
|
|
||||||
# ToDo: make more generic and not only for thinkpad
|
# ToDo: make more generic and not only for thinkpad
|
||||||
#print(psutil.sensors_fans())
|
#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")
|
|
||||||
|
|
||||||
# ToDo: add CPU temperature for each core
|
# ToDo: add CPU temperature for each core
|
||||||
# issue: https://github.com/giampaolo/psutil/issues/1650
|
# issue: https://github.com/giampaolo/psutil/issues/1650
|
||||||
|
Loading…
x
Reference in New Issue
Block a user