Due to CLI redesign, only a single command can be executed at a time.
Therefore, multiple functions and variables that supported multiaction
command line arguments are no longer used or necessary.
- Remove global variable update in get_nr_cpus()
- Remove global ps variable from thread_help()
- Remove global ps variable from thread_help()
- Remove global irqs variable from ps_show_thread()
- Remove get_nics() function and global nics variable
- Remove "too many globals" comment
- Remove unused functions do_list_op() and pick_op()
Signed-off-by: Leah Leshchinsky <lleshchi(a)redhat.com>
diff --git a/tuna-cmd.py b/tuna-cmd.py
index dd99afbcd9db..648742d32a7b 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -37,12 +37,7 @@ try:
except:
have_inet_diag = False
-
-# FIXME: ETOOMANYGLOBALS, we need a class!
-
-nr_cpus = None
ps = None
-irqs = None
class HelpMessageParser(argparse.ArgumentParser):
def error(self, message):
@@ -169,30 +164,11 @@ def gen_parser():
return parser
-
def get_nr_cpus():
- """ Get all cpus including disabled cpus """
- global nr_cpus
- if nr_cpus:
- return nr_cpus
- nr_cpus = os.sysconf('SC_NPROCESSORS_CONF')
- return nr_cpus
-
-nics = None
-
-
-def get_nics():
- global nics
- if nics:
- return nics
- nics = ethtool.get_active_devices()
- return nics
-
+ return os.sysconf('SC_NPROCESSORS_CONF')
def thread_help(tid):
- global ps
- if not ps:
- ps = procfs.pidstats()
+ ps = procfs.pidstats()
if tid not in ps:
print("tuna: " + _("thread %d doesn't exists!") % tid)
@@ -266,7 +242,6 @@ def format_affinity(affinity):
def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
sock_inode_re, cgroups):
- global irqs
try:
affinity = format_affinity(os.sched_getaffinity(pid))
except OSError as e:
@@ -281,18 +256,18 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info,
sock_inodes,
users = ""
if tuna.is_irq_thread(cmd):
try:
- if not irqs:
- irqs = procfs.interrupts()
+ irqs = procfs.interrupts()
+ nics = ethtool.get_active_devices()
if cmd[:4] == "IRQ-":
users = irqs[tuna.irq_thread_number(cmd)]["users"]
for u in users:
- if u in get_nics():
+ if u in nics:
users[users.index(u)] = "%s(%s)" % (
u, ethtool.get_module(u))
users = ",".join(users)
else:
u = cmd[cmd.find('-') + 1:]
- if u in get_nics():
+ if u in nics:
users = ethtool.get_module(u)
except:
users = "Not found in /proc/interrupts!"
@@ -408,7 +383,7 @@ def do_ps(thread_list, cpu_list, irq_list, show_uthreads,
show_kthreads,
def find_drivers_by_users(users):
- nics = get_nics()
+ nics = ethtool.get_active_devices()
drivers = []
for u in users:
try:
@@ -453,15 +428,6 @@ def show_irqs(irq_list, cpu_list):
print(" %s" % ",".join(drivers) if drivers else
"")
-def do_list_op(op, current_list, op_list):
- if not current_list:
- current_list = []
- if op == '+':
- return list(set(current_list + op_list))
- if op == '-':
- return list(set(current_list) - set(op_list))
- return list(set(op_list))
-
def threadstring_to_list(threadstr):
global ps
thread_list = []
@@ -492,13 +458,6 @@ def irqstring_to_list(irqstr):
irq_list += [int(i) for i in irq_list_str if i.isdigit()]
return irq_list
-def pick_op(argument):
- if argument == "":
- return (None, argument)
- if argument[0] in ('+', '-'):
- return (argument[0], argument[1:])
- return (None, argument)
-
def i18n_init():
(app, localedir) = ('tuna', '/usr/share/locale')
--
2.27.0