Profiling based on instrumentation

Currently, we can do sampling based profiling. But how can we do instrumentation based profiling?

In gcc, there are -pg and -finstrument-functions options for generating a special instruction for entries of functions. And the instruction is utilized for profiling.
Also, LLVM has similar thing called to xray.

Is there no way to generate those instructions like them in rustc?
If there is no way, I think that we must consider adding the way to rustc.

1 Like

There's https://github.com/llogiq/flamer which does something similar.

Thanks to your reply!
flamer is somewhat similar to what I want.
But, it is not enough and has limitations.

  1. Need to modify existing codes.
    • We must add some codes to all .rs files for using flamer.
  2. Only supports flame.
    • flamer only supports flame. It is not flexible.

In gcc, -pg and -finstrument-function options add a special call instruction to every functions. And instrumentation based profilers work by hooking the called function to their functions.
It is very flexible and extendable way.
I think this feature should be added to rustc.

It was addressed in https://github.com/rust-lang/rust/pull/57220!!
And we may be able to use that feature in next rust release.