Add -R (--refresh) to be able to set via command line the refresh
time of the GUI. Previously it was hardcoded 2500. I believe this
can be very useful both for unloaded systems where we want faster
refreshes and for very loaded (with many processes/irqs) systems
where 2500 can lead to very high CPU usage of tuna.
Signed-off-by: Federico Pellegrin <fede(a)evolware.org>
---
tuna-cmd.py | 16 +++++++++++++---
tuna/gui/cpuview.py | 4 ++--
tuna/tuna_gui.py | 6 +++---
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 4181004..c27abd1 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -84,6 +84,7 @@ def usage():
{"irqlist": _('IRQ-LIST')}))
print(fmt % ('-r, --run=' + _('COMMAND'), _('fork a new process
and run the %(command)s') %
{"command": _('COMMAND')}))
+ print(fmt % ('-R, --refresh=' + _('MSEC'), _('Refresh the GUI
every MSEC milliseconds')))
print(fmt % ('-s, --save=' + _('FILENAME'), _('Save kthreads
sched tunables to %(filename)s') %
{"filename": _('FILENAME')}))
print(fmt % ('-S, --sockets=' +
@@ -494,14 +495,14 @@ def main():
i18n_init()
try:
- short = "a:c:CfgGhiIKlmNp:PQq:r:s:S:t:UvWx"
+ short = "a:c:CfgGhiIKlmNp:PQq:r:R:s:S:t:UvWx"
long = ["cpus=", "affect_children", "filter",
"gui", "help",
"isolate", "include", "no_kthreads",
"move", "nohz_full",
"show_sockets", "priority=",
"show_threads",
"show_irqs", "irqs=",
"save=", "sockets=", "threads=",
"no_uthreads",
"version", "what_is", "spread",
"cgroup", "config_file_apply=",
- "config_file_list=", "run="]
+ "config_file_list=", "run=", "refresh="]
if have_inet_diag:
short += "n"
long.append("show_sockets")
@@ -526,6 +527,7 @@ def main():
affect_children = False
show_sockets = False
p_waiting_action = False
+ gui_refresh = 2500
for o, a in opts:
if o in ("-h", "--help"):
@@ -578,6 +580,14 @@ def main():
filter = True
elif o in ("-g", "--gui"):
run_gui = True
+ elif o in ("-R", "--refresh"):
+ run_gui = True
+ (op, a) = pick_op(a)
+ try:
+ gui_refresh=int(a)
+ except Exception as err:
+ print("tuna: --refresh %s" % err)
+ sys.exit(2)
elif o in ("-i", "--isolate"):
if not cpu_list:
print("tuna: --isolate " + _("requires a cpu
list!"))
@@ -737,7 +747,7 @@ def main():
try:
cpus_filtered = filter and cpu_list or []
- app = tuna_gui.main_gui(kthreads, uthreads, cpus_filtered)
+ app = tuna_gui.main_gui(kthreads, uthreads, cpus_filtered, gui_refresh)
app.run()
except KeyboardInterrupt:
pass
diff --git a/tuna/gui/cpuview.py b/tuna/gui/cpuview.py
index debdd2d..cc3f0f9 100755
--- a/tuna/gui/cpuview.py
+++ b/tuna/gui/cpuview.py
@@ -246,7 +246,7 @@ class cpu_socket_frame(Gtk.Frame):
class cpuview:
- def __init__(self, vpaned, hpaned, window, procview, irqview, cpus_filtered):
+ def __init__(self, vpaned, hpaned, window, procview, irqview, cpus_filtered,
refresh_time):
self.cpus = sysfs.cpus()
self.cpustats = procfs.cpusstats()
self.socket_frames = {}
@@ -306,7 +306,7 @@ class cpuview:
vpaned.set_position(int(height))
hpaned.set_position(int(width))
- self.timer = GObject.timeout_add(3000, self.refresh)
+ self.timer = GObject.timeout_add(refresh_time, self.refresh)
def isolate_cpus(self, cpus):
self.previous_pid_affinities, \
diff --git a/tuna/tuna_gui.py b/tuna/tuna_gui.py
index 5c3276c..1296beb 100755
--- a/tuna/tuna_gui.py
+++ b/tuna/tuna_gui.py
@@ -23,7 +23,7 @@ tuna_glade = None
class main_gui:
- def __init__(self, show_kthreads=True, show_uthreads=True, cpus_filtered=[]):
+ def __init__(self, show_kthreads=True, show_uthreads=True, cpus_filtered=[],
refresh_time=2500):
global tuna_glade
(app, localedir) = ('tuna', '/usr/share/locale')
@@ -55,7 +55,7 @@ class main_gui:
self.wtree.get_object("vpaned1"),
self.wtree.get_object("hpaned2"),
self.wtree.get_object("cpuview"),
- self.procview, self.irqview, cpus_filtered)
+ self.procview, self.irqview, cpus_filtered, refresh_time)
self.config = Config()
self.check_env()
@@ -106,7 +106,7 @@ class main_gui:
self.ps.reload_threads()
self.show()
- self.timer = GObject.timeout_add(2500, self.refresh)
+ self.timer = GObject.timeout_add(refresh_time, self.refresh)
try:
self.icon = Gtk.status_icon_new_from_stock(Gtk.STOCK_PREFERENCES)
self.icon.connect("activate", self.on_status_icon_activate)
--
2.26.3