Skip to contentSkip to conversation

tools/cgroup: iocost_monitor: parse help before importing drgn

PATCH Applied Yousef Alhouseen 2 participants 2 messages Jun 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/cgroup: iocost_monitor: parse help before importing drgn

iocost_monitor.py imports drgn before argparse can handle "-h" or report argument errors. That makes basic usage help fail on systems where drgn is not installed.

Parse arguments before importing drgn so the help and argument-error paths work without the runtime debugging dependency. Normal execution still imports drgn before reading kernel state.

---
 tools/cgroup/iocost_monitor.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/cgroup/iocost_monitor.py +5 -5
index 933c750b3..bdd78ba27 100644
@@ -15,11 +15,6 @@ import time
 import json
 import math
 
-import drgn
-from drgn import container_of
-from drgn.helpers.linux.list import list_for_each_entry,list_empty
-from drgn.helpers.linux.radixtree import radix_tree_for_each,radix_tree_lookup
-
 import argparse
 parser = argparse.ArgumentParser(description=desc,
                                  formatter_class=argparse.RawTextHelpFormatter)
@@ -34,6 +29,11 @@ parser.add_argument('--json', action='store_true',
                     help='Output in json')
 args = parser.parse_args()
 
+import drgn
+from drgn import container_of
+from drgn.helpers.linux.list import list_for_each_entry,list_empty
+from drgn.helpers.linux.radixtree import radix_tree_for_each,radix_tree_lookup
+
 def err(s):
     print(s, file=sys.stderr, flush=True)
     sys.exit(1)
Signature · 1 line
2.54.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Yousef Alhouseen

iocost_monitor.py imports drgn before argparse can handle "-h" or report argument errors. That makes basic usage help fail on systems where drgn is not installed.

Parse arguments before importing drgn so the help and argument-error paths work without the runtime debugging dependency. Normal execution still imports drgn before reading kernel state.

Applied to cgroup/for-7.3.

Thanks.

Signature · 1 line
tejun