[PATCH v2] tuna: Rework exception handling of invalid policy
by Leah Leshchinsky
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.
Additionally, 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_priorty 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(). If no exceptions are raised, a duplicate
call to this function is still unnecessary.
Remove the finally block in tuna.get_policy_and_rtprio() and move the
error handling so that exceptions are handled directly within the
function, rather than in various locations outside the function. Let
tuna.threads_set_priority() return the tuple (policy, rtprio) so that it
may be called in tuna-cmd.py without a seperate prior call to
tuna.get_policy_and_rtprio().
Small fix to differentiate between unsupported policy and invalid policy
or priority.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index cf117ec046ff..88ff626766a0 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -601,13 +601,13 @@ 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)
if not thread_list:
# For backward compatibility
p_waiting_action = True
+ (policy, rtprio) = tuna.get_policy_and_rtprio(a)
else:
try:
- tuna.threads_set_priority(thread_list, a, affect_children)
+ (policy, rtprio) = tuna.threads_set_priority(thread_list, a, affect_children)
except OSError as err:
print("tuna: %s" % err)
sys.exit(2)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 8fb42121e2e4..7b0cc1f3fe30 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -507,21 +507,20 @@ def get_policy_and_rtprio(parm):
rtprio = 0
policy = None
- try:
- cp = tuna_sched.Policy(parms[0])
- except:
- if parms[0].isdigit():
- rtprio = int(parms[0])
- else:
- raise ValueError
+ if parms[0].isdigit():
+ rtprio = int(parms[0])
else:
- policy = cp.get_policy()
- if len(parms) > 1:
- rtprio = int(parms[1])
- elif cp.is_rt():
- rtprio = 1
- finally:
- return(policy, rtprio)
+ try:
+ cp = tuna_sched.Policy(parms[0])
+ policy = cp.get_policy()
+ if len(parms) > 1:
+ rtprio = int(parms[1])
+ elif cp.is_rt():
+ rtprio = 1
+ except ValueError as err:
+ print(err)
+ sys.exit(2)
+ return (policy, rtprio)
def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
@@ -558,11 +557,8 @@ def thread_set_priority(tid, policy, rtprio):
os.sched_setscheduler(tid, policy, param)
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])
- return
+
+ (policy, rtprio) = get_policy_and_rtprio(parm)
for tid in tids:
try:
@@ -580,6 +576,7 @@ def threads_set_priority(tids, parm, affect_children=False):
if err.args[0] == errno.ESRCH:
continue
raise err
+ return (policy, rtprio)
class sched_tunings:
def __init__(self, name, pid, policy, rtprio, affinity, percpu):
diff --git a/tuna/tuna_sched.py b/tuna/tuna_sched.py
index de9846bb5fae..8c13b914d13a 100644
--- a/tuna/tuna_sched.py
+++ b/tuna/tuna_sched.py
@@ -51,12 +51,12 @@ class Policy:
can use fifo, FIFO, sched_fifo, SCHED_FIFO, etc
"""
self.policy = None
- policy = policy.upper()
- if policy[:6] != "SCHED_":
- policy = "SCHED_" + policy
- if policy not in list(Policy.SCHED_POLICIES):
- raise OSError
- self.policy = policy
+ policy_str = policy.upper()
+ if policy_str[:6] != "SCHED_":
+ policy_str = "SCHED_" + policy_str
+ if policy_str not in list(Policy.SCHED_POLICIES):
+ raise ValueError("tuna: " + _("\"%s\" is an unsupported priority value!") % policy)
+ self.policy = policy_str
@classmethod
def num_init(cls, policy):
--
2.27.0
1 year, 10 months
[PATCH] tuna: Rework exception handling of invalid policy
by Leah Leshchinsky
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.
Additionally, 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_priorty 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(). If no exceptions are raised, a duplicate
call to this function is still unnecessary.
Remove the finally block in tuna.get_policy_and_rtprio() and move the
error handling so that exceptions are handled directly within the
function, rather than in various locations outside the function. Let
tuna.threads_set_priority() return the tuple (policy, rtprio) so that it
may be called in tuna-cmd.py without a seperate prior call to
tuna.get_policy_and_rtprio().
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index cf117ec046ff..88ff626766a0 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -601,13 +601,13 @@ 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)
if not thread_list:
# For backward compatibility
p_waiting_action = True
+ (policy, rtprio) = tuna.get_policy_and_rtprio(a)
else:
try:
- tuna.threads_set_priority(thread_list, a, affect_children)
+ (policy, rtprio) = tuna.threads_set_priority(thread_list, a, affect_children)
except OSError as err:
print("tuna: %s" % err)
sys.exit(2)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 8fb42121e2e4..3ca7c5e6abba 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -507,21 +507,21 @@ def get_policy_and_rtprio(parm):
rtprio = 0
policy = None
- try:
- cp = tuna_sched.Policy(parms[0])
- except:
- if parms[0].isdigit():
- rtprio = int(parms[0])
- else:
- raise ValueError
+ if parms[0].isdigit():
+ rtprio = int(parms[0])
else:
- policy = cp.get_policy()
- if len(parms) > 1:
- rtprio = int(parms[1])
- elif cp.is_rt():
- rtprio = 1
- finally:
- return(policy, rtprio)
+ try:
+ cp = tuna_sched.Policy(parms[0])
+ policy = cp.get_policy()
+ if len(parms) > 1:
+ rtprio = int(parms[1])
+ elif cp.is_rt():
+ rtprio = 1
+ except ValueError:
+ print("tuna: " + _("\"%s\" is unsupported priority value!") % parms[0])
+ sys.exit(2)
+
+ return (policy, rtprio)
def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
@@ -558,11 +558,8 @@ def thread_set_priority(tid, policy, rtprio):
os.sched_setscheduler(tid, policy, param)
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])
- return
+
+ (policy, rtprio) = get_policy_and_rtprio(parm)
for tid in tids:
try:
@@ -580,6 +577,7 @@ def threads_set_priority(tids, parm, affect_children=False):
if err.args[0] == errno.ESRCH:
continue
raise err
+ return (policy, rtprio)
class sched_tunings:
def __init__(self, name, pid, policy, rtprio, affinity, percpu):
diff --git a/tuna/tuna_sched.py b/tuna/tuna_sched.py
index de9846bb5fae..426e8c98bc00 100644
--- a/tuna/tuna_sched.py
+++ b/tuna/tuna_sched.py
@@ -55,7 +55,7 @@ class Policy:
if policy[:6] != "SCHED_":
policy = "SCHED_" + policy
if policy not in list(Policy.SCHED_POLICIES):
- raise OSError
+ raise ValueError
self.policy = policy
@classmethod
--
2.27.0
1 year, 10 months
[PATCH] tuna: Fix ModuleNotFoundError
by John Kacur
commit 43b434867514934593ada5aa8ea448ef6a1778f9 fixed the problem with
relative imports but unfortunately created a new problem with installed
tuna
This fixes the original problem and also fixes the ModuleNotFoundError
in an installed (not running from git) version of tuna.
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/tuna.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 98a1725598dd..8fb42121e2e4 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -12,8 +12,8 @@ import platform
import ethtool
import procfs
from procfs import utilist
-import help
-import tuna_sched
+from tuna import help
+from tuna import tuna_sched
try:
fntable
--
2.31.1
1 year, 11 months
[ANNOUNCE] tuna-0.17
by John Kacur
I'm pleased to announce version 0.17 of tuna.
A few highlights.
- more flexible way to specify scheduling policy, fifo, sched_fifo, etc
- fix to display correct cpu affinity when cpus are offlined
- warning if unable to move a pid during isolate that would otherwise be
legal
- many small fixes and clean-ups
Thanks to everyone who contributed
Your bug reports, patches and comments are always welcome
John Kacur
To fetch
Clone
git://git.kernel.org/pub/scm/utils/tuna/tuna.git
https://git.kernel.org/pub/scm/utils/tuna/tuna.git
Branch: main
Tag: v0.17
Tarballs available here
https://mirrors.edge.kernel.org/pub/software/utils/tuna
Older version tarballs are available here
https://mirrors.edge.kernel.org/pub/software/utils/tuna/older
John Kacur (15):
tuna: Specify Gtk version before import to prevent warning
tuna: Change tuna.spec to define version of python
tuna: Replace unnecessary comprehension
tuna: Replace "and or" with ternary
tuna: Use sys.exit instead of exit
tuna: Remove is_s390 from tuna and use the python-linux-procfs
function
tuna: A few simple spelling / grammar fixes in comments
tuna: Improve sysfs.py
tuna: Print warning if setting affinity results in EBUSY and continue
tuna: Don't use relative imports in tuna.py
tuna: Make it clear that include and isolate affects IRQs in help
tuna: Add tags to gitignore
tuna: Fix tuna displays incorrect cpu affinity when cpu is offlined
tuna: Create class Policy and allow users to specify policy in more
formats
tuna: release 0.17
Leah Leshchinsky (3):
tuna: Remove argument requirement for config_file_list option
tuna: Add distinction between --spread and --move to error message
Clean up print statements for readability
tyberry(a)redhat.com (1):
tuna: Spelling fix in tuna-cmd.py Spelling fix in tuna-cmd.py Signed
off-by: Ty Berry <tyberry(a)redhat.com>
.gitignore | 1 +
docs/tuna.8 | 4 +--
rpm/SPECS/tuna.spec | 11 +++-----
setup.py | 2 +-
tuna-cmd.py | 48 +++++++++++++++--------------------
tuna/config.py | 3 +++
tuna/sysfs.py | 48 +++++++++++++++++++++++++++--------
tuna/tuna.py | 42 +++++++++++++++---------------
tuna/tuna_sched.py | 62 +++++++++++++++++++++++++++++++++++++++++++--
9 files changed, 151 insertions(+), 70 deletions(-)
--
2.31.1
1 year, 11 months
[PATCH] tuna: Create class Policy and allow users to specify policy in more formats
by John Kacur
When users change the priority of a thread, allow them to use various
formats. For example, SCHED_FIFO can be indicated as
SCHED_FIFO, sched_fifo, FIFO or fifo
Create class Policy for this purpose.
The utility functions sched_fromstr and sched_str are left in place for
backwards compatibility and for when a full class is not necessary.
There are certain advantages to using the class though.
- The ability to specify a policy using more formats.
- Functionality such as is_rt() which returns True if a policy is
realtime
- more readable code
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna/tuna.py | 21 ++++++++++------
tuna/tuna_sched.py | 62 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 73 insertions(+), 10 deletions(-)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 6b6edcc8ff72..98a1725598dd 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -506,17 +506,22 @@ def get_policy_and_rtprio(parm):
parms = parm.split(":")
rtprio = 0
policy = None
- if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR"]:
- policy = tuna_sched.sched_fromstr("SCHED_%s" % parms[0].upper())
+
+ try:
+ cp = tuna_sched.Policy(parms[0])
+ except:
+ if parms[0].isdigit():
+ rtprio = int(parms[0])
+ else:
+ raise ValueError
+ else:
+ policy = cp.get_policy()
if len(parms) > 1:
rtprio = int(parms[1])
- elif parms[0].upper() in ["FIFO", "RR"]:
+ elif cp.is_rt():
rtprio = 1
- elif parms[0].isdigit():
- rtprio = int(parms[0])
- else:
- raise ValueError
- return (policy, rtprio)
+ finally:
+ return(policy, rtprio)
def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
diff --git a/tuna/tuna_sched.py b/tuna/tuna_sched.py
index fee5f166b004..de9846bb5fae 100644
--- a/tuna/tuna_sched.py
+++ b/tuna/tuna_sched.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+# Copyright (C) 2022 John Kacur
"""
Functions to translate a scheduling policy into either a string name or an
equivalent integer
@@ -13,12 +15,13 @@ SCHED_POLICIES = {
"SCHED_DEADLINE": 6
}
+
def sched_fromstr(policy):
""" Given a policy as a string, return the equivalent integer """
try:
return SCHED_POLICIES[policy]
- except:
- raise OSError()
+ except KeyError as exc:
+ raise OSError('No such policy') from exc
def sched_str(policy):
@@ -27,3 +30,58 @@ def sched_str(policy):
if pnum == policy:
return pstr
return "UNKNOWN"
+
+class Policy:
+ """ class to encapsulate some scheduling policies operations """
+
+ SCHED_POLICIES = {
+ "SCHED_OTHER": os.SCHED_OTHER,
+ "SCHED_FIFO": os.SCHED_FIFO,
+ "SCHED_RR": os.SCHED_RR,
+ "SCHED_BATCH": os.SCHED_BATCH,
+ "SCHED_IDLE": os.SCHED_IDLE,
+ "SCHED_DEADLINE": 6
+ }
+
+ RT_POLICIES = ["SCHED_FIFO", "SCHED_RR"]
+
+ def __init__(self, policy):
+ """
+ init the class given a policy as a string
+ can use fifo, FIFO, sched_fifo, SCHED_FIFO, etc
+ """
+ self.policy = None
+ policy = policy.upper()
+ if policy[:6] != "SCHED_":
+ policy = "SCHED_" + policy
+ if policy not in list(Policy.SCHED_POLICIES):
+ raise OSError
+ self.policy = policy
+
+ @classmethod
+ def num_init(cls, policy):
+ """ init the class with an integer corresponding to the policy """
+ for pstr, pnum in cls.SCHED_POLICIES.items():
+ if policy == pnum:
+ return cls(pstr)
+ return cls("UNKNOWN")
+
+ def __str__(self):
+ """ return the policy in string format """
+ return self.policy
+
+ def get_sched(self):
+ """ return the policy in string format """
+ return self.policy
+
+ def get_short_str(self):
+ """ return the policy in string format, without the SCHED_ part """
+ return self.policy[6:]
+
+ def get_policy(self):
+ """ return the integer equivlent of the policy """
+ return SCHED_POLICIES[self.policy]
+
+ def is_rt(self):
+ """ Return True if policy is a realtime policy """
+ return self.policy in Policy.RT_POLICIES
--
2.31.1
1 year, 11 months
[PATCH v3] Clean up print statements for readability
by Leah Leshchinsky
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)
--
2.27.0
1 year, 11 months
[PATCH v2] Clean up print statements for readability
by Leah Leshchinsky
Condense various conditionals in print statements into a single line
to improve readability. Additionally, remove unused header_printed
variable.
Small fix, print_header changed to header_printed.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
tuna-cmd.py | 28 +++++++++-------------------
1 file changed, 9 insertions(+), 19 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 7e33a128d676..e5d24ff84077 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -156,14 +156,10 @@ 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):
- header_printed = False
dirname = "/proc/%s/fd" % pid
try:
filenames = os.listdir(dirname)
@@ -182,12 +178,10 @@ def ps_show_sockets(pid, ps, inodes, inode_re, indent=0):
inode = int(inode_match.group(1))
if inode not in inodes:
continue
- if not header_printed:
- print("%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" %
- (sindent, "State", "Recv-Q", "Send-Q",
- "Local Address", "Port",
- "Peer Address", "Port"))
- header_printed = True
+ print("%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" %
+ (sindent, "State", "Recv-Q", "Send-Q",
+ "Local Address", "Port",
+ "Peer Address", "Port"))
s = inodes[inode]
print("%s%-10s %-6d %-6d %15s:%-5d %15s:%-5d" %
(sindent, s.state(),
@@ -203,7 +197,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 +239,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)
--
2.27.0
1 year, 11 months
[PATCH] Clean up print statements for readability
by Leah Leshchinsky
Condense various conditionals in print statements into a single line
to improve readability. Additionally, remove unused print_header
variable.
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
---
tuna-cmd.py | 28 +++++++++-------------------
1 file changed, 9 insertions(+), 19 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 7e33a128d676..e5d24ff84077 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -156,14 +156,10 @@ 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):
- header_printed = False
dirname = "/proc/%s/fd" % pid
try:
filenames = os.listdir(dirname)
@@ -182,12 +178,10 @@ def ps_show_sockets(pid, ps, inodes, inode_re, indent=0):
inode = int(inode_match.group(1))
if inode not in inodes:
continue
- if not header_printed:
- print("%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" %
- (sindent, "State", "Recv-Q", "Send-Q",
- "Local Address", "Port",
- "Peer Address", "Port"))
- header_printed = True
+ print("%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" %
+ (sindent, "State", "Recv-Q", "Send-Q",
+ "Local Address", "Port",
+ "Peer Address", "Port"))
s = inodes[inode]
print("%s%-10s %-6d %-6d %15s:%-5d %15s:%-5d" %
(sindent, s.state(),
@@ -203,7 +197,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 +239,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)
--
2.27.0
1 year, 11 months