Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/usr/share/bcc/tools/trace cannot exit from loops #3049

Closed
realhezhe opened this issue Aug 12, 2020 · 4 comments · Fixed by #4763
Closed

/usr/share/bcc/tools/trace cannot exit from loops #3049

realhezhe opened this issue Aug 12, 2020 · 4 comments · Fixed by #4763

Comments

@realhezhe
Copy link

realhezhe commented Aug 12, 2020

On python 3.8.5 and kernel 5.8
root@intel-x86-64:~# /usr/share/bcc/tools/trace do_sys_openat2 -M 1
PID TID COMM FUNC
179 179 systemd-journal do_sys_openat2
Exception ignored on calling ctypes callback function: <function PerfEventArray.open_perf_buffer..raw_cb at 0x7f2a75f060d0>
Traceback (most recent call last):
File "/usr/lib64/python3.8/site-packages/bcc/table.py", line 685, in raw_cb_
callback(cpu, data, size)
File "/usr/share/bcc/tools/trace", line 630, in print_event
exit()
File "/usr/lib64/python3.8/_sitebuiltins.py", line 26, in call
raise SystemExit(code)
SystemExit: None
The above repeated endlessly

The following change could make it work, but not sure if it's the best way to do.

diff --git a/tools/trace.py b/tools/trace.py
index 7a61594f..d09dd2a8 100755
--- a/tools/trace.py
+++ b/tools/trace.py
@@ -627,7 +627,7 @@ BPF_PERF_OUTPUT(%s);
Probe.event_count += 1
if Probe.max_events is not None and
Probe.event_count >= Probe.max_events:
"- exit()"
"+ os._exit(0)"
sys.stdout.flush()

" def attach(self, bpf, verbose):"

@yonghong-song
Copy link
Collaborator

Maybe sys.exit()?

@yonghong-song
Copy link
Collaborator

It does not fail in my environment with python 3.7

$ sudo trace.py do_sys_openat2 -M 1 
PID     TID     COMM            FUNC             
117055  117055  tmux: server    do_sys_openat2

Do you know why it fails? Maybe due to python site packages?
https://www.geeksforgeeks.org/python-exit-commands-quit-exit-sys-exit-and-os-_exit/

@realhezhe
Copy link
Author

realhezhe commented Aug 13, 2020

sys.exit() and other way would trigger the same call trace.
Seems due to new python update. But it's not easy for me to turn between versions. I'll try.

@nurdann
Copy link
Contributor

nurdann commented Jun 23, 2023

This could be related to #4649

jeromemarchand added a commit to jeromemarchand/bcc that referenced this issue Oct 16, 2023
To exit the tool when the maximal number of event is reached (-M
option), the tool currently call exit(), which raise a SystemExit
exception. The handling of exception from ctype callback doesn't seem
straightforward and dependent on python version.

This patch avoid the issue altogether by using a global variable
instead.

Closes iovisor#3049

Signed-off-by: Jerome Marchand <[email protected]>
yonghong-song pushed a commit that referenced this issue Nov 6, 2023
To exit the tool when the maximal number of event is reached (-M
option), the tool currently call exit(), which raise a SystemExit
exception. The handling of exception from ctype callback doesn't seem
straightforward and dependent on python version.

This patch avoid the issue altogether by using a global variable
instead.

Closes #3049

Signed-off-by: Jerome Marchand <[email protected]>
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 a pull request may close this issue.

3 participants