# Profiling Interface

### Profiler Operation

The following methods can be used by dynamic profiler methods to monitor different aspects of the program.

A custom profiler will have one public method defined in the shared library which is the entry point that Mono calls at startup, it has the following signature:

    	void mono_profiler_startup (const char *desc)

Where "desc" is the set of arguments that were passed from the command line. This routine will call `mono_profiler_install` to activate the profiler and will install one or more filters (one of the various `mono_profiler_install_` functions).

In addition, a profiler developer will typically call `mono_profiler_set_events` to register which kinds of traces should be enabled, these can be an OR-ed combination of the following:

    	MONO_PROFILE_NONE
            MONO_PROFILE_APPDOMAIN_EVENTS
            MONO_PROFILE_ASSEMBLY_EVENTS
            MONO_PROFILE_MODULE_EVENTS
            MONO_PROFILE_CLASS_EVENTS
            MONO_PROFILE_JIT_COMPILATION
            MONO_PROFILE_INLINING
            MONO_PROFILE_EXCEPTIONS
            MONO_PROFILE_ALLOCATIONS
            MONO_PROFILE_GC
            MONO_PROFILE_THREADS
            MONO_PROFILE_REMOTING
            MONO_PROFILE_TRANSITIONS
            MONO_PROFILE_ENTER_LEAVE
            MONO_PROFILE_COVERAGE
            MONO_PROFILE_INS_COVERAGE
            MONO_PROFILE_STATISTICAL

Developers can change the set of monitored events at runtime by calling `mono_profiler_set_events`.
`mono_profiler_install`
Syntax
void mono_profiler_install (MonoProfiler *prof, MonoProfileFunc callback)

Parameters

prof | a MonoProfiler structure pointer, or a pointer to a derived structure.
callback | the function to invoke at shutdown

Description

Use mono_profiler_install to activate profiling in the Mono runtime. Typically developers of new profilers will create a new structure whose first field is a MonoProfiler and put any extra information that they need to access from the various profiling callbacks there.

`mono_profiler_install_allocation`
Syntax
mono_profiler_install_allocation

`mono_profiler_install_appdomain`
Syntax
mono_profiler_install_appdomain

`mono_profiler_install_assembly`
Syntax
mono_profiler_install_assembly

`mono_profiler_install_class`
Syntax
mono_profiler_install_class

`mono_profiler_install_coverage_filter`
Syntax
mono_profiler_install_coverage_filter

`mono_profiler_install_enter_leave`
Syntax
void mono_profiler_install_enter_leave (MonoProfileMethodFunc enter, MonoProfileMethodFunc fleave)

Parameters

enter | the routine to be called on each method entry
fleave | the routine to be called each time a method returns

Description

Use this routine to install routines that will be called everytime a method enters and leaves. The routines will receive as an argument the MonoMethod representing the method that is entering or leaving.
`mono_profiler_install_jit_compile`
Syntax
void mono_profiler_install_jit_compile (MonoProfileMethodFunc start, MonoProfileMethodResult end)

Parameters

start | the routine to be called when the JIT process starts.
end | the routine to be called when the JIT process ends.

Description

Use this routine to install routines that will be called when JIT compilation of a method starts and completes.
`mono_profiler_install_module`
Syntax
mono_profiler_install_module

`mono_profiler_install_thread`
Syntax
mono_profiler_install_thread

`mono_profiler_install_transition`
Syntax
mono_profiler_install_transition

`mono_profiler_install_gc`
Syntax
mono_profiler_install_gc

`mono_profiler_install_statistical`
Syntax
mono_profiler_install_statistical

`mono_profiler_set_events`
Syntax
void mono_profiler_set_events (MonoProfileFlags events)

Parameters

events | an ORed set of values made up of MONO_PROFILER_ flags

Description

The events descriped in the events argument is a set of flags that represent which profiling events must be triggered. For example if you have registered a set of methods for tracking JIT compilation start and end with mono_profiler_install_jit_compile, you will want to pass the MONO_PROFILE_JIT_COMPILATION flag to this routine.

You can call mono_profile_set_events more than once and you can do this at runtime to modify which methods are invoked.
`mono_profiler_get_events`
Syntax
MonoProfileFlags mono_profiler_get_events (void)

Description

Returns a list of active events that will be intercepted.

### Coverage

To support profiling modules that need to do code coverage analysis, the following routines is provided: