import tuna-0.18-6.el8

This commit is contained in:
CentOS Sources 2023-05-16 06:23:55 +00:00 committed by Stepan Oksanichenko
parent 86ef4a5ef2
commit f3a74fa370
8 changed files with 588 additions and 3 deletions

View File

@ -0,0 +1,175 @@
From 9dfaafe278f6cccf6911cddef413dc59e87722e7 Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Wed, 16 Nov 2022 10:38:10 -0500
Subject: [PATCH] tuna: Adapt show_threads cgroup output to terminal size
Passing the --cgroup flag for the --show_threads command currently displays
long cgroup strings on the thread output and decreases readability.
Adapt the show_threads output to account for output string and terminal
size, and format output accordingly to improve readability. Add
--spaced flag to --show_threads to print cgroups spacing in
between thread outputs.
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
---
target branch: getopt
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
diff --git a/docs/tuna.8 b/docs/tuna.8
index 3a06556..218ba14 100644
--- a/docs/tuna.8
+++ b/docs/tuna.8
@@ -80,6 +80,9 @@ Disable display of selected CPUs in \fB--gui\fR. Requires \fB-c\R.
\fB\-G\fR, \fB\-\-cgroup\fR
Display the processes with the type of cgroups they are in. Requires \fB-P\R.
.TP
+\fB\-z\fR, \fB\-\-spaced\fR
+Display spaced view for cgroups. Requires \fB-G\R.
+.TP
\fB\-K\fR, \fB\-\-no_kthreads\fR
Operations will not affect kernel threads.
.TP
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 75b63da..54dc567 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -99,6 +99,8 @@ def usage():
print(fmt % ('-g, --gui', _('Start the GUI')))
print(fmt % ('-G, --cgroup',
_('Display the processes with the type of cgroups they are in')))
+ print(fmt % ('-z, --spaced',
+ "Display spaced view for cgroups"))
print(fmt % ('-c, --cpus=' + _('CPU-LIST'), _('%(cpulist)s affected by commands') %
{"cpulist": _('CPU-LIST')}))
print(fmt % ('-C, --affect_children',
@@ -249,7 +251,7 @@ def format_affinity(affinity):
return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, get_nr_cpus()))
def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
- sock_inode_re, cgroups):
+ sock_inode_re, cgroups, columns=None, compact=True):
global irqs
try:
affinity = format_affinity(os.sched_getaffinity(pid))
@@ -286,10 +288,20 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
nonvoluntary_ctxt_switches)
# Indent affected children
- print(" %-5d " % pid if affect_children else " %-5d" % pid, end=' ')
- print("%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
- ctxt_switch_info, cmd, users), end=' ')
- print(" %9s" % cgout if cgroups else "")
+ s1 = " %-5d " % pid if affect_children else " %-5d" % pid
+ print(s1, end=' ')
+ s2 = "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
+ ctxt_switch_info, cmd, users)
+ print(s2, end=' ')
+
+ if cgroups:
+ length = int(columns) - len(s1 + " ") - len(s2 + " ")
+ if len(" %9s" % cgout) <= length:
+ print("%s" % cgout)
+ else:
+ print("\n %s" % cgout + ("" if compact else "\n"))
+ else:
+ print()
if sock_inodes:
ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
@@ -298,12 +310,12 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
for tid in list(ps[pid]["threads"].keys()):
ps_show_thread(tid, False, ps[pid]["threads"],
has_ctxt_switch_info,
- sock_inodes, sock_inode_re, cgroups)
+ sock_inodes, sock_inode_re, cgroups, columns, compact)
def ps_show(ps, affect_children, thread_list, cpu_list,
irq_list_numbers, show_uthreads, show_kthreads,
- has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups):
+ has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups, compact):
ps_list = []
for pid in list(ps.keys()):
@@ -340,9 +352,14 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
ps_list.sort()
+ # Width of terminal in columns
+ columns = None
+ if cgroups:
+ _, columns = os.popen('stty size', 'r').read().split()
+
for pid in ps_list:
ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info,
- sock_inodes, sock_inode_re, cgroups)
+ sock_inodes, sock_inode_re, cgroups, columns, compact)
def load_socktype(socktype, inodes):
@@ -363,7 +380,7 @@ def load_sockets():
def do_ps(thread_list, cpu_list, irq_list, show_uthreads, show_kthreads,
- affect_children, show_sockets, cgroups):
+ affect_children, show_sockets, cgroups, compact):
ps = procfs.pidstats()
if affect_children:
ps.reload_threads()
@@ -380,7 +397,7 @@ def do_ps(thread_list, cpu_list, irq_list, show_uthreads, show_kthreads,
ps_show_header(has_ctxt_switch_info, cgroups)
ps_show(ps, affect_children, thread_list,
cpu_list, irq_list, show_uthreads, show_kthreads,
- has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups)
+ has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups, compact)
except IOError:
# 'tuna -P | head' for instance
pass
@@ -535,13 +552,13 @@ def main():
i18n_init()
try:
- short = "a:c:dDCfgGhiIKlmNp:PQq:r:R:s:S:t:UvWxL:"
+ short = "a:c:dDCfgGzhiIKlmNp: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=",
+ "version", "what_is", "spread", "cgroup", "spaced", "config_file_apply=",
"config_file_list", "run=", "refresh=", "disable_perf", "logging=", "debug"]
if have_inet_diag:
short += "n"
@@ -556,6 +573,7 @@ def main():
kthreads = True
uthreads = True
cgroups = False
+ compact = True
cpu_list = None
debug = False
irq_list = None
@@ -623,6 +641,8 @@ def main():
affect_children = True
elif o in ("-G", "--cgroup"):
cgroups = True
+ elif o in ("-z", "--spaced"):
+ compact = False
elif o in ("-t", "--threads"):
# The -t - will reset thread list
if a == '-':
@@ -691,7 +711,7 @@ def main():
if thread_list_str or irq_list_str:
continue
do_ps(thread_list, cpu_list, irq_list, uthreads,
- kthreads, affect_children, show_sockets, cgroups)
+ kthreads, affect_children, show_sockets, cgroups, compact)
elif o in ("-Q", "--show_irqs"):
# If the user specified IRQ names that weren't
# resolved to IRQs, don't show all IRQs.
--
2.38.1

