diff --git a/tuna-Add-cleanlogs-rule-to-Makefile.patch b/tuna-Add-cleanlogs-rule-to-Makefile.patch new file mode 100644 index 0000000..dca3db9 --- /dev/null +++ b/tuna-Add-cleanlogs-rule-to-Makefile.patch @@ -0,0 +1,31 @@ +From 681304a9a57a9c2b05fcc2cc372e3d921b5ff415 Mon Sep 17 00:00:00 2001 +From: Leah Leshchinsky +Date: Tue, 10 May 2022 11:59:08 -0400 +Subject: [PATCH 2/2] tuna: Add cleanlogs rule to Makefile + +The logging infrastructure creates directories that contain log files. +It may be tedious for users to manually remove these directories and +files. + +Add a Makefile rule that allows for easy removal of multiple logging +directories. The rule can be called via 'make cleanlogs'. + +Signed-off-by: Leah Leshchinsky +Signed-off-by: John Kacur + +diff --git a/Makefile b/Makefile +index 2c72feaa398c..50ded3985743 100644 +--- a/Makefile ++++ b/Makefile +@@ -45,4 +45,8 @@ tags: + cleantags: + rm -f tags + ++.PHONY: cleanlogs ++cleanlogs: ++ rm -rf tuna-20* ++ + clean: pyclean rpmclean +-- +2.27.0 + diff --git a/tuna-Add-logging-infrastructure-to-tuna-cmd.patch b/tuna-Add-logging-infrastructure-to-tuna-cmd.patch new file mode 100644 index 0000000..e665919 --- /dev/null +++ b/tuna-Add-logging-infrastructure-to-tuna-cmd.patch @@ -0,0 +1,159 @@ +From 85330a8ab1afec5370676e7c3d753a4528f24e6f Mon Sep 17 00:00:00 2001 +From: Leah Leshchinsky +Date: Tue, 10 May 2022 11:59:07 -0400 +Subject: [PATCH 1/2] tuna: Add logging infrastructure to tuna-cmd + +Currently, tuna does not have an easy way for developers and maintainers +to access necessary information about the state of the program. + +Add logging infrastructure that allows the user to specify, at the +command line, what level of logging to print from the following levels: +(notset, debug, info, warning, error, critical). Levels may also be +specified numerically, ranging from 0-5. + +A directory will be created with the current date and test run. +Logging statements will print to a log file within the created directory, +and can be specified with the '-L' and '--logging' flags. The '-D' and +'--debug' flags will print all debug information to the console. + +Logging of other files outside of tuna-cmd.py can be implemented by +importing the logging directory and adding the necessary logging +statments. + +Signed-off-by: Leah Leshchinsky +Signed-off-by: John Kacur + +diff --git a/tuna-cmd.py b/tuna-cmd.py +index ac21481df554..57b62298c48a 100755 +--- a/tuna-cmd.py ++++ b/tuna-cmd.py +@@ -29,6 +29,50 @@ import ethtool + import tuna.tuna_sched as tuna_sched + import procfs + from tuna import tuna, sysfs ++import logging ++import time ++ ++def get_loglevel(level): ++ if level.isdigit() and int(level) in range(0,5): ++ # logging built-in module levels: ++ # 0 - NOTSET ++ # 10 - DEBUG ++ # 20 - INFO, ++ # 30 - WARNING ++ # 40 - ERROR ++ return int(level) * 10 ++ level_str = level.upper() ++ if level_str == "CRITICAL": ++ raise ValueError("CRITICAL level is not supported by tuna") ++ return level_str ++ ++def setup_logging(logger_name): ++ ++ logger = logging.getLogger(logger_name) ++ logger.setLevel(logging.DEBUG) ++ logger.propagate = False ++ return logger ++ ++def add_handler(loglevel, tofile=False): ++ ++ formatter = logging.Formatter('[%(levelname)s] %(message)s') ++ ++ if tofile: ++ lognum = 1 ++ date = time.strftime("%Y%m%d") ++ while os.path.exists("tuna-{}-{}".format(date, lognum)): ++ lognum += 1 ++ ++ path = "tuna-{}-{}/log/Log".format(date,lognum) ++ os.makedirs(os.path.dirname(path), exist_ok=True, mode=0o777) ++ handler = logging.FileHandler(path) ++ else: ++ handler = logging.StreamHandler(sys.stderr) ++ ++ handler.setFormatter(formatter) ++ handler.setLevel(loglevel) ++ ++ return handler + + try: + import inet_diag +@@ -61,6 +105,7 @@ def usage(): + _('Operation will affect children threads'))) + print(fmt % ('-d, --disable_perf', + _('Explicitly disable usage of perf in GUI for process view'))) ++ print(fmt % ('-D, --debug', _('Print DEBUG level logging details to console'))) + print(fmt % ('-f, --filter', + _('Display filter the selected entities'))) + print(fmt % ('-i, --isolate', _('Move all allowed threads and IRQs away from %(cpulist)s') % +@@ -69,6 +114,8 @@ def usage(): + {"cpulist": _('CPU-LIST')})) + print(fmt % ('-K, --no_kthreads', + _('Operations will not affect kernel threads'))) ++ print(fmt % ('-L, --logging', ++ _('Log application details to log file for given LOG-LEVEL'))) + print(fmt % ('-m, --move', _('Move selected entities to %(cpulist)s') % + {"cpulist": _('CPU-LIST')})) + print(fmt % ('-N, --nohz_full', +@@ -490,14 +537,14 @@ def main(): + + i18n_init() + try: +- short = "a:c:dCfgGhiIKlmNp:PQq:r:R:s:S:t:UvWx" ++ short = "a:c:dDCfgGhiIKlmNp:PQq:r:R:s:S:t:UvWxL:" + long = ["cpus=", "affect_children", "filter", "gui", "help", + "isolate", "include", "no_kthreads", "move", "nohz_full", + "show_sockets", "priority=", "show_threads", + "show_irqs", "irqs=", + "save=", "sockets=", "threads=", "no_uthreads", + "version", "what_is", "spread", "cgroup", "config_file_apply=", +- "config_file_list", "run=", "refresh=", "disable_perf"] ++ "config_file_list", "run=", "refresh=", "disable_perf", "logging=", "debug"] + if have_inet_diag: + short += "n" + long.append("show_sockets") +@@ -512,8 +559,10 @@ def main(): + uthreads = True + cgroups = False + cpu_list = None ++ debug = False + irq_list = None + irq_list_str = None ++ log = False + rtprio = None + policy = None + thread_list = [] +@@ -529,6 +578,30 @@ def main(): + if o in ("-h", "--help"): + usage() + return ++ if o in ("-D", "--debug"): ++ if debug: ++ my_logger.warning("Debugging already set") ++ continue ++ debug = True ++ if not log: ++ my_logger = setup_logging("my_logger") ++ my_logger.addHandler(add_handler("DEBUG", tofile=False)) ++ my_logger.info("Debug option set") ++ if o in ("-L", "--logging"): ++ if log: ++ my_logger.warning("Logging already set") ++ continue ++ log = True ++ loglevel = get_loglevel(a) ++ if not debug: ++ my_logger = setup_logging("my_logger") ++ try: ++ my_logger.addHandler(add_handler(loglevel, tofile=True)) ++ except ValueError as e: ++ print(e, "tuna: --logging requires valid logging level\n") ++ print("Valid log levels: NOTSET, DEBUG, INFO, WARNING, ERROR") ++ print("Log levels may be specified numerically (0-4)") ++ my_logger.info("Logging option set") + if o in ("-a", "--config_file_apply"): + apply_config(a) + elif o in ("-l", "--config_file_list"): +-- +2.27.0 + diff --git a/tuna-Fix-typo-for-variable-parm.patch b/tuna-Fix-typo-for-variable-parm.patch new file mode 100644 index 0000000..0dc1d31 --- /dev/null +++ b/tuna-Fix-typo-for-variable-parm.patch @@ -0,0 +1,26 @@ +From 8cad3c289471b985a8d0b7f698fcbf5ecbfa7bb5 Mon Sep 17 00:00:00 2001 +From: Leah Leshchinsky +Date: Wed, 2 Feb 2022 15:18:26 -0500 +Subject: [PATCH 1/5] tuna: Fix typo for variable 'parm' + +Variable 'parms' should be 'parm'. Fix typo. + +Signed-off-by: Leah Leshchinsky +Signed-off-by: John Kacur + +diff --git a/tuna/tuna.py b/tuna/tuna.py +index 8fb42121e2e4..126990339985 100755 +--- a/tuna/tuna.py ++++ b/tuna/tuna.py +@@ -561,7 +561,7 @@ def threads_set_priority(tids, parm, affect_children=False): + try: + (policy, rtprio) = get_policy_and_rtprio(parm) + except ValueError: +- print("tuna: " + _("\"%s\" is unsupported priority value!") % parms[0]) ++ print("tuna: " + _("\"%s\" is an unsupported priority value!") % parm[0]) + return + + for tid in tids: +-- +2.27.0 + diff --git a/tuna-Handle-get_policy_and_rtprio-exceptions.patch b/tuna-Handle-get_policy_and_rtprio-exceptions.patch new file mode 100644 index 0000000..8b6eb90 --- /dev/null +++ b/tuna-Handle-get_policy_and_rtprio-exceptions.patch @@ -0,0 +1,39 @@ +From f857c822256d512d351cda0d8fa4d5d255d1e64f Mon Sep 17 00:00:00 2001 +From: Leah Leshchinsky +Date: Wed, 2 Feb 2022 15:18:27 -0500 +Subject: [PATCH 2/5] tuna: Handle get_policy_and_rtprio exceptions + +In tuna-cmd.py, if a thread list is passed along with the +'--priority' flag, tuna.get_policy_and_rtprio() is called twice, first +directly, and then again by tuna.threads_set_priority(). The +expectation is that tuna.threads_set_priority will handle exceptions +raised by tuna.get_policy_and_rtprio(). This results in a failure to +handle exceptions that are raised by the initial direct call to +tuna.get_policy_and_rtprio(). + +Handle exceptions that may be raised during direct calls to +get_policy_and_rtprio in tuna-cmd.py. + +Signed-off-by: Leah Leshchinsky +Signed-off-by: John Kacur + +diff --git a/tuna-cmd.py b/tuna-cmd.py +index cf117ec046ff..2b6e91bd0104 100755 +--- a/tuna-cmd.py ++++ b/tuna-cmd.py +@@ -601,7 +601,11 @@ def main(): + tuna.include_cpus(cpu_list, get_nr_cpus()) + elif o in ("-p", "--priority"): + # Save policy and rtprio for future Actions (e.g. --run). +- (policy, rtprio) = tuna.get_policy_and_rtprio(a) ++ try: ++ (policy, rtprio) = tuna.get_policy_and_rtprio(a) ++ except ValueError: ++ print("tuna: " + _("\"%s\" is an unsupported priority value!") % a) ++ sys.exit(2) + if not thread_list: + # For backward compatibility + p_waiting_action = True +-- +2.27.0 + diff --git a/tuna-Remove-finally-block-in-get_policy_and_rtprio.patch b/tuna-Remove-finally-block-in-get_policy_and_rtprio.patch new file mode 100644 index 0000000..cebc8d3 --- /dev/null +++ b/tuna-Remove-finally-block-in-get_policy_and_rtprio.patch @@ -0,0 +1,34 @@ +From adba6d6cad1a5c9f062dcf5ee4b4be40d4dc134f Mon Sep 17 00:00:00 2001 +From: Leah Leshchinsky +Date: Wed, 2 Feb 2022 15:18:29 -0500 +Subject: [PATCH 3/5] tuna: Remove finally block in get_policy_and_rtprio + +The implementation of the error handling block in +tuna.get_policy_and_rtprio() caused the exceptions raised by +tuna_sched.Policy to be consumed by the finally block. +When an invalid policy is passed via the '--priority' flag, +this consumption of the exception causes tuna to fail silently. + +Remove the finally block in tuna.get_policy_and_rtprio(). + +Signed-off-by: Leah Leshchinsky +Signed-off-by: John Kacur + +diff --git a/tuna/tuna.py b/tuna/tuna.py +index 126990339985..31707c9cb69c 100755 +--- a/tuna/tuna.py ++++ b/tuna/tuna.py +@@ -520,8 +520,8 @@ def get_policy_and_rtprio(parm): + rtprio = int(parms[1]) + elif cp.is_rt(): + rtprio = 1 +- finally: +- return(policy, rtprio) ++ ++ return (policy, rtprio) + + def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads): + if cpus_filtered: +-- +2.27.0 + diff --git a/tuna.spec b/tuna.spec index 72b6bb6..0429561 100644 --- a/tuna.spec +++ b/tuna.spec @@ -1,6 +1,6 @@ Name: tuna Version: 0.17 -Release: 1%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: Application tuning GUI & command line utility Group: Applications/System @@ -17,6 +17,11 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) # PATCHES Patch1: tuna-Fix-ModuleNotFoundError.patch +Patch2: tuna-Fix-typo-for-variable-parm.patch +Patch3: tuna-Handle-get_policy_and_rtprio-exceptions.patch +Patch4: tuna-Remove-finally-block-in-get_policy_and_rtprio.patch +Patch5: tuna-Add-logging-infrastructure-to-tuna-cmd.patch +Patch6: tuna-Add-cleanlogs-rule-to-Makefile.patch %description Provides interface for changing scheduler and IRQ tunables, at whole CPU and at @@ -30,6 +35,11 @@ installed. %prep %setup -q %patch1 -p1 +%patch2 -p1 +%patch3 -p1 +%patch4 -p1 +%patch5 -p1 +%patch6 -p1 %build %{__python3} setup.py build @@ -76,6 +86,17 @@ rm -rf %{buildroot} %{_datadir}/polkit-1/actions/org.tuna.policy %changelog +* Thu May 19 2022 Leah Leshchinsky - 0.17-3 +- Add logging infrastructure to tuna +- Add cleanlogs rule to Makefile +Resolves: rhbz#2062882 + +* Mon Apr 11 2022 Leah Leshchinsky - 0.17-2 +- Fix typo for variable parm +- Handle get_policy_and_rtprio exceptions +- Remove finally block in get_policy_and_rtprio +Resolves: rhbz#2049746 + * Thu Jan 13 2022 Leah Leshchinsky - 0.17-1 - Rebase to upstream version 0.17 - Fix ModuleNotFoundError