Skip to content

Commit

Permalink
scripts/stall-analyser: improve error messages on invalid input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bhalevy authored and xemul committed Nov 28, 2024
1 parent 1fe948f commit 665fed0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/stall-analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def main():
args = get_command_line_parser().parse_args()
comment = re.compile(r'^\s*#')
pattern = re.compile(r"Reactor stalled for (?P<stall>\d+) ms on shard (?P<shard>\d+).*Backtrace:")
expected_input_format = "Expected one or more lines ending with: 'Reactor stalled for <n> ms on shard <i>. Backtrace: <addr> [<addr> ...]'"
address_threshold = int(args.address_threshold, 0)
# map from stall time in ms to the count of the stall time
tally = {}
Expand Down Expand Up @@ -434,12 +435,19 @@ def main():
if address_threshold:
trace = list(dropwhile(lambda addr: int(addr, 0) >= address_threshold, trace))
if t >= args.tmin:
if not trace:
print(f"""Invalid input line: '{s.strip()}'
{expected_input_format}
Please run `stall-analyser.py --help` for usage instruction""", file=sys.stderr)
sys.exit(1)
render.process_trace(trace, t)

try:
if not render:
print("No input data found. Please run `stall-analyser.py --help` for usage instruction")
sys.exit()
print(f"""No input data found.
{expected_input_format}
Please run `stall-analyser.py --help` for usage instruction""", file=sys.stderr)
sys.exit(1)
if args.format == 'graph':
print_command_line_options(args)
print_stats(tally, args.tmin)
Expand Down

0 comments on commit 665fed0

Please sign in to comment.