Skip to content

Commit

Permalink
stall-analyser: avoid referencing undefined variable
Browse files Browse the repository at this point in the history
before this change, if user specifies an emtpy file to `--file`,
the body of `for s in args.file` loop is not executed, and the
script just goes ahead and tries to print out the analyse result,
it's fine, as the result is empty. but we pass a yet-defined
variable to `print_stats()`, this result in
```
Traceback (most recent call last):
  File "/home/bhalevy/dev/scylla_s3_reloc_server/./seastar//scripts/stall-analyser.py", line 363, in <module>
    print_stats(tally, tmin)
                       ^^^^
NameError: name 'tmin' is not defined. Did you mean: 'min'?
```

so, in this change, we

- use a better name for the `--minimum` option, `args.minimum`
  is way too general.
- use the default value of 0 instead of `None`, simpler this way
- just reference `arg.tmin`, so we don't reference an undefined
  variable even if the stall report file is empty.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Jun 27, 2024
1 parent 53e33e0 commit f8f5875
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions scripts/stall-analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_command_line_parser():
help='Smart trim of long lines to width characters (0=disabled)')
parser.add_argument('-d', '--direction', choices=['bottom-up', 'top-down'], default='bottom-up',
help='Print graph bottom-up (default, callees first) or top-down (callers first)')
parser.add_argument('-m', '--minimum', type=int, default=None,
parser.add_argument('-m', '--minimum', type=int, dest='tmin', default=0,
help='Process only stalls lasting the given time, in milliseconds, or longer')
parser.add_argument('-b', '--branch-threshold', type=float, default=0.03,
help='Drop branches responsible for less than this threshold relative to the previous level, not global. (default 3%%)')
Expand Down Expand Up @@ -368,13 +368,12 @@ def main():
# ?? ??:0
if address_threshold:
trace = list(dropwhile(lambda addr: int(addr, 0) >= address_threshold, trace))
tmin = args.minimum or 0
if t >= tmin:
if t >= args.tmin:
graph.process_trace(trace, t)

try:
print_command_line_options(args)
print_stats(tally, tmin)
print_stats(tally, args.tmin)
graph.print_graph(args.direction, args.width, args.branch_threshold)
except BrokenPipeError:
pass
Expand Down

0 comments on commit f8f5875

Please sign in to comment.