crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.39k stars 1.62k forks source link

ability to retrieve callstacks of all fibers #4683

Open rdp opened 7 years ago

rdp commented 7 years ago

Sometimes it would be "nice to know" where all the fibers in, say, a web app are currently at, for debug purposes. Or to do periodic profiling, or to profile "hung" processes, etc.

This is the equivalent in Ruby, in case it's helpful: Thread.list.each {|t| puts t.name, t.status, t.backtrace}

Thanks.

rdp commented 7 years ago

update: actually this wouldn't help with "hung" processes (that are using 100% cpu) since they're usually caught in some busy loop or other and wouldn't allow [?] a signal interrupt, but still, useful in some other cases :)

konovod commented 7 years ago

You can get list of fibers https://carc.in/#/r/2b8y but getting the backtrace seems more difficult. I don't quite understand how libunwind works, but maybe it's possible to pass it custom pointer.

nono commented 4 years ago

I find gops really convenient for debugging Go programs, and an equivalent in Crystal would need to be able to retrieve the stack trace for all fibers.

straight-shoota commented 4 years ago

@nono Is that gops trace behaviour?

nono commented 4 years ago

@straight-shoota I was thinking more of gops stack, that displays the goroutines and their stack traces.

Sija commented 3 years ago

ftr, @bcardiff's solution: https://forum.crystal-lang.org/t/finding-where-a-fiber-is-halt/2946

rdp commented 2 years ago

For followers, I got a prototype that "does this" (no idea if it's the "right way" or what have you) at https://github.com/rdp/crystal/tree/bt5 . I hope to clean it up someday and submit a PR... :)

straight-shoota commented 1 year ago

There is a fiber trace implementation available in https://github.com/crystal-lang/perf-tools/blob/main/src/perf_tools/fiber_trace.cr