[PATCH 00/36] [ANNOUNCE] tuna-0.15
by John Kacur
tuna-0.15 is now available. In git the tag is v0.15
There were a lot of clean-ups to format the code in a manner consistent
with python3 standards.
There were also a lot changes to move the gui from gtk2 to gtk3
The gui is still not working correctly, but we are a lot closer than we
used to be. patches here would be much appreciated.
The final major change was to use the built-in schedutils support in
python-3.3 and up and to get rid of our depenency on python-schedutils.
To work with tuna git
Clone one of
git://git.kernel.org/pub/scm/utils/tuna/tuna.git
https://git.kernel.org/pub/scm/utils/tuna/tuna.git
https://kernel.googlesource.com/pub/scm/utils/tuna/tuna.git
and work in the master branch
To fetch the tarball:
https://www.kernel.org/pub/software/utils/tuna/tuna-0.15.tar.xz
Older versions are here:
https://www.kernel.kernel.org/pub/software/utils/tuna/older/
Enjoy!
John Kacur (36):
tuna_gui.py: Reformat the file, style fix-ups
tuna_gui.glade: Initial changes to upgrade glade file for gtk3
tuna_gui.py: gtk2 to gtk3 changes
tuna: gui changes for gtk2 to gtk3
tuna: More changes to header files in tuna/gui for gtk3
tuna: add to gitignore and create gitattributes
tuna: modernize the spacing in irqview
tuna: Remove old glade imports from tuna_gui.py
tuna_gui.py: Fix inconsistent spacing from in tuna_gui.py
tuna: cpuview.py - Modernize the spacing
tuna: cpuview.py: A few more style improvements
irqview: fix bad spacing
tuna: procview.py: Update the spacing and style
tuna: commonview.py: Update the spacing and style
tuna: procview.py: Update spacing and style
tuna: util.py: Update the spacing and fix some style problems
tuna-cmd: Update the spacing and style for tuna-cmd
tuna: tuna-cmd:py: Convert type comparison to isinstance
tuna: config.py: Update spacing to 4 spaces
tuna/gui/__init__.py: Fix some whitespace problems
tuna: commonview.py: Fix comparisons with None
tuna: cpuview.py: box.pack_start needs extra parameter
tuna: tuna-cmd.py Fix style problems recommened by PEP8
tuna: Fix spacing of oscilloscope.py
tuna: config.py: Port file to Gtk-3.0
tuna:irqview.py: Port to Gtk-3.0
tuna: procview.py: Port to Gtk-3.0
tuna: profileview.py: Port to Gtk-3.0
tuna: util.py: Fix some style problems
tuna: oscilloscope.py: Changes to port to Gtk-3.0
tuna: sysfs.py: Update spacing / tabs to modern python style
tuna: tuna.py: Update spacing / tabs to modern python style
tuna: tuna_gui.py: Chanages to port to Gtk-3.0
tuna: Remove python-schedutils dependency
tuna: Add ctags to the tuna makefile
tuna: release 0.15
.gitattributes | 2 +
.gitignore | 2 +
Makefile | 8 +
oscilloscope-cmd.py | 141 ++--
rpm/SPECS/tuna.spec | 5 +-
setup.py | 2 +-
tuna-cmd.py | 1268 ++++++++++++++++++------------------
tuna/config.py | 760 +++++++++++-----------
tuna/gui/__init__.py | 6 +-
tuna/gui/commonview.py | 521 +++++++--------
tuna/gui/cpuview.py | 694 ++++++++++----------
tuna/gui/irqview.py | 640 ++++++++++---------
tuna/gui/procview.py | 1347 +++++++++++++++++++--------------------
tuna/gui/profileview.py | 668 ++++++++++---------
tuna/gui/util.py | 223 +++----
tuna/oscilloscope.py | 861 ++++++++++++-------------
tuna/sysfs.py | 199 +++---
tuna/tuna.py | 1190 +++++++++++++++++-----------------
tuna/tuna_gui.glade | 1037 ++++++++++++++++--------------
tuna/tuna_gui.py | 294 +++++----
tuna/tuna_sched.py | 29 +
21 files changed, 5050 insertions(+), 4847 deletions(-)
create mode 100644 .gitattributes
mode change 100755 => 100644 tuna/gui/util.py
create mode 100644 tuna/tuna_sched.py
--
2.26.2
2 years, 10 months
[PATCH] tuna: release 0.15
by John Kacur
- Create release 0.15
- tag it as v0.15
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
rpm/SPECS/tuna.spec | 3 +--
setup.py | 2 +-
tuna-cmd.py | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/rpm/SPECS/tuna.spec b/rpm/SPECS/tuna.spec
index 72365a29f2e4..2ab5511081d5 100644
--- a/rpm/SPECS/tuna.spec
+++ b/rpm/SPECS/tuna.spec
@@ -2,7 +2,7 @@
%{!?python_ver: %define python_ver %(%{__python} -c "import sys ; print(sys.version[:3])")}
Name: tuna
-Version: 0.14.1
+Version: 0.15
Release: 1%{?dist}
License: GPLv2
Summary: Application tuning GUI & command line utility
@@ -13,7 +13,6 @@ BuildArch: noarch
BuildRequires: python-devel, gettext, desktop-file-utils
Requires: python-ethtool
Requires: python-linux-procfs >= 0.6
-Requires: python-schedutils >= 0.6
# This really should be a Suggests...
# Requires: python-inet_diag
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
diff --git a/setup.py b/setup.py
index acbc2eeaac37..f6320b1eaf34 100755
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ if isfile("MANIFEST"):
PYTHONLIB = join(get_python_lib(standard_lib=1, prefix=''), 'site-packages')
setup(name="tuna",
- version = "0.14.1",
+ version = "0.15",
description = "Application tuning GUI",
author = "Arnaldo Carvalho de Melo",
author_email = "acme(a)redhat.com",
diff --git a/tuna-cmd.py b/tuna-cmd.py
index d3446d7aabb3..7b9f6ebd57c3 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -41,7 +41,7 @@ except:
nr_cpus = None
ps = None
irqs = None
-version = "0.14.1"
+version = "0.15"
def usage():
--
2.26.2
2 years, 10 months
[PATCH 1/2] tuna: Remove python-schedutils dependency
by John Kacur
python-schedutils isn't necessary anymore as python-3.3 and up has built in
support for scheduling functions
- Also remove check for SystemError that old python-schedutils
incorrectly raised, this was fixed long ago.
- A functions to go from a str to a policy number and from a policy
number to a str. These were in python-schedutils but not in python3
- Fix a few remaining spots where the code tested for 3 instead of
errno.ERSCH
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
tuna-cmd.py | 15 +++----
tuna/gui/cpuview.py | 4 +-
tuna/gui/irqview.py | 10 ++---
tuna/gui/procview.py | 14 +++---
tuna/gui/util.py | 35 +++++++--------
tuna/tuna.py | 103 ++++++++++++++++++-------------------------
tuna/tuna_sched.py | 29 ++++++++++++
7 files changed, 109 insertions(+), 101 deletions(-)
create mode 100644 tuna/tuna_sched.py
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 0388ecb87290..d3446d7aabb3 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import gettext
import locale
from functools import reduce
import ethtool
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
@@ -203,13 +203,13 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
sock_inode_re, cgroups):
global irqs
try:
- affinity = format_affinity(schedutils.get_affinity(pid))
- except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ affinity = format_affinity(os.sched_getaffinity(pid))
+ except OSError as e:
if e.args[0] == errno.ESRCH:
return
raise e
- sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
+ sched = tuna_sched.sched_str(os.sched_getscheduler(pid))[6:]
rtprio = int(ps[pid]["stat"]["rt_priority"])
cgout = ps[pid]["cgroups"]
cmd = ps[pid]["stat"]["comm"]
@@ -288,8 +288,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
if not in_irq_list and thread_list and pid not in thread_list:
continue
try:
- affinity = schedutils.get_affinity(pid)
- except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
+ affinity = os.sched_getaffinity(pid)
+ except OSError as e:
if e.args[0] == errno.ESRCH:
continue
raise e
@@ -597,8 +597,7 @@ def main():
else:
try:
tuna.threads_set_priority(thread_list, a, affect_children)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
print("tuna: %s" % err)
sys.exit(2)
elif o in ("-P", "--show_threads"):
diff --git a/tuna/gui/cpuview.py b/tuna/gui/cpuview.py
index 4915ce4e5f1d..ec19149d0578 100755
--- a/tuna/gui/cpuview.py
+++ b/tuna/gui/cpuview.py
@@ -9,7 +9,7 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import sysfs, tuna, gui
@@ -337,7 +337,7 @@ class cpuview:
affinities = self.previous_pid_affinities
for pid in list(affinities.keys()):
try:
- schedutils.set_affinity(pid, affinities[pid])
+ os.sched_setaffinity(pid, affinities[pid])
except:
pass
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 012bd9f5ec4f..ea5c2f5eda0f 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -8,7 +8,7 @@ from gi.repository import GObject
import os
from functools import reduce
import ethtool
-import schedutils
+import tuna.tuna_sched as tuna_sched
import gi
gi.require_version("Gtk", "3.0")
@@ -46,7 +46,7 @@ class irq_druid:
pid = pids[0]
prio = int(ps[pid]["stat"]["rt_priority"])
self.create_policy_model(self.sched_policy)
- self.sched_policy.set_active(schedutils.get_scheduler(pid))
+ self.sched_policy.set_active(os.sched_getscheduler(pid))
self.sched_pri.set_value(prio)
text.set_markup(
"IRQ <b>%u</b> (PID <b>%u</b>), pri <b>%u</b>, aff <b>%s</b>, <tt><b>%s</b></tt>" %
@@ -68,13 +68,13 @@ class irq_druid:
policy.add_attribute(renderer, "text", COL_TEXT)
for pol in range(4):
row = list_store.append()
- list_store.set(row, COL_TEXT, schedutils.schedstr(pol),
+ list_store.set(row, COL_TEXT, tuna_sched.sched_str(pol),
COL_SCHED, pol)
policy.set_model(list_store)
def on_sched_policy_combo_changed(self, button):
new_policy = self.sched_policy.get_active()
- if new_policy in (schedutils.SCHED_FIFO, schedutils.SCHED_RR):
+ if new_policy in (os.SCHED_FIFO, os.SCHED_RR):
can_change_pri = True
else:
can_change_pri = False
@@ -201,7 +201,7 @@ class irqview:
if pids:
pid = pids[0]
prio = int(self.ps[pid]["stat"]["rt_priority"])
- sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
+ sched = tuna_sched.sched_str(os.sched_getscheduler(pid))[6:]
else:
sched = ""
pid = -1
diff --git a/tuna/gui/procview.py b/tuna/gui/procview.py
index 435ce111439a..f897fdd9e153 100755
--- a/tuna/gui/procview.py
+++ b/tuna/gui/procview.py
@@ -1,5 +1,5 @@
import re
-import schedutils
+import tuna.tuna_sched as tuna_sched
import gi
gi.require_version("Gtk", "3.0")
@@ -54,11 +54,11 @@ class process_druid:
self.sched_pri.set_value(int(pid_info["stat"]["rt_priority"]))
cmdline_regex = procfs.process_cmdline(pid_info)
- self.affinity_text = tuna.list_to_cpustring(schedutils.get_affinity(pid))
+ self.affinity_text = tuna.list_to_cpustring(os.sched_getaffinity(pid))
self.affinity.set_text(self.affinity_text)
self.create_matching_process_model(processes)
self.create_policy_model(self.sched_policy)
- self.sched_policy.set_active(schedutils.get_scheduler(pid))
+ self.sched_policy.set_active(os.sched_getscheduler(pid))
self.regex_edit.set_text(cmdline_regex)
self.just_this_thread.set_active(True)
self.regex_edit.set_sensitive(False)
@@ -98,7 +98,7 @@ class process_druid:
policy.add_attribute(renderer, "text", COL_TEXT)
for pol in range(4):
row = list_store.append()
- list_store.set(row, COL_TEXT, schedutils.schedstr(pol),
+ list_store.set(row, COL_TEXT, tuna_sched.sched_str(pol),
COL_SCHED, pol)
policy.set_model(list_store)
@@ -141,7 +141,7 @@ class process_druid:
def on_sched_policy_combo_changed(self, button):
new_policy = self.sched_policy.get_active()
- if new_policy in (schedutils.SCHED_FIFO, schedutils.SCHED_RR):
+ if new_policy in (os.SCHED_FIFO, os.SCHED_RR):
can_change_pri = True
else:
can_change_pri = False
@@ -396,8 +396,8 @@ class procview:
new_value = [None] * self.nr_columns
new_value[self.COL_PRI] = int(thread_info["stat"]["rt_priority"])
- new_value[self.COL_POL] = schedutils.schedstr(schedutils.get_scheduler(tid))[6:]
- thread_affinity_list = schedutils.get_affinity(tid)
+ new_value[self.COL_POL] = tuna_sched.sched_str(os.sched_getscheduler(tid))[6:]
+ thread_affinity_list = os.sched_getaffinity(tid)
new_value[self.COL_PID] = tid
new_value[self.COL_AFF] = tuna.list_to_cpustring(thread_affinity_list)
diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 3b5ff426213b..3c3ff4a706ad 100644
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -1,10 +1,10 @@
+import errno
import gi
gi.require_version("Gtk", "3.0")
-
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Pango
-import schedutils
+import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna
@@ -62,13 +62,14 @@ def invalid_affinity():
def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus):
pid = pid_info.pid
changed = False
- curr_policy = schedutils.get_scheduler(pid)
+ curr_policy = os.sched_getscheduler(pid)
curr_prio = int(pid_info["stat"]["rt_priority"])
- if new_policy == schedutils.SCHED_OTHER:
+ if new_policy == os.SCHED_OTHER:
new_prio = 0
if curr_policy != new_policy or curr_prio != new_prio:
+ param = os.sched_param(new_prio)
try:
- schedutils.set_scheduler(pid, new_policy, new_prio)
+ os.sched_setscheduler(pid, new_policy, param)
except:
dialog = Gtk.MessageDialog(None, \
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \
@@ -79,22 +80,20 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
dialog.destroy()
return False
- curr_policy = schedutils.get_scheduler(pid)
+ curr_policy = os.sched_getscheduler(pid)
if curr_policy != new_policy:
print(_("couldn't change pid %(pid)d from %(cpol)s(%(cpri)d) to %(npol)s(%(npri)d)!") % \
- {'pid': pid, 'cpol': schedutils.schedstr(curr_policy),
+ {'pid': pid, 'cpol': tuna_sched.sched_str(curr_policy),
'cpri': curr_prio,
- 'npol': schedutils.schedstr(new_policy),
+ 'npol': tuna_sched.sched_str(new_policy),
'npri': new_prio})
else:
changed = True
try:
- curr_affinity = schedutils.get_affinity(pid)
- # (3, 'No such process') old python-schedutils
- # incorrectly raised SystemError
- except (SystemError, OSError) as err:
- if err.args[0] == 3:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
+ if err.args[0] == errno.ESRCH:
return False
raise err
@@ -110,16 +109,14 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
if curr_affinity != new_affinity:
try:
- schedutils.set_affinity(pid, new_affinity)
+ os.sched_setaffinity(pid, new_affinity)
except:
return invalid_affinity()
try:
- curr_affinity = schedutils.get_affinity(pid)
- # (3, 'No such process') old python-schedutils
- # incorrectly raised SystemError
- except (SystemError, OSError) as err:
- if err.args[0] == 3:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
+ if err.args[0] == errno.ESRCH:
return False
raise err
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30e87529f656..e5122dac1081 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,11 +9,11 @@ import sys
import shlex
import fnmatch
import platform
-import schedutils
import ethtool
import procfs
from procfs import utilist
from . import help
+import tuna.tuna_sched as tuna_sched
try:
fntable
@@ -191,19 +191,17 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
try:
try:
- curr_affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
curr_affinity = None
raise err
if set(curr_affinity) != set(new_affinity):
try:
- schedutils.set_affinity(pid, new_affinity)
- curr_affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(pid, new_affinity)
+ curr_affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
curr_affinity = None
@@ -231,18 +229,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
threads = procfs.pidstats("/proc/%d/task" % pid)
for tid in list(threads.keys()):
try:
- curr_affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ curr_affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
if set(curr_affinity) != set(new_affinity):
try:
- schedutils.set_affinity(tid, new_affinity)
- curr_affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(tid, new_affinity)
+ curr_affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -254,8 +250,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning=None, spread=False)
print("move_threads_to_cpu: %s " % \
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
{'pid':pid, 'new_affinity':new_affinity}))
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
# process died
continue
@@ -304,9 +299,8 @@ def move_irqs_to_cpu(cpus, irq_list, spread=False):
if pid:
pid = int(pid[0])
try:
- schedutils.set_affinity(pid, new_affinity)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ os.sched_setaffinity(pid, new_affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
unprocessed.append(i)
changed -= 1
@@ -354,9 +348,8 @@ def isolate_cpus(cpus, nr_cpus):
if procfs.cannot_set_affinity(ps, pid):
continue
try:
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -367,9 +360,8 @@ def isolate_cpus(cpus, nr_cpus):
previous_pid_affinities[pid] = copy.copy(affinity)
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
- schedutils.set_affinity(pid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(pid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -384,9 +376,8 @@ def isolate_cpus(cpus, nr_cpus):
if procfs.cannot_set_thread_affinity(ps, pid, tid):
continue
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -397,9 +388,8 @@ def isolate_cpus(cpus, nr_cpus):
previous_pid_affinities[tid] = copy.copy(affinity)
affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
try:
- schedutils.set_affinity(tid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(tid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
if err.args[0] == errno.EINVAL:
@@ -436,9 +426,8 @@ def include_cpus(cpus, nr_cpus):
if procfs.cannot_set_affinity(ps, pid):
continue
try:
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -446,9 +435,8 @@ def include_cpus(cpus, nr_cpus):
previous_pid_affinities[pid] = copy.copy(affinity)
affinity = list(set(affinity + cpus))
try:
- schedutils.set_affinity(pid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(pid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -460,9 +448,8 @@ def include_cpus(cpus, nr_cpus):
if procfs.cannot_set_thread_affinity(ps, pid, tid):
continue
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -470,9 +457,8 @@ def include_cpus(cpus, nr_cpus):
previous_pid_affinities[tid] = copy.copy(affinity)
affinity = list(set(affinity + cpus))
try:
- schedutils.set_affinity(tid, affinity)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ os.sched_setaffinity(tid, affinity)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -524,7 +510,7 @@ def get_policy_and_rtprio(parm):
rtprio = 0
policy = None
if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR"]:
- policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper())
+ policy = tuna_sched.sched_fromstr("SCHED_%s" % parms[0].upper())
if len(parms) > 1:
rtprio = int(parms[1])
elif parms[0].upper() in ["FIFO", "RR"]:
@@ -538,9 +524,8 @@ def get_policy_and_rtprio(parm):
def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
if cpus_filtered:
try:
- affinity = schedutils.get_affinity(tid)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ affinity = os.sched_getaffinity(tid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
return False
raise err
@@ -565,9 +550,10 @@ def irq_filtered(irq, irqs, cpus_filtered, is_root):
return False
def thread_set_priority(tid, policy, rtprio):
+ param = os.sched_param(rtprio)
if not policy and policy != 0:
- policy = schedutils.get_scheduler(tid)
- schedutils.set_scheduler(tid, policy, rtprio)
+ policy = os.sched_getscheduler(tid)
+ os.sched_setscheduler(tid, policy, param)
def threads_set_priority(tids, parm, affect_children=False):
try:
@@ -579,8 +565,7 @@ def threads_set_priority(tids, parm, affect_children=False):
for tid in tids:
try:
thread_set_priority(tid, policy, rtprio)
- # old python-schedutils incorrectly raised SystemError
- except (SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -589,8 +574,7 @@ def threads_set_priority(tids, parm, affect_children=False):
if child != tid:
try:
thread_set_priority(child, policy, rtprio)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -619,10 +603,9 @@ def get_kthread_sched_tunings(proc=None):
if iskthread(pid) and not name.startswith("migration/"):
rtprio = int(proc[pid]["stat"]["rt_priority"])
try:
- policy = schedutils.get_scheduler(pid)
- affinity = schedutils.get_affinity(pid)
- # old python-schedutils incorrectly raised SystemError
- except(SystemError, OSError) as err:
+ policy = os.sched_getscheduler(pid)
+ affinity = os.sched_getaffinity(pid)
+ except OSError as err:
if err.args[0] == errno.ESRCH:
continue
raise err
@@ -646,7 +629,7 @@ def run_command(cmd, policy, rtprio, cpu_list):
sys.exit(2)
if cpu_list:
try:
- schedutils.set_affinity(pid, cpu_list)
+ os.sched_setaffinity(pid, cpu_list)
except (SystemError, OSError) as err:
print("tuna: %s" % err)
sys.exit(2)
@@ -718,7 +701,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
mask = ",".join([hex(a) for a in \
procfs.hexbitmask(kt.affinity, nr_cpus)])
f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
- schedutils.schedstr(kt.policy)[6].lower(), \
+ tuna_sched.sched_str(kt.policy)[6].lower(), \
kt.rtprio, mask, regex))
f.close()
diff --git a/tuna/tuna_sched.py b/tuna/tuna_sched.py
new file mode 100644
index 000000000000..fee5f166b004
--- /dev/null
+++ b/tuna/tuna_sched.py
@@ -0,0 +1,29 @@
+"""
+Functions to translate a scheduling policy into either a string name or an
+equivalent integer
+"""
+import os
+
+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
+}
+
+def sched_fromstr(policy):
+ """ Given a policy as a string, return the equivalent integer """
+ try:
+ return SCHED_POLICIES[policy]
+ except:
+ raise OSError()
+
+
+def sched_str(policy):
+ """ Given a policy as an integer, return the equivalent string name """
+ for pstr, pnum in SCHED_POLICIES.items():
+ if pnum == policy:
+ return pstr
+ return "UNKNOWN"
--
2.26.2
2 years, 10 months
[PATCH] python-linux-procfs: Create release 0.6.3
by John Kacur
python-linux-procfs: Create release 0.6.3
with tag v0.6.3
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
rpm/SPECS/python-linux-procfs.spec | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/rpm/SPECS/python-linux-procfs.spec b/rpm/SPECS/python-linux-procfs.spec
index 6103cbff8c19..6f32a771ca42 100644
--- a/rpm/SPECS/python-linux-procfs.spec
+++ b/rpm/SPECS/python-linux-procfs.spec
@@ -5,7 +5,7 @@
%endif
Name: python-linux-procfs
-Version: 0.6.2
+Version: 0.6.3
Release: 1%{?dist}
License: GPLv2
Summary: Linux /proc abstraction classes
@@ -84,6 +84,11 @@ rm -rf %{buildroot}
%endif
%changelog
+* Mon Jan 11 2021 John Kacur <jkacur(a)redhat.com> - 0.6.3-1
+- python-linux-procfs: Fix more spacing problems with procfs.py
+- python-linux-procfs: procfs.py: Simplify is_s390
+- python-linux-procfs: procfs.py: Fix a few more style problems
+
* Mon Jun 22 2020 John Kacur <jkacur(a)redhat.com> - 0.6.2-1
- Add bitmasklist_test
- clean-ups for recent python formating regarding spacing, tabs, etc
--
2.26.2
2 years, 11 months
[PATCH 1/3] python-linux-procfs: Fix more spacing problems with procfs.py
by John Kacur
Fix spacing problems as recommended by PEP8 for procfs.py
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
procfs/procfs.py | 133 +++++++++++++++++++++++++++++------------------
1 file changed, 81 insertions(+), 52 deletions(-)
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 3cfa941ffdb9..14135ac72cc2 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -18,7 +18,8 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
-import os, time
+import os
+import time
from functools import reduce
from six.moves import range
from procfs.utilist import bitmasklist
@@ -27,6 +28,7 @@ import re
VERSION = "0.5"
+
def is_s390():
machine = platform.machine()
if re.search('s390', machine):
@@ -34,6 +36,7 @@ def is_s390():
else:
return False
+
def process_cmdline(pid_info):
"""
Returns the process command line, if available in the given `process' class, if
@@ -44,6 +47,7 @@ def process_cmdline(pid_info):
return pid_info["stat"]["comm"]
+
class pidstat:
"""Provides a dictionary to access the fields in the per process /proc/PID/stat
files.
@@ -74,54 +78,57 @@ class pidstat:
# Entries with the same value, the one with a comment after it is the
# more recent, having replaced the other name in v4.1-rc kernel times.
- PF_ALIGNWARN = 0x00000001
- PF_STARTING = 0x00000002
- PF_EXITING = 0x00000004
- PF_EXITPIDONE = 0x00000008
- PF_VCPU = 0x00000010
- PF_WQ_WORKER = 0x00000020 # /* I'm a workqueue worker */
- PF_FORKNOEXEC = 0x00000040
- PF_MCE_PROCESS = 0x00000080 # /* process policy on mce errors */
- PF_SUPERPRIV = 0x00000100
- PF_DUMPCORE = 0x00000200
- PF_SIGNALED = 0x00000400
- PF_MEMALLOC = 0x00000800
- PF_NPROC_EXCEEDED= 0x00001000 # /* set_user noticed that RLIMIT_NPROC was exceeded */
- PF_FLUSHER = 0x00001000
- PF_USED_MATH = 0x00002000
- PF_USED_ASYNC = 0x00004000 # /* used async_schedule*(), used by module init */
- PF_NOFREEZE = 0x00008000
- PF_FROZEN = 0x00010000
- PF_FSTRANS = 0x00020000
- PF_KSWAPD = 0x00040000
- PF_MEMALLOC_NOIO = 0x00080000 # /* Allocating memory without IO involved */
- PF_SWAPOFF = 0x00080000
+ PF_ALIGNWARN = 0x00000001
+ PF_STARTING = 0x00000002
+ PF_EXITING = 0x00000004
+ PF_EXITPIDONE = 0x00000008
+ PF_VCPU = 0x00000010
+ PF_WQ_WORKER = 0x00000020 # /* I'm a workqueue worker */
+ PF_FORKNOEXEC = 0x00000040
+ PF_MCE_PROCESS = 0x00000080 # /* process policy on mce errors */
+ PF_SUPERPRIV = 0x00000100
+ PF_DUMPCORE = 0x00000200
+ PF_SIGNALED = 0x00000400
+ PF_MEMALLOC = 0x00000800
+ # /* set_user noticed that RLIMIT_NPROC was exceeded */
+ PF_NPROC_EXCEEDED = 0x00001000
+ PF_FLUSHER = 0x00001000
+ PF_USED_MATH = 0x00002000
+ PF_USED_ASYNC = 0x00004000 # /* used async_schedule*(), used by module init */
+ PF_NOFREEZE = 0x00008000
+ PF_FROZEN = 0x00010000
+ PF_FSTRANS = 0x00020000
+ PF_KSWAPD = 0x00040000
+ PF_MEMALLOC_NOIO = 0x00080000 # /* Allocating memory without IO involved */
+ PF_SWAPOFF = 0x00080000
PF_LESS_THROTTLE = 0x00100000
- PF_KTHREAD = 0x00200000
- PF_RANDOMIZE = 0x00400000
- PF_SWAPWRITE = 0x00800000
- PF_SPREAD_PAGE = 0x01000000
- PF_SPREAD_SLAB = 0x02000000
- PF_THREAD_BOUND = 0x04000000
- PF_NO_SETAFFINITY = 0x04000000 # /* Userland is not allowed to meddle with cpus_allowed */
- PF_MCE_EARLY = 0x08000000 # /* Early kill for mce process policy */
- PF_MEMPOLICY = 0x10000000
- PF_MUTEX_TESTER = 0x20000000
- PF_FREEZER_SKIP = 0x40000000
+ PF_KTHREAD = 0x00200000
+ PF_RANDOMIZE = 0x00400000
+ PF_SWAPWRITE = 0x00800000
+ PF_SPREAD_PAGE = 0x01000000
+ PF_SPREAD_SLAB = 0x02000000
+ PF_THREAD_BOUND = 0x04000000
+ # /* Userland is not allowed to meddle with cpus_allowed */
+ PF_NO_SETAFFINITY = 0x04000000
+ PF_MCE_EARLY = 0x08000000 # /* Early kill for mce process policy */
+ PF_MEMPOLICY = 0x10000000
+ PF_MUTEX_TESTER = 0x20000000
+ PF_FREEZER_SKIP = 0x40000000
PF_FREEZER_NOSIG = 0x80000000
- PF_SUSPEND_TASK = 0x80000000 # /* this thread called freeze_processes and should not be frozen */
+ # /* this thread called freeze_processes and should not be frozen */
+ PF_SUSPEND_TASK = 0x80000000
proc_stat_fields = ["pid", "comm", "state", "ppid", "pgrp", "session",
- "tty_nr", "tpgid", "flags", "minflt", "cminflt",
- "majflt", "cmajflt", "utime", "stime", "cutime",
- "cstime", "priority", "nice", "num_threads",
- "itrealvalue", "starttime", "vsize", "rss",
- "rlim", "startcode", "endcode", "startstack",
- "kstkesp", "kstkeip", "signal", "blocked",
- "sigignore", "sigcatch", "wchan", "nswap",
- "cnswap", "exit_signal", "processor",
- "rt_priority", "policy",
- "delayacct_blkio_ticks", "environ"]
+ "tty_nr", "tpgid", "flags", "minflt", "cminflt",
+ "majflt", "cmajflt", "utime", "stime", "cutime",
+ "cstime", "priority", "nice", "num_threads",
+ "itrealvalue", "starttime", "vsize", "rss",
+ "rlim", "startcode", "endcode", "startstack",
+ "kstkesp", "kstkeip", "signal", "blocked",
+ "sigignore", "sigcatch", "wchan", "nswap",
+ "cnswap", "exit_signal", "processor",
+ "rt_priority", "policy",
+ "delayacct_blkio_ticks", "environ"]
def __init__(self, pid, basedir="/proc"):
self.pid = pid
@@ -218,22 +225,25 @@ class pidstat:
return sflags
+
def cannot_set_affinity(self, pid):
PF_NO_SETAFFINITY = 0x04000000
try:
return int(self.processes[pid]["stat"]["flags"]) & \
- PF_NO_SETAFFINITY and True or False
+ PF_NO_SETAFFINITY and True or False
except:
return True
+
def cannot_set_thread_affinity(self, pid, tid):
PF_NO_SETAFFINITY = 0x04000000
try:
return int(self.processes[pid].threads[tid]["stat"]["flags"]) & \
- PF_NO_SETAFFINITY and True or False
+ PF_NO_SETAFFINITY and True or False
except:
return True
+
class pidstatus:
"""
Provides a dictionary to access the fields in the per process /proc/PID/status
@@ -309,6 +319,7 @@ class pidstatus:
self.fields[name] = value
f.close()
+
class process:
"""
Information about a process with a given pid, provides a dictionary with
@@ -401,6 +412,7 @@ class process:
self.environ[y[0]] = y[1]
f.close()
+
class pidstats:
"""
Provides access to all the processes in the system, to get a picture of
@@ -409,6 +421,7 @@ class pidstats:
The entries can be accessed as a dictionary, keyed by pid. Also there are
methods to find processes that match a given COMM or regular expression.
"""
+
def __init__(self, basedir="/proc"):
self.basedir = basedir
self.processes = {}
@@ -568,6 +581,7 @@ class pidstats:
"""
return self.processes[pid]["stat"].is_bound_to_cpu()
+
class interrupts:
"""
Information about IRQs in the system. A dictionary keyed by IRQ number
@@ -592,6 +606,7 @@ class interrupts:
{'affinity': [0, 1, 2, 3], 'type': 'PCI-MSI', 'cpu': [3495, 0, 81, 0], 'users': ['thunderbolt']}
>>>
"""
+
def __init__(self):
self.interrupts = {}
self.reload()
@@ -647,7 +662,8 @@ class interrupts:
dict["type"] = fields[self.nr_cpus]
# look if there are users (interrupts 3 and 4 haven't)
if nr_fields > self.nr_cpus + 1:
- dict["users"] = [a.strip() for a in fields[nr_fields - 1].split(',')]
+ dict["users"] = [a.strip()
+ for a in fields[nr_fields - 1].split(',')]
else:
dict["users"] = []
return dict
@@ -709,6 +725,7 @@ class interrupts:
break
return irqs
+
class cmdline:
"""
Parses the kernel command line (/proc/cmdline), turning it into a dictionary."
@@ -756,6 +773,7 @@ class cmdline:
def items(self):
return self.options
+
class cpuinfo:
"""
Dictionary with information about CPUs in the system.
@@ -787,6 +805,7 @@ class cpuinfo:
4096 KB
>>>
"""
+
def __init__(self, filename="/proc/cpuinfo"):
self.tags = {}
self.nr_cpus = 0
@@ -829,8 +848,11 @@ class cpuinfo:
f.close()
self.nr_sockets = self.sockets and len(self.sockets) or \
- (self.nr_cpus / ("siblings" in self.tags and int(self.tags["siblings"]) or 1))
- self.nr_cores = ("cpu cores" in self.tags and int(self.tags["cpu cores"]) or 1) * self.nr_sockets
+ (self.nr_cpus /
+ ("siblings" in self.tags and int(self.tags["siblings"]) or 1))
+ self.nr_cores = ("cpu cores" in self.tags and int(
+ self.tags["cpu cores"]) or 1) * self.nr_sockets
+
class smaps_lib:
"""
@@ -842,6 +864,7 @@ class smaps_lib:
The 'vm_start' and 'vm_end' in turn can be used when trying to resolve
processor instruction pointer addresses to a symbol name in a library.
"""
+
def __init__(self, lines):
fields = lines[0].split()
self.vm_start, self.vm_end = [int(a, 16) for a in fields[0].split("-")]
@@ -901,6 +924,7 @@ class smaps:
/usr/lib64/libpthread-2.20.so: r-xp
...
"""
+
def __init__(self, pid):
self.pid = pid
self.entries = []
@@ -946,10 +970,11 @@ class smaps:
for i in range(self.nr_entries):
if self.entries[i].name and \
self.entries[i].name.find(fragment) >= 0:
- result.append(self.entries[i])
+ result.append(self.entries[i])
return result
+
class cpustat:
"""
CPU statistics, obtained from a line in the '/proc/stat' file, Please
@@ -973,13 +998,15 @@ class cpustat:
def __repr__(self):
s = "< user: %s, nice: %s, system: %s, idle: %s, iowait: %s, irq: %s, softirq: %s" % \
- (self.user, self.nice, self.system, self.idle, self.iowait, self.irq, self.softirq)
+ (self.user, self.nice, self.system, self.idle,
+ self.iowait, self.irq, self.softirq)
if hasattr(self, 'steal'):
s += ", steal: %d" % self.steal
if hasattr(self, 'guest'):
s += ", guest: %d" % self.guest
return s + ">"
+
class cpusstats:
"""
Dictionary with information about CPUs in the system. First entry in the
@@ -988,6 +1015,7 @@ class cpusstats:
about the '/proc/stat' file, that is the source of the information provided
by this class.
"""
+
def __init__(self, filename="/proc/stat"):
self.entries = {}
self.time = None
@@ -1046,6 +1074,7 @@ class cpusstats:
if curr.usage > 100:
curr.usage = 100
+
if __name__ == '__main__':
import sys
--
2.26.2
2 years, 11 months