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

[performance] deferred stacktrace symbolication #4

Closed
timotheecour opened this issue Mar 8, 2020 · 3 comments
Closed

[performance] deferred stacktrace symbolication #4

timotheecour opened this issue Mar 8, 2020 · 3 comments

Comments

@timotheecour
Copy link
Contributor

I can provide a benchmark showing this could make a significant difference if needed to justify this feature.
The idea is to collect backtraces as efficiently as possible, and symbolicate them at a later time, via a proc:

proc symbolicate(result: var string, addresses: ptr ByteAddress, len: int)

where addresses are provided for eg via backtrace (see http://man7.org/linux/man-pages/man3/backtrace.3.html)
and the symbolication is provided via libbacktrace; I don't know whether libbacktrace supports symbolication "after the fact" given an array of addresses, hopfully it should (just needs to read and symbolicate DWARF info attached to input addresses, in theory)

use cases

  • nimprof, which collects at regular intervals a full backtrace, and then aggregates these to produce profiling data (at granularity of full backtraces, not just individual function calls)
  • (I need to verify this one) IIUC right now you pay a penalty with try/catch by symbolicating the trace even if user doesn't require symbolication (eg via getStacktrace(e)); this feature would make symbolication lazy, ie as needed; resulting in faster exception handling (in the common case where a caught exception isn't symbolicated)

note

(somewhat related)
nim's own standard backtrace approach could be made much more efficient it it didn't symbolicate at every frame (by having a filename, procname line info etc at each TFrame); instead all it'd need would be to have at each frame a unique int index pointing to a debug info that could be stored somewhere else.

note

that debug info could even in a separate file so we can "strip" debug info from a binary while retaining ability to generate symbolicated stacktraces in a separate process; this feature is useful (and in heavy use) eg when shipping stripped binaries to your clients, collecting stacktraces as opaque addresses, and symbolicating on a remote server.

links

D's approach: uses something a bit similar, on thrown exception, we just collect addresses (eg via backtrace), and at a later time, when needed, we symbolicate, see https://github.com/dlang/druntime/blob/master/src/rt/backtrace/dwarf.d

@arnetheduck
Copy link
Member

@timotheecour do you plan to work on this / provide a PR and you're looking for implementation feedback?

otherwise, efficient stack tracing is something of a solved problem should one wish to implement it - ie it's been around for decades in other toolchains so if we wanted to, we know how to do it and there's really no need to open issues about it.

@timotheecour
Copy link
Contributor Author

I may at a later point in time, but not at the moment. Feel free to close but IMO this is more likely to be addressed (including by external contributors) if there's an issue tracking it.

@stefantalpalaru
Copy link
Contributor

Fixed in 3ff163c

Now waiting for the corresponding Nim stdlib changes to be merged, so we can use it with exceptions.

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

No branches or pull requests

3 participants