You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
11 KiB

From 876beba81c6b213e0fe4755409142cddb78e344d Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 12 Sep 2017 23:35:39 +0100
Subject: [PATCH 1/2] tuna: Use errno codes instead of numbers
Use errno codes instead of numbers since they
are self documenting.
Simplify the comments as a result
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 12 +++++-----
tuna/tuna.py | 78 ++++++++++++++++++++++++++++++------------------------------
2 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 39666c7c77f1..f0c5c0662ebd 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
-import getopt, ethtool, fnmatch, os, procfs, re, schedutils, sys
+import getopt, ethtool, fnmatch, errno, os, procfs, re, schedutils, sys
from tuna import tuna, sysfs
import gettext
@@ -180,8 +180,8 @@ def ps_show_thread(pid, affect_children, ps,
global irqs
try:
affinity = format_affinity(schedutils.get_affinity(pid))
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
return
raise e
@@ -262,8 +262,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
continue
try:
affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if cpu_list and not set(cpu_list).intersection(set(affinity)):
@@ -558,7 +558,7 @@ def main():
else:
try:
tuna.threads_set_priority(thread_list, a, affect_children)
- except (SystemError, OSError) as err: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
+ except (SystemError, OSError) as err: # old python-schedutils incorrectly raised SystemError
print "tuna: %s" % err
sys.exit(2)
elif o in ("-P", "--show_threads"):
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 9aab16a409d2..562c7fcf92d9 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -1,7 +1,7 @@
# -*- python -*-
# -*- coding: utf-8 -*-
-import copy, ethtool, os, procfs, re, schedutils, sys, shlex
+import copy, ethtool, errno, os, procfs, re, schedutils, sys, shlex
import help, fnmatch
from procfs import utilist
@@ -209,8 +209,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
try:
curr_affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3: # 'No such process'
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
curr_affinity = None
raise e
@@ -218,8 +218,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
schedutils.set_affinity(pid, new_affinity)
curr_affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3: # 'No such process'
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
curr_affinity == None
raise e
@@ -247,16 +247,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
for tid in threads.keys():
try:
curr_affinity = schedutils.get_affinity(tid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) != set(new_affinity):
try:
schedutils.set_affinity(tid, new_affinity)
curr_affinity = schedutils.get_affinity(tid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) == set(new_affinity):
@@ -267,12 +267,12 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
print "move_threads_to_cpu: %s " % \
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
{'pid':pid, 'new_affinity':new_affinity})
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
# process died
continue
- elif e[0] == 22: # (22, EINVAL - unmovable thread)
- print "thread %(pid)d cannot be moved as requested" %{'pid':pid}
+ elif e[0] == errno.EINVAL: # unmovable thread)
+ print >> stderr, "thread %(pid)d cannot be moved as requested" %{'pid':pid}
continue
raise e
return changed
@@ -317,8 +317,8 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False):
pid = int(pid[0])
try:
schedutils.set_affinity(pid, new_affinity)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
unprocessed.append(i)
changed -= 1
continue
@@ -351,8 +351,8 @@ def isolate_cpus(cpus, nr_cpus):
continue
try:
affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)):
@@ -360,8 +360,8 @@ def isolate_cpus(cpus, nr_cpus):
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
schedutils.set_affinity(pid, affinity)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
@@ -373,8 +373,8 @@ def isolate_cpus(cpus, nr_cpus):
continue
try:
affinity = schedutils.get_affinity(tid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)):
@@ -382,8 +382,8 @@ def isolate_cpus(cpus, nr_cpus):
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
schedutils.set_affinity(tid, affinity)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
@@ -419,8 +419,8 @@ def include_cpus(cpus, nr_cpus):
continue
try:
affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -428,8 +428,8 @@ def include_cpus(cpus, nr_cpus):
affinity = list(set(affinity + cpus))
try:
schedutils.set_affinity(pid, affinity)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
@@ -441,8 +441,8 @@ def include_cpus(cpus, nr_cpus):
continue
try:
affinity = schedutils.get_affinity(tid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -450,8 +450,8 @@ def include_cpus(cpus, nr_cpus):
affinity = list(set(affinity + cpus))
try:
schedutils.set_affinity(tid, affinity)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
@@ -518,8 +518,8 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
try:
affinity = schedutils.get_affinity(tid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
return False
raise e
@@ -557,8 +557,8 @@ def threads_set_priority(tids, parm, affect_children = False):
for tid in tids:
try:
thread_set_priority(tid, policy, rtprio)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
if affect_children:
@@ -566,8 +566,8 @@ def threads_set_priority(tids, parm, affect_children = False):
if child != tid:
try:
thread_set_priority(child, policy, rtprio)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
@@ -597,8 +597,8 @@ def get_kthread_sched_tunings(proc = None):
try:
policy = schedutils.get_scheduler(pid)
affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ if e[0] == errno.ESRCH:
continue
raise e
percpu = iskthread(pid) and \
--
2.9.5