[PATCH v2] tuna: Adapt show_threads cgroup output to terminal size
by Leah Leshchinsky
Passing the --cgroup flag to 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 with spacing in
between thread outputs.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
Target branch: main
Pull from: https://gitlab.com/lleshchi/tuna
Branch: main_format
Commit: 4236d757e1fda22086c619229cc7cfc2fb1f68c5
diff --git a/docs/tuna.8 b/docs/tuna.8
index f50a8c2a0a16..242389455f83 100644
--- a/docs/tuna.8
+++ b/docs/tuna.8
@@ -188,6 +188,7 @@ optional arguments:
Operation will affect children threads
-G, --cgroups Display the processes with the type of cgroups they
are in
+ -z, --spaced Display spaced view for cgroups
.TP
\fBtuna show_irqs\fR
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8be35f7fb4c4..630c8bc60deb 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -114,6 +114,7 @@ def gen_parser():
"sockets": dict(dest='cpu_list', default=[], metavar='CPU-SOCKET-LIST', type=socketstring_to_list, help="CPU-SOCKET-LIST affected by commands"),
"show_sockets": dict(action='store_true', help='Show network sockets in use by threads'),
"cgroups": dict(action='store_true', dest='cgroups', help='Display the processes with the type of cgroups they are in'),
+ "spaced": dict(action='store_false', dest='compact', help='Display spaced view for cgroups'),
"affect_children": dict(action='store_true', help="Operation will affect children threads"),
"nohz_full": dict(action='store_true', help="CPUs in nohz_full kernel command line will be affected by operations"),
"no_uthreads": dict(action='store_false', dest='uthreads', help="Operations will not affect user threads"),
@@ -215,6 +216,7 @@ def gen_parser():
if have_inet_diag:
show_threads.add_argument('-n', '--show_sockets', **MODS['show_sockets'])
show_threads.add_argument('-G', '--cgroups', **MODS['cgroups'])
+ show_threads.add_argument('-z', '--spaced', **MODS['spaced'])
show_irqs_group = show_irqs.add_mutually_exclusive_group(required=False)
@@ -335,7 +337,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))
@@ -372,10 +374,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,
@@ -384,12 +396,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()):
@@ -426,9 +438,15 @@ 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):
@@ -449,7 +467,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()
@@ -466,7 +484,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
@@ -698,7 +716,7 @@ def main():
elif args.command in ['show_threads']:
do_ps(args.thread_list, args.cpu_list, args.irq_list, args.uthreads,
- args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups)
+ args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups, args.compact)
elif args.command in ['show_irqs']:
show_irqs(args.irq_list, args.cpu_list)
--
2.31.1
1 year, 5 months
[PATCH v2] tuna: Adapt show_threads cgroup output to terminal size
by Leah Leshchinsky
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(a)redhat.com>
---
Target branch: getopt
Pull from: https://gitlab.com/lleshchi/tuna
Branch: getopt_format
Commit: 9dfaafe278f6cccf6911cddef413dc59e87722e7
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/docs/tuna.8 b/docs/tuna.8
index 3a065562b00e..218ba141c8c4 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 75b63da972c2..54dc567300f2 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.31.1
1 year, 5 months
[PATCH] tuna: Adapt show_threads cgroup output to terminal size
by Leah Leshchinsky
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
--compact flag to --show_threads to print cgroups without a new line in
between thread outputs.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
target branch: getopt
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/docs/tuna.8 b/docs/tuna.8
index 3a065562b00e..6124108fc4f4 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\-\-compact\fR
+Display compact 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 75b63da972c2..1f34bfb058fe 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, --compact',
+ "Display compact 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=False):
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", "compact", "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 = False
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", "--compact"):
+ compact = True
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.31.1
1 year, 5 months
[PATCH] tuna: Adapt show_threads cgroup output to terminal size
by Leah Leshchinsky
Passing the --cgroup flag to 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
--compact flag to show_threads to print cgroups without a new line in
between thread outputs.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
target branch: main
diff --git a/docs/tuna.8 b/docs/tuna.8
index f50a8c2a0a16..8bfd4af90d66 100644
--- a/docs/tuna.8
+++ b/docs/tuna.8
@@ -188,6 +188,7 @@ optional arguments:
Operation will affect children threads
-G, --cgroups Display the processes with the type of cgroups they
are in
+ --compact Display compact view for cgroups
.TP
\fBtuna show_irqs\fR
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8be35f7fb4c4..5563c823d9b0 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -114,6 +114,7 @@ def gen_parser():
"sockets": dict(dest='cpu_list', default=[], metavar='CPU-SOCKET-LIST', type=socketstring_to_list, help="CPU-SOCKET-LIST affected by commands"),
"show_sockets": dict(action='store_true', help='Show network sockets in use by threads'),
"cgroups": dict(action='store_true', dest='cgroups', help='Display the processes with the type of cgroups they are in'),
+ "compact": dict(action='store_true', dest='compact', help='Display compact view for cgroups'),
"affect_children": dict(action='store_true', help="Operation will affect children threads"),
"nohz_full": dict(action='store_true', help="CPUs in nohz_full kernel command line will be affected by operations"),
"no_uthreads": dict(action='store_false', dest='uthreads', help="Operations will not affect user threads"),
@@ -215,6 +216,7 @@ def gen_parser():
if have_inet_diag:
show_threads.add_argument('-n', '--show_sockets', **MODS['show_sockets'])
show_threads.add_argument('-G', '--cgroups', **MODS['cgroups'])
+ show_threads.add_argument('--compact', **MODS['compact'])
show_irqs_group = show_irqs.add_mutually_exclusive_group(required=False)
@@ -335,7 +337,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=False):
global irqs
try:
affinity = format_affinity(os.sched_getaffinity(pid))
@@ -372,10 +374,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,
@@ -384,12 +396,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()):
@@ -426,9 +438,15 @@ 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):
@@ -449,7 +467,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()
@@ -466,7 +484,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
@@ -698,7 +716,7 @@ def main():
elif args.command in ['show_threads']:
do_ps(args.thread_list, args.cpu_list, args.irq_list, args.uthreads,
- args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups)
+ args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups, args.compact)
elif args.command in ['show_irqs']:
show_irqs(args.irq_list, args.cpu_list)
--
2.31.1
1 year, 5 months
[PATCH] tuna: Update manpages for argparse CLI changes
by Leah Leshchinsky
Due to the introduction a new commandline interface, the tuna manpages
need to be updated.
Update with new command line options.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
target branch: main
Pull from https://gitlab.com/lleshchi/tuna
diff --git a/docs/tuna.8 b/docs/tuna.8
index 3a065562b00e..2fd3e7fa452f 100644
--- a/docs/tuna.8
+++ b/docs/tuna.8
@@ -9,100 +9,257 @@ This manual page explains the \fBtuna\fR program. The program can be used to cha
.PP
\fBtuna\fP can change scheduling policy, scheduler priority and processor affinity for processes and process threads. \fBtuna\fR can also change the processor affinity for interrupts.
When \fBtuna\fR is invoked without any options it starts up in its graphical interface mode. This manual page explains only the command\-line options for \fBtuna\fR
-.SH "OPTIONS"
-\fBtuna\fR has both \fIaction\fR options and \fImodifier\fR options. Modifier options must be specified on the command\-line before the actions they are intended to modify. Any modifier option applies to following actions on the same command-line until it is over-ridden.
-.IP \fIActions\fR
+.SH "GLOBAL OPTIONS"
.TP
\fB\-h\fR, \fB\-\-help\fR
Print a list of options. \fBtuna\fR will exit after this action, ignoring the remainder of the command-line.
.TP
-\fB\-g\fR, \fB\-\-gui\fR
-Start the GUI. Actions that follow this on the command-line will be processed without waiting for the GUI to complete.
-.TP
-\fB\-a\fR, \fB\-\-config_file_apply=profilename\fR
-Apply changes described in profile
-.TP
-\fB\-l\fR, \fB\-\-config_file_list\fR
-List preloaded profiles
-.TP
-\fB\-i\fR, \fB\-\-isolate\fR
-Move all allowed threads and IRQs away from CPU\-LIST. Requires \fB\-c\fR or \fB-S\fR.
-.TP
-\fB\-I\fR, \fB\-\-include\fR
-Allow all allowed threads and IRQs to run on CPU\-LIST. Requires \fB\-c\fR or \fB-S\fR.
-.TP
-\fB\-m\fR, \fB\-\-move\fR
-Move selected entities to CPU\-LIST. Requires \fB\-c\fR and either \fB-t\fR or \fB-q\fR.
-.TP
-\fB\-p\fR, \fB\-\-priority\fR=\fI[POLICY:]\fRRTPRIO
-Set thread scheduler tunables: POLICY and RTPRIO. POLICY is one of OTHER, FIFO, RR, or BATCH. If \fB\-t\fR is not set, \fB\-p\fR will act as a Modifier saving the sched tunables for future Actions, for example \fB\-r\fR.
-.TP
-\fB\-P\fR, \fB\-\-show_threads\fR
-Show thread list.
-.TP
-\fB\-Q\fR, \fB\-\-show_irqs\fR
-Show IRQ list.
-.TP
-\fB\-r\fR, \fB\-\-run\fR=\fI"COMMAND"\fR
-Run the COMMAND. If arguments are passed, the entire command line must be provided inside "quotes". Modifiers \fB-c\fR and \fB-p\fR can be used to set the affinity and scheduler tunables of the given COMMAND. The arg[0] (i.e. the command) will be set in THREAD\-LIST. Likewise the \fB-t\fR, the COMMAND accepts the prefix \fB+\fR and \fB-\fR as wildcards in order to be appended or removed from THREAD\-LIST, respectively.
-.TP
-\fB\-R\fR, \fB\-\-refresh\fR=\fIMSEC\fR
-Refresh the GUI every MSEC milliseconds
-.TP
-\fB\-s\fR, \fB\-\-save\fR=\fIFILENAME\fR
-Save kthreads sched tunables to FILENAME.
-.TP
\fB\-v\fR, \fB\-\-version\fR
Show version
.TP
-\fB\-W\fR, \fB\-\-what_is\fR
-Provides help about selected entities. Requires \fB-t\fR.
+\fB\-L\fR, \fB\-\-logging\fR=\fILOG-LEVEL\fR
+Log application details to file for given LOG-LEVEL
+.TP
+\fB\-D\fR, \fB\-\-debug\fR
+Print DEBUG level logging details to console
+.SH "COMMANDS"
.TP
-\fB\-x\fR, \fB\-\-spread\fR
-Spread selected entities over CPU\-LIST. Requires at least one of \fB-t\fR or \fB-q\fR. The specified threads and IRQs are each assigned to one cpu in CPU\-LIST.
-.IP \fIModifiers\fR
+\fBtuna isolate\fR
+usage: tuna-cmd.py isolate [-h] (-c CPU-LIST | -S CPU-SOCKET-LIST | -N)
+
+Move all allowed threads and IRQs away from CPU\-LIST. Requires \fB\-c\fR, \fB-S\fR, or \fB-N\fR.
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
.TP
-\fB\-c\fR, \fB\-\-cpus\fR=\fICPU\-LIST\fR
-CPU\-LIST affected by commands. Requires a CPU number or a comma-separated list of CPU numbers.
+\fBtuna include\fR
+usage: tuna-cmd.py include [-h] (-c CPU-LIST | -S CPU-SOCKET-LIST | -N)
+
+Allow all allowed threads and IRQs to run on CPU\-LIST. Requires \fB\-c\fR, \fB-S\fR, or \fB-N\fR.
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
.TP
-\fB\-C\fR, \fB\-\-affect_children\fR
-Operation will affect children threads.
+\fBtuna move\fR
+usage: tuna-cmd.py move [-h] (-c CPU-LIST | -S CPU-SOCKET-LIST | -N)
+ [-t THREAD-LIST] [-q IRQ-LIST]
+
+Move selected entities to CPU\-LIST. Requires \fB\-c\fR, \fB-S\fR, or \fB-N\fR and \fB-t\fR or \fB-q\fR.
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -t THREAD-LIST, --threads THREAD-LIST
+ THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
+ -q IRQ-LIST, --irqs IRQ-LIST
+ IRQ-LIST affect by commands
.TP
-\fB\-d\fR, \fB\-\-disable_perf\fR
-Explicitly disable usage of perf in GUI for process view
+\fBtuna spread\fR
+usage: tuna-cmd.py spread [-h] (-c CPU-LIST | -S CPU-SOCKET-LIST | -N)
+ [-t THREAD-LIST] [-q IRQ-LIST]
+
+Spread selected entities over CPU-LIST. The specified threads and IRQs are each assigned to one cpu in CPU-LIST. Requires \fB\-c\fR, \fB-S\fR, or \fB-N\fR and \fB-t\fR or \fB-q\fR.
+
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -t THREAD-LIST, --threads THREAD-LIST
+ THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
+ -q IRQ-LIST, --irqs IRQ-LIST
+ IRQ-LIST affect by commands
.TP
-\fB\-D\fR, \fB\-\-debug\fR
-Print DEBUG level logging details to console.
+
+\fBtuna priority\fR
+usage: tuna-cmd.py priority [-h] -t THREAD-LIST [-C] POLICY:RTPRIO
+
+Set thread scheduler tunables: POLICY and RTPRIO. POLICY is one of OTHER, FIFO, RR, or BATCH. Provide POLICY, RTPRIO, or POLICY:RTPRIO seperated by ":". If only POLICY is set, the RT priority will default to 1 if the policy is RT, and 0 otherwise. If only RTPRIO is specified, policy will not be changed.
+
+positional arguments:
+ POLICY:RTPRIO Set thread scheduler tunables: POLICY and RTPRIO
+
+optional arguments:
+ -h, --help show this help message and exit
+ -t THREAD-LIST, --threads THREAD-LIST
+ THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
+ -C, --affect_children
+ Operation will affect children threads
.TP
-\fB\-f\fR, \fB\-\-filter\fR
-Disable display of selected CPUs in \fB--gui\fR. Requires \fB-c\R.
+\fBtuna run\fR
+usage: tuna-cmd.py run [-h] [-c CPU-LIST | -S CPU-SOCKET-LIST | -N]
+ [-p PRIORITY] [-b]
+ COMMAND
+
+Run the COMMAND. The entire command line must be provided inside "quotes". Modifiers \fB-c\fR, \fB-S\fR and \fB-p\fR can be used to set the affinity and scheduler tunables of the given COMMAND.
+
+positional arguments:
+ COMMAND fork a new process and run the "COMMAND"
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -p PRIORITY, --priority PRIORITY
+ Set thread scheduler tunables: POLICY and RTPRIO
+ -b, --background Run command as background task
+
.TP
-\fB\-G\fR, \fB\-\-cgroup\fR
-Display the processes with the type of cgroups they are in. Requires \fB-P\R.
+\fBtuna save\fR
+usage: tuna-cmd.py save [-h] [-c CPU-LIST | -S CPU-SOCKET-LIST | -N]
+ [-t THREAD-LIST]
+ FILENAME
+
+Save kthreads sched tunables to FILENAME
+
+positional arguments:
+ FILENAME Save kthreads sched tunables to this file
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -t THREAD-LIST, --threads THREAD-LIST
+ THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
.TP
-\fB\-K\fR, \fB\-\-no_kthreads\fR
-Operations will not affect kernel threads.
+\fBtuna apply\fR
+usage: tuna-cmd.py apply [-h] profilename
+
+Apply changes described in profile
+
+positional arguments:
+ profilename Apply changes described in this file
+
+optional arguments:
+ -h, --help show this help message and exit
+
.TP
-\fB\-L\fR, \fB\-\-logging\fR=\fILOG\-LEVEL\fR
-Log application details to log file for given LOG-LEVEL
+\fBtuna show_threads\fR
+usage: tuna-cmd.py show_threads [-h] [-c CPU-LIST | -N | -S CPU-SOCKET-LIST]
+ [-t THREAD-LIST | -q IRQ-LIST] [-U] [-K] [-C]
+ [-G]
+
+Show thread list
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -t THREAD-LIST, --threads THREAD-LIST
+ THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
+ -q IRQ-LIST, --irqs IRQ-LIST
+ IRQ-LIST affect by commands
+ -U, --no_uthreads Operations will not affect user threads
+ -K, --no_kthreads Operations will not affect kernel threads
+ -C, --affect_children
+ Operation will affect children threads
+ -G, --cgroups Display the processes with the type of cgroups they
+ are in
+
.TP
-\fB\-N\fR, \fB\-\-nohz_full\fR
-CPUs in nohz_full= kernel command line parameter will be affected by operations
+\fBtuna show_irqs\fR
+usage: tuna-cmd.py show_irqs [-h] [-c CPU-LIST | -N | -S CPU-SOCKET-LIST]
+ [-q IRQ-LIST]
+
+Show IRQ list
+
+optional arguments:
+ -h, --help show this help message and exit
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -q IRQ-LIST, --irqs IRQ-LIST
+ IRQ-LIST affect by commands
+
.TP
-\fB\-q\fR, \fB\-\-irqs\fR=\fIIRQ\-LIST\fR
-IRQ\-LIST affected by commands. Requires an IRQ number or a comma-separated list of IRQ numbers.
+\fBtuna show_configs\fR
+usage: tuna-cmd.py show_configs [-h]
+
+List preloaded profiles
+
+optional arguments:
+ -h, --help show this help message and exit
+
.TP
-\fB\-S\fR, \fB\-\-sockets\fR=\fICPU\-SOCKET\-LIST\fR
-CPU\-SOCKET\-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+\fB tuna what_is\fR
+usage: tuna-cmd.py what_is [-h] THREAD-LIST
+
+Provides help about selected entities
+
+positional arguments:
+ THREAD-LIST THREAD-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications.
+
+
+optional arguments:
+ -h, --help show this help message and exit
.TP
-\fB\-t\fR, \fB\-\-threads\fR=\fITHREAD\-LIST\fR
-THREAD\-LIST affected by commands. Requires a thread number or thread name, or a comma-separated list of thread numbers and/or names. Thread names may contain wildcards. Be sure to quote or escape any wildcard specifications. If only \fB-\fR is passed as argument, the THREAD\-LIST will be cleared.
+\fB tuna gui\fR
+usage: tuna-cmd.py gui [-h] [-d] [-R MSEC]
+ [-c CPU-LIST | -N | -S CPU-SOCKET-LIST] [-U] [-K]
+
+Start the GUI
+
+optional arguments:
+ -h, --help show this help message and exit
+ -d, --disable_perf Explicitly disable usage of perf in GUI for process
+ view
+ -R MSEC, --refresh MSEC
+ Refresh the GUI every MSEC milliseconds
+ -c CPU-LIST, --cpus CPU-LIST
+ CPU-LIST affected by commands. Requires a CPU number, a range, or a comma-separated list of CPU numbers.
+ -N, --nohz_full CPUs in nohz_full kernel command line will be affected
+ by operations
+ -S CPU-SOCKET-LIST, --sockets CPU-SOCKET-LIST
+ CPU-SOCKET-LIST affected by commands. Requires a socket number or a comma-separated list of socket numbers.
+ -U, --no_uthreads Operations will not affect user threads
+ -K, --no_kthreads Operations will not affect kernel threads
.TP
-\fB\-U\fR, \fB\-\-no_uthreads\fR
-Operations will not affect user threads.
.SH USAGE EXAMPLES
If for instance the Ethernet NICs have multiple queues for both receive and transmit, each with its own IRQ, the Ethernet IRQs can be associated with a CPU socket:
.TP
-.B tuna -S 2 -i -q 'eth*' -x
+.B tuna isolate -S 2
+.TP
+.B tuna spread -q 'eth*' -S 2
Move everything off the CPUs in socket 2, then spread the IRQs for the Ethernet devices across those same CPUs.
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 4ac01f4f4522..8be35f7fb4c4 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -101,7 +101,7 @@ def gen_parser():
"filename": dict(metavar='FILENAME', type=str, help="Save kthreads sched tunables to this file"),
"profilename": dict(type=str, help="Apply changes described in this file"),
"run_command": dict(metavar='COMMAND', type=str, help="fork a new process and run the \"COMMAND\""),
- "priority": dict(type=tuna.get_policy_and_rtprio, help="policy/priority help"),
+ "priority": dict(type=tuna.get_policy_and_rtprio, metavar="POLICY:RTPRIO", help="Set thread scheduler tunables: POLICY and RTPRIO"),
}
MODS = {
@@ -120,7 +120,7 @@ def gen_parser():
"no_kthreads": dict(action='store_false', dest='kthreads', help="Operations will not affect kernel threads"),
"disable_perf": dict(action='store_true', help="Explicitly disable usage of perf in GUI for process view"),
"refresh": dict(default=2500, metavar='MSEC', type=int, help="Refresh the GUI every MSEC milliseconds"),
- "priority": dict(default=(None, None), type=tuna.get_policy_and_rtprio, help="Set thread scheduler tunables: POLICY and RTPRIO"),
+ "priority": dict(default=(None, None), metavar="POLICY:RTPRIO", type=tuna.get_policy_and_rtprio, help="Set thread scheduler tunables: POLICY and RTPRIO"),
"background": dict(action='store_true', help="Run command as background task")
}
--
2.31.1
1 year, 6 months
[PATCH] tuna: remove import and fix help message
by Leah Leshchinsky
Remove getopt import and fix help message for 'spread' command.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 44d9faaf15fb..4ac01f4f4522 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -21,7 +21,6 @@ import os
import sys
import errno
import re
-import getopt
import fnmatch
import gettext
import locale
@@ -140,7 +139,7 @@ def gen_parser():
help="Allow all threads to run on CPU-LIST")
move = subparser.add_parser('move', description="Move selected entities to CPU-LIST",
help="Move selected entities to CPU-LIST")
- spread = subparser.add_parser('spread', description="Move selected entities to CPU-LIST",
+ spread = subparser.add_parser('spread', description="Spread selected entities to CPU-LIST",
help="Spread selected entities over CPU-LIST")
priority = subparser.add_parser('priority', description="Set thread scheduler tunables: POLICY and RTPRIO",
help="Set thread scheduler tunables: POLICY and RTPRIO")
--
2.31.1
1 year, 6 months
[PATCH] tuna: tuna-cmd.py use fstrings
by Leah Leshchinsky
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(a)redhat.com>
---
target branch: getopt
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
1 year, 6 months
[PATCH 0/2] tuna: use fstrings
by Leah Leshchinsky
fstring changes targeted for getopt branch
Leah Leshchinsky (2):
tuna: tuna_gui.py use fstrings
tuna: tuna.py use fstrings
tuna/tuna.py | 20 ++++++++++----------
tuna/tuna_gui.py | 2 +-
2 files changed, 11 insertions(+), 11 deletions(-)
--
2.31.1
1 year, 6 months
[PATCH v2] tuna: tuna.py use fstrings
by Leah Leshchinsky
Add fstrings where possible to improve readabilty
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
Fixed pathname = f"/proc/irq/{filename}"
target branch: getopt
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
1 year, 6 months