tools/writeback: parse help before importing drgn
Subsystems (2)
PATCH 1/1 tools/writeback: parse help before importing drgn
wb_monitor.py imports drgn before argparse can handle "-h". That makes help fail on systems where drgn is not installed, even though the script does not need drgn to print usage text.
Parse arguments before importing drgn so the help path works without the runtime debugging dependency. While there, fix a typo in the help text.
--- tools/writeback/wb_monitor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/writeback/wb_monitor.py +4 -4
@@ -14,7 +14,7 @@ backing dev. For more info on drgn, visit https://github.com/osandov/drgn. dirtied(kB) Amount of pages have been dirtied. - wrttien(kB) Amount of dirty pages have been written back to disk. + written(kB) Amount of dirty pages have been written back to disk. avg_wb(kBps) Smoothly estimated write bandwidth of writing dirty pages back to disk.
@@ -25,9 +25,6 @@ import re import time import json -import drgn -from drgn.helpers.linux.list import list_for_each_entry - import argparse parser = argparse.ArgumentParser(description=desc, formatter_class=argparse.RawTextHelpFormatter)
@@ -41,6 +38,9 @@ parser.add_argument('-c', '--cgroup', action='store_true', help='show writeback of bdi in cgroup') args = parser.parse_args() +import drgn +from drgn.helpers.linux.list import list_for_each_entry + bdi_list = prog['bdi_list'] WB_RECLAIMABLE = prog['WB_RECLAIMABLE']
Signature · 1 line
2.54.0
Quoted 3 lines · On Wed, 24 Jun 2026 14:35:14 +0200 Yousef Alhouseen…
wb_monitor.pyimports drgn before argparse can handle "-h". That makes help fail on systems where drgn is not installed, even though the script does not need drgn to print usage text.
But... How do you execute the drgn script on systems not having drgn? I tried to mimic the situation and reproduce the issue you are saying about, but what I get is like below:
$ sudo mv /usr/bin/drgn /usr/bin/drgn.bak
$ drgn tools/writeback/wb_monitor.py
-bash: /usr/bin/drgn: No such file or directory
$ python tools/writeback/wb_monitor.py
Traceback (most recent call last):
File "/home/lkhack/linux/tools/writeback/wb_monitor.py", line 44, in <module>
bdi_list = prog['bdi_list']
^^^^
NameError: name 'prog' is not definedThanks,
SJ
[...]
Hi SJ,
You're right; the normal invocation path is through the drgn launcher, so the no-drgn case I described is too narrow to justify the patch as written.
Please drop this patch.
Thanks,
Yousef
Quoted 24 lines · SeongJae Park
Quoted 3 lines · On Wed, 24 Jun 2026 14:35:14 +0200 Yousef Alhouseen…
wb_monitor.pyimports drgn before argparse can handle "-h". That makes help fail on systems where drgn is not installed, even though the script does not need drgn to print usage text.But... How do you execute the drgn script on systems not having drgn? I tried to mimic the situation and reproduce the issue you are saying about, but what I get is like below:
$ sudo mv /usr/bin/drgn /usr/bin/drgn.bak $ drgn tools/writeback/wb_monitor.py -bash: /usr/bin/drgn: No such file or directory $ python tools/writeback/wb_monitor.py Traceback (most recent call last): File "/home/lkhack/linux/tools/writeback/wb_monitor.py", line 44, in <module> bdi_list = prog['bdi_list'] ^^^^ NameError: name 'prog' is not definedThanks,
SJ[...]