Open rdp opened 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 :)
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.
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.
@nono Is that gops trace
behaviour?
@straight-shoota I was thinking more of gops stack
, that displays the goroutines and their stack traces.
ftr, @bcardiff's solution: https://forum.crystal-lang.org/t/finding-where-a-fiber-is-halt/2946
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... :)
There is a fiber trace implementation available in https://github.com/crystal-lang/perf-tools/blob/main/src/perf_tools/fiber_trace.cr
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.