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

trace: Allow function signatures in uprobes and kprobes #911

Merged
merged 1 commit into from
Jan 17, 2017

Conversation

goldshtn
Copy link
Collaborator

trace now allows uprobes and kprobes to have function signatures,
which means function parameters can be named and typed, rather than
relying on the positional arg1, arg2, etc. arguments. This also
enables structure field access, which is impossible with the unnamed
arguments due to rewriter limitations.

The example requested by @brendangregg, which now works, is the
following:

# trace 'p::SyS_nanosleep(struct timespec *ts) "sleep for %lld ns", ts->tv_nsec'
PID    TID    COMM         FUNC             -
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
^C

Resolves #907.

§`trace` now allows uprobes and kprobes to have function signatures,
which means function parameters can be named and typed, rather than
relying on the positional arg1, arg2, etc. arguments. This also
enables structure field access, which is impossible with the unnamed
arguments due to rewriter limitations.

The example requested by @brendangregg, which now works, is the
following:

§Â```
PID    TID    COMM         FUNC             -
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
777    785    automount    SyS_nanosleep    sleep for 500000000 ns
^C
```
@4ast
Copy link
Member

4ast commented Jan 17, 2017

looks pretty cool. merging now. If @brendangregg finds issues, they can be fixed afterwards :)

@4ast 4ast merged commit 3cc4c0a into iovisor:master Jan 17, 2017
@brendangregg
Copy link
Member

Awesome @goldshtn, thanks! I just tried it out, and it works:

# trace 'p::SyS_nanosleep(struct timespec *ts) "sleep for %d s %lld ns", ts->tv_sec, ts->tv_nsec'
PID    TID    COMM         FUNC             -
1009   1009   iscsid       SyS_nanosleep    sleep for 1 s 0 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1 s 0 ns
20291  20291  sleep        SyS_nanosleep    sleep for 0 s 500000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1 s 0 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1 s 0 ns
806    806    cron         SyS_nanosleep    sleep for 60 s 0 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1 s 0 ns

Someone's going to look at this and ask why it can't be:

# trace 'p::SyS_nanosleep(struct timespec *ts) "sleep for %.1f s", (ts->tv_sec + ts->tv_nsec/1000000000)'

And I'd say that's taking it too far (floats, etc). What works right now is enough.

... although I noticed this happens to work:

trace 'p::SyS_nanosleep(struct timespec *ts) "sleep for %d ns", (ts->tv_sec * 1000000000 + ts->tv_nsec)'
PID    TID    COMM         FUNC             -
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns
20308  20308  sleep        SyS_nanosleep    sleep for 500000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns

Ok, sure, then we can just:

# stdbuf -oL trace 'p::SyS_nanosleep(struct timespec *ts) "sleep for %d ns", (ts->tv_sec * 1000000000 + ts->tv_nsec)' | awk '{ printf "%s (%.1f s)\n", $0, $(NF-1) / 1000000000; }'
PID    TID    COMM         FUNC             - (0.0 s)
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns (1.0 s)
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns (1.0 s)
20317  20317  sleep        SyS_nanosleep    sleep for 500000000 ns (0.5 s)
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns (1.0 s)
1009   1009   iscsid       SyS_nanosleep    sleep for 1000000000 ns (1.0 s)

if we really had to. Again, I don't think trace needs to do anything more -- what's there gives us the data we need. Thanks!

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