Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Rust compiler have a profiling option?

Tags:

profiling

rust

I have a Rust program that isn't running as fast as I think it should. Is there a way to tell the compiler to instrument the binary to generate profiling information?

I mean something like GCC's -p and -pg options or GHC's -prof.

like image 684
Jason Orendorff Avatar asked Dec 20 '22 04:12

Jason Orendorff


2 Answers

The compiler doesn't support any form of instrumentation specifically for profiling (like -p/-pg/-prof), but compiled Rust programs can be profiled under tools that do not require custom instrumentation, such as Instruments on OS X, and perf or callgrind on Linux.

I believe such tools support using DWARF debuginfo (as emitted by -g) to provide more detailed performance diagnostics (per-line etc.), but enabling optimisations play havoc with the debug info, and it's never really worked for me. When I'm analysing performance, diving into the asm is very common.

Making this easier would be really nice, and tooling is definitely a post-1.0 priority.

like image 174
huon Avatar answered Dec 24 '22 22:12

huon


There's no direct switch that I'm aware of. However, I've successfully compiled my code with optimizations enabled as well as debugging symbols. I can then use OS X's Instruments to profile the code. Other people have used KCachegrind on Linux systems to the same effect.

like image 39
Shepmaster Avatar answered Dec 24 '22 22:12

Shepmaster