View File

@ -0,0 +1,52 @@
From 3f1fbb092f5ef07d04fef7ddec9e538f36d84450 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Fri, 2 Sep 2022 11:55:07 -0400
Subject: [PATCH] tuna: Fix matching irqs in ps_show_thread
The new format to match irqs is "irqs/"
We already test this when we call is_irq_thread(cmd):
With this fix if you do
tuna show_threads
You will get nic information that was previously missed such as
986 FIFO 50 9 69286 2 irq/164-iwlwifi:default_que
ue iwlwifi:default_queue
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index b13b25b8a801..80e27523acc6 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -351,17 +351,12 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
try:
if not irqs:
irqs = procfs.interrupts()
- if cmd[:4] == "IRQ-":
- users = irqs[tuna.irq_thread_number(cmd)]["users"]
- for u in users:
- if u in get_nics():
- users[users.index(u)] = "%s(%s)" % (
- u, ethtool.get_module(u))
- users = ",".join(users)
- else:
- u = cmd[cmd.find('-') + 1:]
+ users = irqs[tuna.irq_thread_number(cmd)]["users"]
+ for u in users:
if u in get_nics():
- users = ethtool.get_module(u)
+ users[users.index(u)] = "%s(%s)" % (
+ u, ethtool.get_module(u))
+ users = ",".join(users)
except:
users = "Not found in /proc/interrupts!"
--
2.37.3

View File

@ -0,0 +1,42 @@
From 613bc73f6ad821db682e9efc097c29af9cb40858 Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Wed, 23 Nov 2022 14:14:36 -0500
Subject: [PATCH] tuna: Fix --show_threads --cgroup without a term
When tuna --show_threads --cgroups is run without a term,
provide a default column size of 80 to fix a traceback
that occurred when querying the terminal size.
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
- Edited the commit title
- Edited the description
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 54dc567..f5dafa7 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -31,6 +31,7 @@ import procfs
from tuna import tuna, sysfs
import logging
import time
+import shutil
def get_loglevel(level):
if level.isdigit() and int(level) in range(0,5):
@@ -353,9 +354,10 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
ps_list.sort()
# Width of terminal in columns
- columns = None
+ columns = 80
if cgroups:
- _, columns = os.popen('stty size', 'r').read().split()
+ if os.isatty(sys.stdout.fileno()):
+ columns = shutil.get_terminal_size().columns
for pid in ps_list:
ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info,
--
2.38.1

View File

