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

Add BPF python helpers for reading trace_pipe #156

Merged
merged 1 commit into from
Aug 21, 2015
Merged

Add BPF python helpers for reading trace_pipe #156

merged 1 commit into from
Aug 21, 2015

Conversation

drzaeus77
Copy link
Collaborator

Signed-off-by: Brenden Blanco bblanco@plumgrid.com

Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
4ast pushed a commit that referenced this pull request Aug 21, 2015
Add BPF python helpers for reading trace_pipe
@4ast 4ast merged commit 29856f6 into master Aug 21, 2015
@brendangregg
Copy link
Member

Sorry to overload, but here's 3 small suggestions:

  1. I'd default trace_readline() to blocking, given the nature of these tools. I forgot to set it to false (like it is in trace_print()) and got this:
# python3 syncsnoop
TIME(s)            CALL
Traceback (most recent call last):
  File "syncsnoop", line 33, in <module>
    line = b.trace_readline()
  File "/usr/lib/python3/dist-packages/bpf/__init__.py", line 422, in trace_readline
    trace = BPF.trace_open(nonblocking)
  File "/usr/lib/python3/dist-packages/bpf/__init__.py", line 409, in trace_open
    fd = trace.fileno()
NameError: name 'trace' is not defined
  1. I'd also seriously consider making this exception handling inbuilt to trace_readline():
        try:
                line = b.trace_readline()
        except KeyboardInterrupt:
                pass; exit()

So we can just call b.trace_readline().

This means a Ctrl-C will always exit() the program if you are using trace_readline(). I think this is desirable, since the signal means a human has hit Ctrl-C, and the common expected behavior would be to exit. (This exception handling should be the same with #149 as well). It'll save some boilerplate in many common scripts.

  1. Is there a way to define BlockingIOError for python 2.6?:
# ../examples/hello_world.py
            bash-14044 [001] d... 29450763.501397: : Hello, World!
^CTraceback (most recent call last):
  File "../examples/hello_world.py", line 19, in <module>
    b.trace_print()
  File "/usr/lib/python2.7/dist-packages/bpf/__init__.py", line 435, in trace_print
    line = BPF.trace_readline(nonblocking=False)
  File "/usr/lib/python2.7/dist-packages/bpf/__init__.py", line 427, in trace_readline
    except BlockingIOError:
NameError: global name 'BlockingIOError' is not defined

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.

3 participants