forked from NG-SD-Plugins/PowerTools
Improve logging and docs
This commit is contained in:
parent
1459479342
commit
2cbf3ec2c6
2 changed files with 31 additions and 16 deletions
|
@ -14,6 +14,7 @@ You will need that installed for this plugin to work.
|
||||||
- Set some GPU power parameters (fastPPT & slowPPT)
|
- Set some GPU power parameters (fastPPT & slowPPT)
|
||||||
- Set the fan RPM (unsupported on SteamOS beta)
|
- Set the fan RPM (unsupported on SteamOS beta)
|
||||||
- Display supplementary battery info
|
- Display supplementary battery info
|
||||||
|
- Keep settings between restarts (stored in `~/.config/powertools.json`)
|
||||||
|
|
||||||
## Cool, but that's too much work
|
## Cool, but that's too much work
|
||||||
|
|
||||||
|
|
46
main.py
46
main.py
|
@ -4,9 +4,9 @@ import json
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
VERSION = "0.5.0"
|
VERSION = "0.5.0"
|
||||||
SETTINGS_LOCATION = "/home/deck/.config/powertools.json"
|
SETTINGS_LOCATION = "~/.config/powertools.json"
|
||||||
LOG_LOCATION = "/home/deck/.powertools.log"
|
LOG_LOCATION = "/tmp/powertools.log"
|
||||||
FANTASTIC_INSTALL_DIR = "/home/deck/homebrew/plugins/Fantastic"
|
FANTASTIC_INSTALL_DIR = "~/homebrew/plugins/Fantastic"
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ logging.basicConfig(
|
||||||
force = True)
|
force = True)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.INFO)
|
||||||
logging.info(f"PowerTools v{VERSION}")
|
logging.info(f"PowerTools v{VERSION} https://github.com/NGnius/PowerTools")
|
||||||
|
startup_time = time.time()
|
||||||
|
|
||||||
class CPU:
|
class CPU:
|
||||||
SCALING_FREQUENCIES = [1700000, 2400000, 2800000]
|
SCALING_FREQUENCIES = [1700000, 2400000, 2800000]
|
||||||
|
@ -246,15 +247,27 @@ class Plugin:
|
||||||
# startup: load & apply settings
|
# startup: load & apply settings
|
||||||
if os.path.exists(SETTINGS_LOCATION):
|
if os.path.exists(SETTINGS_LOCATION):
|
||||||
settings = read_json(SETTINGS_LOCATION)
|
settings = read_json(SETTINGS_LOCATION)
|
||||||
logging.debug(f"Loaded settings from file: {settings}")
|
logging.debug(f"Loaded settings from {SETTINGS_LOCATION}: {settings}")
|
||||||
else:
|
else:
|
||||||
settings = None
|
settings = None
|
||||||
|
logging.debug(f"Settings {SETTINGS_LOCATION} does not exist, skipped")
|
||||||
if settings is None or settings["persistent"] == False:
|
if settings is None or settings["persistent"] == False:
|
||||||
|
logging.debug("Ignoring settings from file")
|
||||||
self.persistent = False
|
self.persistent = False
|
||||||
self.cpus = []
|
self.cpus = []
|
||||||
|
|
||||||
for cpu_number in range(0, Plugin.CPU_COUNT):
|
for cpu_number in range(0, Plugin.CPU_COUNT):
|
||||||
self.cpus.append(CPU(cpu_number))
|
self.cpus.append(CPU(cpu_number))
|
||||||
|
|
||||||
|
# If any core has two threads, smt is True
|
||||||
|
self.smt = self.cpus[1].status()
|
||||||
|
if(not self.smt):
|
||||||
|
for cpu_number in range(2, len(self.cpus), 2):
|
||||||
|
if(self.cpus[cpu_number].status()):
|
||||||
|
self.smt = True
|
||||||
|
break
|
||||||
|
logging.info(f"SMT state is guessed to be {self.smt}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# apply settings
|
# apply settings
|
||||||
logging.debug("Restoring settings from file")
|
logging.debug("Restoring settings from file")
|
||||||
|
@ -274,6 +287,7 @@ class Plugin:
|
||||||
write_to_sys("/sys/class/hwmon/hwmon5/recalculate", 1)
|
write_to_sys("/sys/class/hwmon/hwmon5/recalculate", 1)
|
||||||
write_to_sys("/sys/class/hwmon/hwmon5/fan1_target", settings["fan"]["target"])
|
write_to_sys("/sys/class/hwmon/hwmon5/fan1_target", settings["fan"]["target"])
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
|
logging.info("Handled saved settings, back-end startup complete")
|
||||||
# work loop
|
# work loop
|
||||||
while True:
|
while True:
|
||||||
if self.modified_settings and self.persistent:
|
if self.modified_settings and self.persistent:
|
||||||
|
@ -283,14 +297,8 @@ class Plugin:
|
||||||
|
|
||||||
# called from main_view::onViewReady
|
# called from main_view::onViewReady
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
|
delta = time.time() - startup_time
|
||||||
# If any core has two threads, smt is True
|
logging.info(f"Front-end initialised {delta}s after startup")
|
||||||
self.smt = self.cpus[1].status()
|
|
||||||
if(not self.smt):
|
|
||||||
for cpu_number in range(2, len(self.cpus), 2):
|
|
||||||
if(self.cpus[cpu_number].status()):
|
|
||||||
self.smt = True
|
|
||||||
break
|
|
||||||
|
|
||||||
# persistence
|
# persistence
|
||||||
|
|
||||||
|
@ -334,7 +342,7 @@ class Plugin:
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
settings = self.current_settings(self)
|
settings = self.current_settings(self)
|
||||||
logging.debug(f"Saving settings to file: {settings}")
|
logging.info(f"Saving settings to file: {settings}")
|
||||||
write_json(SETTINGS_LOCATION, settings)
|
write_json(SETTINGS_LOCATION, settings)
|
||||||
|
|
||||||
|
|
||||||
|
@ -371,10 +379,13 @@ def read_fan_target() -> int:
|
||||||
def write_to_sys(path, value: int):
|
def write_to_sys(path, value: int):
|
||||||
with open(path, mode="w") as f:
|
with open(path, mode="w") as f:
|
||||||
f.write(str(value))
|
f.write(str(value))
|
||||||
|
logging.debug(f"Wrote `{value}` to {path}")
|
||||||
|
|
||||||
def read_from_sys(path, amount=1):
|
def read_from_sys(path, amount=1):
|
||||||
with open(path, mode="r") as f:
|
with open(path, mode="r") as f:
|
||||||
return f.read(amount)
|
value = f.read(amount)
|
||||||
|
logging.debug(f"Read `{value}` from {path}")
|
||||||
|
return value
|
||||||
|
|
||||||
def read_sys_int(path) -> int:
|
def read_sys_int(path) -> int:
|
||||||
return int(read_from_sys(path, amount=-1).strip())
|
return int(read_from_sys(path, amount=-1).strip())
|
||||||
|
@ -386,3 +397,6 @@ def write_json(path, data):
|
||||||
def read_json(path):
|
def read_json(path):
|
||||||
with open(path, mode="r") as f:
|
with open(path, mode="r") as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
|
||||||
|
os_release = read_from_sys("/etc/os-release", amount=-1).strip()
|
||||||
|
logging.info(f"/etc/os-release\n{os_release}")
|
||||||
|
|
Loading…
Reference in a new issue