@ -0,0 +1,104 @@
From ff1963daf4d5a23e5f9476710e983ab781210608 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 27 Sep 2022 12:59:54 -0400
Subject: [PATCH 1/2] tuna: Replace python_ethtool with builtin funtionality
This patch replaces the dependency on python_ethtool with some
simplified functions to achieve the same result.
Reviewed-by: Federico Pellegrin <fede@evolware.org>
- return 'tun' only if tun_flags exists
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 2 +-
tuna/gui/irqview.py | 2 +-
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
tuna/tuna.py | 2 +-
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100755 tuna/new_eth.py
diff --git a/tuna-cmd.py b/tuna-cmd.py
index bdaa70ffc156..21a70cf1d37d 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -25,7 +25,7 @@ import fnmatch
import gettext
import locale
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 35fc3fd0b0ca..5143d6dc0df5 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -7,7 +7,7 @@ from gi.repository import Gtk
from gi.repository import GObject
import os
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import gi
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
new file mode 100755
index 000000000000..98f9179d5695
--- /dev/null
+++ b/tuna/new_eth.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 John Kacur
+""" A few functions similar to ethtool """
+import os
+import socket
+
+def get_active_devices():
+ """ return a list of network devices """
+ ret = []
+
+ for device in socket.if_nameindex():
+ ret.append(device[1])
+
+ return ret
+
+def get_module(intf):
+ """ return the kernel module for the given network interface """
+ if intf == 'lo':
+ return ""
+ myp = f'/sys/class/net/{intf}/device/driver'
+ if os.path.exists(myp):
+ return os.path.basename(os.readlink(myp))
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
+ return 'bridge'
+ if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
+ return 'tun'
+ return ""
+
+if __name__ == "__main__":
+ nics = get_active_devices()
+ print(f'nics = {nics}')
+
+ for intf in nics:
+ driver = get_module(intf)
+ if driver:
+ print(f'{intf}, {driver}')
+ else:
+ print(f'{intf}')
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 31707c9cb69c..84419c957b1b 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,7 +9,7 @@ import sys
import shlex
import fnmatch
import platform
-import ethtool
+import tuna.new_eth as ethtool
import procfs
from procfs import utilist
from tuna import help
--
2.37.3

View File

@ -0,0 +1,66 @@
From e9f60274865475c4e9081ee356ffbc61d1df2ade Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Wed, 2 Nov 2022 10:57:19 -0400
Subject: [PATCH 3/3] tuna: tuna-cmd.py use fstrings
Add fstrings where possible to improve readabilty
Due to the discussion regarding dropping the language feature, gettext
shorthand _() have been removed.
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 79e33371837e..75b63da972c2 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -176,13 +176,16 @@ def thread_help(tid):
ps = procfs.pidstats()
if tid not in ps:
- print("tuna: " + _("thread %d doesn't exists!") % tid)
+ print(f"tuna: thread {tid} doesn't exist!")
return
pinfo = ps[tid]
cmdline = procfs.process_cmdline(pinfo)
help, title = tuna.kthread_help_plain_text(tid, cmdline)
- print("%s\n\n%s" % (title, _(help)))
+ print(title, "\n\n")
+ if help.isspace():
+ help = "No help description available."
+ print(help)
def save(cpu_list, thread_list, filename):
@@ -208,7 +211,7 @@ def ps_show_header(has_ctxt_switch_info, cgroups=False):
def ps_show_sockets(pid, ps, inodes, inode_re, indent=0):
header_printed = False
- dirname = "/proc/%s/fd" % pid
+ dirname = f"/proc/{pid}/fd"
try:
filenames = os.listdir(dirname)
except: # Process died
@@ -650,7 +653,7 @@ def main():
try:
gui_refresh=int(a)
except Exception as err:
- print("tuna: --refresh %s" % err)
+ print(f"tuna: --refresh {err}")
sys.exit(2)
elif o in ("-d", "--disable_perf"):
run_gui = True
@@ -679,7 +682,7 @@ def main():
try:
tuna.threads_set_priority(thread_list, a, affect_children)
except OSError as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
elif o in ("-P", "--show_threads"):
# If the user specified process names that weren't
--
2.31.1

View File

@ -0,0 +1,94 @@
From 5f90d8b80a259884d3ca2a647fdf9471b7d7091c Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Mon, 31 Oct 2022 13:15:07 -0400
Subject: [PATCH 1/3] tuna: tuna.py use fstrings
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 84419c957b1b..e64211b88fc3 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -58,7 +58,7 @@ def iskthread(pid):
# in this function, so that they know that the thread vanished and
# can act accordingly, removing entries from tree views, etc
try:
- f = open("/proc/%d/smaps" % pid)
+ f = open(f"/proc/{pid}/smaps")
except IOError:
# Thread has vanished
return True
@@ -88,7 +88,7 @@ def is_irq_thread(cmd):
return cmd[:4] in ("IRQ-", "irq/")
def threaded_irq_re(irq):
- return re.compile("(irq/%s-.+|IRQ-%s)" % (irq, irq))
+ return re.compile(f"(irq/{irq}-.+|IRQ-{irq})")
# FIXME: Move to python-linux-procfs
def has_threaded_irqs(ps):
@@ -96,10 +96,10 @@ def has_threaded_irqs(ps):
return len(ps.find_by_regex(irq_re)) > 0
def set_irq_affinity_filename(filename, bitmasklist):
- pathname = "/proc/irq/%s" % filename
+ pathname = f"/proc/irq/{filename}"
f = open(pathname, "w")
text = ",".join(["%x" % a for a in bitmasklist])
- f.write("%s\n" % text)
+ f.write(f"{text}\n")
try:
f.close()
except IOError:
@@ -225,7 +225,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
if pid not in ps:
continue
- threads = procfs.pidstats("/proc/%d/task" % pid)
+ threads = procfs.pidstats(f"/proc/{pid}/task")
for tid in list(threads.keys()):
try:
curr_affinity = os.sched_getaffinity(tid)
@@ -320,11 +320,11 @@ def affinity_remove_cpus(affinity, cpus, nr_cpus):
# Should be moved to python_linux_procfs.interrupts, shared with interrupts.parse_affinity, etc.
def parse_irq_affinity_filename(filename, nr_cpus):
try:
- f = open("/proc/irq/%s" % filename)
+ f = open(f"/proc/irq/{filename}")
except IOError as err:
if procfs.is_s390():
print("This operation is not supported on s390", file=sys.stderr)
- print("tuna: %s" % err, file=sys.stderr)
+ print(f"tuna: {err}", file=sys.stderr)
sys.exit(2)
line = f.readline()
@@ -627,19 +627,19 @@ def run_command(cmd, policy, rtprio, cpu_list):
try:
thread_set_priority(pid, policy, rtprio)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
if cpu_list:
try:
os.sched_setaffinity(pid, cpu_list)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
try:
os.execvp(cmd_list[0], cmd_list)
except (SystemError, OSError) as err:
- print("tuna: %s" % err)
+ print(f"tuna: {err}")
sys.exit(2)
else:
os.waitpid(newpid, 0)
--
2.31.1

