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

Better stack walking APIs #448

Merged
merged 2 commits into from
Mar 27, 2016
Merged

Better stack walking APIs #448

merged 2 commits into from
Mar 27, 2016

Conversation

vmg
Copy link
Contributor

@vmg vmg commented Mar 26, 2016

Hi folks!

Here's a hot take on replacing @brendangregg's lovingly crafted eBPF stack walker code (teehee) with the brand new StackTrace table APIs.

I totally get the kernel is not quite there yet, but the APIs in Torvald's mainline seem to be stabilized now and running a nightly kernel makes this work like a charm. I'll just twiddle my fingers until 4.6 comes out, but I wanted to open this PR early to discuss it. 👌

Looking at the (minimal) changes, the design for the new table seems just right, and the resulting Python APIs make all the stack-related code significantly simpler. Details on the changes are described in each individual commit message.

There's a couple points I'm not sure about -- I'm leaving inline comments with questions.

Thanks for the amazing work with bcc. This is by far the coolest thing going on right now re. perf work in Linux.

vmg added 2 commits March 25, 2016 17:12
The StackWalker iterator lets us call `stack_trace.walk(id)` to iterate
through the addresses in any given stack. The constructor of this
iterator takes an optional `resolver` to convert the addresses in the
iterator into symbols (or to format them according to the users' needs).
This simple example script traces all calls to `malloc` in a process and
prints the callsite using the new `BPF_STACK_TRACE` table API.
@@ -412,9 +412,37 @@ def __init__(self, *args, **kwargs):
raise Exception("Unsupported")

class StackTrace(TableBase):
MAX_DEPTH = 127
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is hardcoded in the kernel. I am not sure whether it'd be worth it to dig into the FFI ctypes to figure it out dynamically. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4ast it makes sense to me to leave this unless the kernel value is ever likely to change. How likely is that?

The problem with getting this dynamically will be that the kernel headers may update but the libc-headers, where the userspace value of this will be most readily available, is very slow to update. I tend to come across (and am one myself) lagging userspace header files, which is why bcc includes a bunch of compat header files and hardcoded things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PERF_MAX_STACK_DEPTH is highly unlikely to change. All sorts of abi concerns will pop up, including increase in size of perf.data files, since 127 is also default for 'perf record -g'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Let's leave it hardcoded then.

@goldshtn
Copy link
Collaborator

Looks awesome!

By the way, when this gets merged, the man and example files also need to be updated to point out that the stack support is not experimental anymore, and to remove the stack depth command line arguments.

@drzaeus77
Copy link
Collaborator

It might make sense to split out the updates to table.py into a separate PR, since that can merge right away, while the others we might want to discuss about backwards compat.

@brendangregg
Copy link
Member

Thanks! I was looking for this specific support yesterday and saw it hadn't been done yet.

Might want a hello world simple example in /examples, or, (either now or later) we can update stackcount/stacksnoop in /tools which can serve as the same thing.

Also, as tools get rewritten to use the new stack support, I'd put old copies of those tools (which used unrolling hacks) in /tools/old -- particularly for Ubuntu Xenial users.

FWIW, the stackdepth limit of 127 will be suitable for many cases, but we're already exceeding it for Java/Groovy stacks (which can get as deep as >512).

@goldshtn
Copy link
Collaborator

While we are at it, would it make sense to extend the user symbol resolution support with data from perf-map-agent? That would give us call stacks for Java and Node, right? @brendangregg

@brendangregg
Copy link
Member

@goldshtn right, it does make sense, now or later. User symbol resolution should check for /tmp/perf-PID.map files. Format is tools/perf/Documentation/jit-interface.txt .

@vmg vmg mentioned this pull request Mar 27, 2016
4 tasks
@vmg
Copy link
Contributor Author

vmg commented Mar 27, 2016

It might make sense to split out the updates to table.py into a separate PR, since that can merge right away, while the others we might want to discuss about backwards compat.

Done! This PR now only contains the changes to table.py and a Hello World example (examples/tracing/mallocstacks.py) as suggested by @brendangregg.

I've opened #450 where I'm working on converting the actual tools to use 4.6.

By the way, when this gets merged, the man and example files also need to be updated to point out that the stack support is not experimental anymore, and to remove the stack depth command line arguments.

This is done in #450.

Also, as tools get rewritten to use the new stack support, I'd put old copies of those tools (which used unrolling hacks) in /tools/old -- particularly for Ubuntu Xenial users.

Also done in #450 👌

@vmg vmg changed the title I'm thirsty for stacks! Better stack walking APIs Mar 27, 2016
@drzaeus77 drzaeus77 merged commit 478636b into iovisor:master Mar 27, 2016
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.

None yet

5 participants