I want to use a .NET profiler to trace the called functions of an application. I used CLR Profiler as a template, but didn't change the profiler (Project ProfilerOBJ
) itself (except the GUID). When I try to profile an application the enter/leave function hooks (besides other callbacks like JITCompilationStarted
) are not called. But there are also some callbacks which are called (e.g. Shutdown
) (which tells me that the profiler is loaded in the process).
I tried running the processes in 32 and 64 bit (with 64 bit the function hooks seem to be defined somewhere) without success.
The test application I profiled is as follows:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press Enter to allocate object");
Console.ReadLine();
var obj = new Person();
Console.WriteLine("Press Enter to call method on allocated object");
Console.ReadLine();
obj.Walk();
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
}
}
class Person
{
private int walked = 0;
public void Walk()
{
this.walked++;
}
}
I expected at least the callbacks ICorProfilerCallback::ObjectAllocated
and the enter/leave function hooks to be called. But the only callback called was ICorProfilerCallback::Shutdown
.
It seems that even the original CLR profiler's enter/leave function hooks are not called (I tried to output a message in the callback).
What am I missing? Is there more to do than registering the enter/leave function hooks? Or am I making wrong assumptions about the enter/leave function hooks?
I just read that there are additional flags you may set to specify in which events you are interested. One of them is COR_PRF_MONITOR_ENTERLEAVE
which does exactly what I was looking for. Thanks rubberduck.