From fb8815823562371384d69a8dfbac9cc1939a6b10 Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Fri, 11 Sep 2020 21:15:59 +0200 Subject: [PATCH] refactor + additon of new functionality i,e (app_res_use) --- bin/auto-cpufreq | 12 ++++++++---- source/core.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index a141496..2ea19a4 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -54,10 +54,7 @@ def main(monitor, live, daemon, install, log, debug): countdown(5) run("clear") else: - print("\n" + "-" * 32 + " Daemon check " + "-" * 33 + "\n") - print("ERROR:\n\nDaemon not enabled, must run install first, i.e: \nsudo auto-cpufreq --install") - footer() - exit(1) + daemon_not_found() elif monitor: while True: root_check() @@ -100,6 +97,13 @@ def main(monitor, live, daemon, install, log, debug): print("") python_info() print("") + if charging(): + print("Battery is: charging") + else: + print("Battery is: discharging") + print("") + app_res_use() + print("") sysinfo() display_load() get_current_gov() diff --git a/source/core.py b/source/core.py index bb3e7ea..05ac64d 100644 --- a/source/core.py +++ b/source/core.py @@ -47,6 +47,12 @@ dcheck = getoutput("snapctl get daemon") def app_version(): print("Build git commit:", check_output(["git", "describe", "--always"]).strip().decode()) +def app_res_use(): + p = psutil.Process() + print("auto-cpufreq system resource consumption:") + print("cpu usage:", p.cpu_percent(), "%") + print("memory use:", round(p.memory_percent(),2), "%") + # set/change state of turbo def turbo(value: bool = None): """ @@ -163,6 +169,11 @@ def cpufreqctl_restore(): def footer(l=79): print("\n" + "-" * l + "\n") +def daemon_not_found(): + print("\n" + "-" * 32 + " Daemon check " + "-" * 33 + "\n") + print("ERROR:\n\nDaemon not enabled, must run install first, i.e: \nsudo auto-cpufreq --install") + footer() + sys.exit() def deploy_complete_msg(): print("\n" + "-" * 17 + " auto-cpufreq daemon installed and running " + "-" * 17 + "\n") @@ -363,10 +374,10 @@ def set_autofreq(): # determine which governor should be used if charging(): - print("Battery is: charging") + print("Battery is: charging\n") set_performance() else: - print("Battery is: discharging") + print("Battery is: discharging\n") set_powersave() @@ -379,12 +390,12 @@ def mon_autofreq(): # determine which governor should be used if charging(): - print("Battery is: charging") + print("Battery is: charging\n") get_current_gov() print(f"Suggesting use of \"{get_avail_performance()}\" governor") mon_performance() else: - print("Battery is: discharging") + print("Battery is: discharging\n") get_current_gov() print(f"Suggesting use of \"{get_avail_powersave()}\" governor") mon_powersave() @@ -495,14 +506,24 @@ def sysinfo(): # read log func def read_log(): + + def no_log_msg(): + print("\n" + "-" * 30 + " auto-cpufreq log " + "-" * 31 + "\n") + print("ERROR: auto-cpufreq log is missing.\n\nMake sure to run: \"auto-cpufreq --install\" first") + + # read log (snap) if os.getenv("PKG_MARKER") == "SNAP": - call(["tail", "-n 50", "-f", str(auto_cpufreq_log_file_snap)]) + if os.path.isfile(auto_cpufreq_log_file_snap): + call(["tail", "-n 50", "-f", str(auto_cpufreq_log_file_snap)]) + else: + no_log_msg() + # read log (non snap) elif os.path.isfile(auto_cpufreq_log_file): call(["tail", "-n 50", "-f", str(auto_cpufreq_log_file)]) else: - print("\n" + "-" * 30 + " auto-cpufreq log " + "-" * 31 + "\n") - print("ERROR: auto-cpufreq log is missing.\n\nMake sure to run: \"auto-cpufreq --install\" first") + no_log_msg() footer() + sys.exit() # check if program (argument) is running