On Tue, 4 Jan 2022, Leah Leshchinsky wrote:
Condense various conditionals in print statements into a single line
to improve readability.
Small fix, remove header_printed section.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
tuna-cmd.py | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 7e33a128d676..ccd7036093d9 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -156,10 +156,7 @@ def ps_show_header(has_ctxt_switch_info, cgroups=False):
has_ctxt_switch_info and " %9s %12s" %
(
"voluntary",
"nonvoluntary")
or "", "cmd"), end='
')
- if cgroups:
- print(" %7s" % ("cgroup"))
- else:
- print("")
+ print(" %7s" % ("cgroup") if cgroups else "")
def ps_show_sockets(pid, ps, inodes, inode_re, indent=0):
@@ -203,7 +200,6 @@ def format_affinity(affinity):
ncpus = os.sysconf('SC_NPROCESSORS_CONF')
return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, ncpus))
-
def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
sock_inode_re, cgroups):
global irqs
@@ -246,15 +242,12 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info,
sock_inodes,
ctxt_switch_info = " %9d %12s" % (voluntary_ctxt_switches,
nonvoluntary_ctxt_switches)
- if affect_children:
- print(" %-5d " % pid, end=' ')
- else:
- print(" %-5d" % pid, end=' ')
+ # 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=' ')
- if cgroups:
- print(" %9s" % cgout, end=' ')
- print("")
+ print(" %9s" % cgout if cgroups else "")
+
if sock_inodes:
ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
affect_children and 3 or 4)
--
Signed-off-by: John Kacur <jkacur(a)redhat.com>