[Mono-dev] Mono profiler agent for jitted code

Paolo Molaro lupus at ximian.com
Mon Apr 3 06:31:30 EDT 2006

On 03/31/06 Yeh, Jason wrote:
> I have been working on a proposal to extend Oprofile to profile the
> "anonymous samples" resulted from jitted code.  I am not familiar enough
> with Mono to determine how such profiler will benefit Mono.  I would
> like to know if such profiler would benefit Mono, and also how would you
> use this profiler if it is available.  

Having oprofile properly support JITs would be excellent: we certainly
can use it.
We already have a statistical profiler that uses either setitimer()
or /dev/rtc to get samples of the app behaviour. Having oprofile support
JITs we could also enable support for sampling based on cache misses and
so on and this would help us a lot in tuning the mono runtime and the apps
that run on mono.
The important properties we'd like to see from oprofile are:
*) handle jitted methods (code stored in non-file-backed memory)
*) not require root privs (at least for a subset of the capabilities or
with limits designed to reduce the number of interrupts per second)
*) have the counters virtualized per process (this may be already the
case, I haven't looked at oprofile in a long time)

If these features were available we could gather all the interesting
info the cpus can have counters for and we could not only have a
offline profiler, but we could also use it to do dynamic profiling: this
would enable us to recompile hot methods with more aggressive
optimizations at runtime etc.

> If this profiler can benefit Mono, I would like to write a profile agent
> for Mono and make sure that it will work with Mono.  It would also be
> great if someone can point me the files that I should check if I ever
> need to look at how Mono creates jit code.

We have a profiling interface: it is defined in mono/metadta/profiler.h.
What you'd likely want to do is create a profile module (mono can load
them at runtime) that intercepts JIT compilation. The MonoProfileJitResult
callback will allow you to get some info about a jitted method (like the
address and the size in memory).
The mono/metadata/profiler.c file also contains our sample profiler
that you might want to look at for ideas on how to implement your agent.
As for the JIT sources, they are in the mono/mini/ directory, but you'll
likely only need to deal with the profiling interface.
Let me know if you have any other question.


lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better

More information about the Mono-devel-list mailing list