Skip to content

tools/ustat: Properly handle SIGINT in ustat#5498

Open
jeromemarchand wants to merge 1 commit intoiovisor:masterfrom
jeromemarchand:ustat-sigint
Open

tools/ustat: Properly handle SIGINT in ustat#5498
jeromemarchand wants to merge 1 commit intoiovisor:masterfrom
jeromemarchand:ustat-sigint

Conversation

@jeromemarchand
Copy link
Copy Markdown
Contributor

Most interactive tools waiting for a keyboard interrupt just expect it during sleep() call. In most case it works well enough since most of the time is typically spend in sleep. In the case of tclstat however, the tool can spend a lot of time detaching uprobes, in self.bpf.cleanup() more specifically and it fails when CTRL+C is pressed.

Fix this by catching the SIGINT signal. We still want to raise KeyboardInterrupt while sleeping though, for the tool to exit immediately when possible.

Fixes the following error:
10:12:42 loadavg: 0.03 0.05 0.01 2/289 21928

PID CMDLINE METHOD/s GC/s OBJNEW/s CLOAD/s EXC/s THR/s
21926 tclsh ./fib.tcl 2 2 0 8 0 0 0
^Cioctl(PERF_EVENT_IOC_DISABLE) failed: Bad file descriptor
close perf event FD failed: Bad file descriptor
Exception ignored in atexit callback: <bound method BPF.cleanup of <bcc.BPF object at 0x7f00481bbc20>>
Traceback (most recent call last):
File "/usr/lib/python3.12/site-packages/bcc/init.py", line 1855, in cleanup
self.detach_uprobe_event(k)
File "/usr/lib/python3.12/site-packages/bcc/init.py", line 1507, in detach_uprobe_event
raise Exception("Failed to detach BPF from uprobe")
Exception: Failed to detach BPF from uprobe

Most interactive tools waiting for a keyboard interrupt just expect it
during sleep() call. In most case it works well enough since most of
the time is typically spend in sleep. In the case of tclstat however, the
tool can spend a lot of time detaching uprobes, in self.bpf.cleanup() more
specifically and it fails when CTRL+C is pressed.

Fix this by catching the SIGINT signal. We still want to raise
KeyboardInterrupt while sleeping though, for the tool to exit
immediately when possible.

Fixes the following error:
10:12:42 loadavg: 0.03 0.05 0.01 2/289 21928

PID    CMDLINE              METHOD/s   GC/s   OBJNEW/s   CLOAD/s  EXC/s  THR/s
21926  tclsh ./fib.tcl 2    2          0      8          0        0      0
^Cioctl(PERF_EVENT_IOC_DISABLE) failed: Bad file descriptor
close perf event FD failed: Bad file descriptor
Exception ignored in atexit callback: <bound method BPF.cleanup of <bcc.BPF object at 0x7f00481bbc20>>
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/bcc/__init__.py", line 1855, in cleanup
    self.detach_uprobe_event(k)
  File "/usr/lib/python3.12/site-packages/bcc/__init__.py", line 1507, in detach_uprobe_event
    raise Exception("Failed to detach BPF from uprobe")
Exception: Failed to detach BPF from uprobe

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant