The Crystal Programming Language Forum

Feature request: "trace method calls" compilation mode

Similar to ruby’s “-rtracer” functionality, it would be grand to be able to have a crystal method “trace” functionality, like…it just does a printf to the screen of the method name + parameters + line number for each method call that’s made. I assume this would be a compiler flag or some odd…

Where it would be helpful: sometimes there’s an obscure bug in crystal’s http (or openssl?) server code where it uses 100% cpu. It would be nice to be able to “show all that it’s doing” to trace it when it does that, and when I use gdb + sampling I’m never quite certain if I’m getting it all or not…
Though theoretically gdb’s “step” method should be enough for me to jump in and do that. But never seems to work quite right. Maybe that could be fixed instead :)

Second reason it’d be good: sometimes there is little visibility into fibers that are waiting on sockets. It’d be nice to know where those fibers “last lived at” to see what all’s going on.
Though theoretically if there were a “Thread.all_backtraces” method that would show about the same functionality. Maybe that could be added instead :)

Just brainstorming I guess :)

Fiber backtraces: https://github.com/crystal-lang/crystal/issues/6461

Or just outputting once “per line executed” would work as well for the tracer option :)

Turns out that by kind of “extrapolating” from the most common backtraces you can kind of tell the main method where the cpu is being used (i.e. extrapolating from the 30 traces of the gdb style poor man profiler LOL). So that…barely works already. -rtracer tends to be way too much output sometimes… :)