Skip to content

Commit 665fed0

Browse files
bhalevyxemul
authored andcommitted
scripts/stall-analyser: improve error messages on invalid input
and make sure to exit with failure status Currently the program hits an internal error on invalid input like: `Reactor stalled for 4 ms on shard 0. Backtrace:` that has no following backtrace. Instead of emitting an obscure backtrace, like: ``` Traceback (most recent call last): File "/home/bhalevy/dev/seastar/./scripts/stall-analyser.py", line 461, in <module> main() File "/home/bhalevy/dev/seastar/./scripts/stall-analyser.py", line 443, in main render.process_trace(trace, t) File "/home/bhalevy/dev/seastar/./scripts/stall-analyser.py", line 156, in process_trace self.add_head(t, node) File "/home/bhalevy/dev/seastar/./scripts/stall-analyser.py", line 175, in add_head self.head.link_callee(t, n) File "/home/bhalevy/dev/seastar/./scripts/stall-analyser.py", line 104, in link_callee if n.addr in self.callees: ^^^^^^ AttributeError: 'NoneType' object has no attribute 'addr' ``` Print a formal error message that describes how valid input should look like in 2 cases: 1. When no valid input is found 2. When a line with empty backtrace is found. Signed-off-by: Benny Halevy <[email protected]> Closes #2558
1 parent 1fe948f commit 665fed0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: scripts/stall-analyser.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def main():
394394
args = get_command_line_parser().parse_args()
395395
comment = re.compile(r'^\s*#')
396396
pattern = re.compile(r"Reactor stalled for (?P<stall>\d+) ms on shard (?P<shard>\d+).*Backtrace:")
397+
expected_input_format = "Expected one or more lines ending with: 'Reactor stalled for <n> ms on shard <i>. Backtrace: <addr> [<addr> ...]'"
397398
address_threshold = int(args.address_threshold, 0)
398399
# map from stall time in ms to the count of the stall time
399400
tally = {}
@@ -434,12 +435,19 @@ def main():
434435
if address_threshold:
435436
trace = list(dropwhile(lambda addr: int(addr, 0) >= address_threshold, trace))
436437
if t >= args.tmin:
438+
if not trace:
439+
print(f"""Invalid input line: '{s.strip()}'
440+
{expected_input_format}
441+
Please run `stall-analyser.py --help` for usage instruction""", file=sys.stderr)
442+
sys.exit(1)
437443
render.process_trace(trace, t)
438444

439445
try:
440446
if not render:
441-
print("No input data found. Please run `stall-analyser.py --help` for usage instruction")
442-
sys.exit()
447+
print(f"""No input data found.
448+
{expected_input_format}
449+
Please run `stall-analyser.py --help` for usage instruction""", file=sys.stderr)
450+
sys.exit(1)
443451
if args.format == 'graph':
444452
print_command_line_options(args)
445453
print_stats(tally, args.tmin)

0 commit comments

Comments
 (0)