View File

@ -0,0 +1,26 @@
From f53f77f73199f398713f8edfdfa417cf8b9e1a74 Mon Sep 17 00:00:00 2001
From: Leah Leshchinsky <lleshchi@redhat.com>
Date: Fri, 28 Oct 2022 13:14:04 -0400
Subject: [PATCH 2/3] tuna: tuna_gui.py use fstrings
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/tuna/tuna_gui.py b/tuna/tuna_gui.py
index f1f2caacbcba..459f90303ed5 100755
--- a/tuna/tuna_gui.py
+++ b/tuna/tuna_gui.py
@@ -33,7 +33,7 @@ class main_gui:
if self.check_root():
sys.exit(1)
for dir in tuna_glade_dirs:
- tuna_glade = "%s/tuna_gui.glade" % dir
+ tuna_glade = f"{dir}/tuna_gui.glade"
if os.access(tuna_glade, os.F_OK):
break
self.wtree = Gtk.Builder()
--
2.31.1

View File

@ -1,6 +1,6 @@
Name: tuna
Version: 0.18
Release: 1%{?dist}
Release: 6%{?dist}
License: GPLv2
Summary: Application tuning GUI & command line utility
Group: Applications/System
@ -9,13 +9,19 @@ URL: https://git.kernel.org/pub/scm/utils/tuna/tuna.git
BuildArch: noarch
BuildRequires: python3-devel, gettext
Requires: python3-ethtool
Requires: python3-linux-procfs >= 0.6
# This really should be a Suggests...
# Requires: python-inet_diag
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
# PATCHES
Patch1: tuna-Replace-python_ethtool-with-builtin-funtionalit.patch
Patch2: tuna-Fix-matching-irqs-in-ps_show_thread.patch
Patch3: tuna-tuna.py-use-fstrings.patch
Patch4: tuna-tuna_gui.py-use-fstrings.patch
Patch5: tuna-tuna-cmd.py-use-fstrings.patch
Patch6: tuna-Adapt-show_threads-cgroup-output-to-terminal-si.patch
Patch7: tuna-Fix-show_threads-cgroup-without-a-term.patch
%description
Provides interface for changing scheduler and IRQ tunables, at whole CPU and at
@ -27,7 +33,7 @@ Can be used as a command line utility without requiring the GUI libraries to be
installed.
%prep
%setup -q
%autosetup -p1
%build
%{__python3} setup.py build
@ -74,6 +80,26 @@ rm -rf %{buildroot}
%{_datadir}/polkit-1/actions/org.tuna.policy
%changelog
* Wed Nov 23 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-6
- Fix show_threads --cgroups without a term
Resolves: rhbz#2121518
* Fri Nov 18 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-5
- Adapt show_threads cgroup output to terminal size
Resolves: rhbz#2121518
* Wed Nov 02 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-4
- Use f-strings in tuna where possible
Resolves: rhbz#2120805
* Mon Oct 03 2022 John Kacur <jkacur@redhat.com> - 0.18-3
- Match irqs with "irqs/"
Resolves: rhbz#2131353
* Fri Sep 30 2022 John Kacur <jkacur@redhat.com> - 0.18-2
- Replace dependency on python-ethtool with built-in functionality
Resolves: rhbz#2123753
* Wed Jun 29 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-1
- Rebase to upstream version 0.18
Resolves: rhbz#2073555