Reputation: 27275
I'm trying to write a .NET application that can profile other .NET processes and list all the calls that have been made by them including the values of the passed parameters.
I understand that writing my own profiler with something like "ICorProfilerCallback2" can help on this but it seems like a quite challenging task. Before undertaking it I want to be sure that's the only way to do this.
I looked into open source .NET profilers and alike such as part-cover, CLR Profiler v4.0 etc. but none of them seems like provide a managed API to do this, and they do much more than what I need (memory profiling etc.).
Is there any other way to do this? An easier way to do this kind of profiling? What are my options in here?
Upvotes: 5
Views: 547
Reputation: 3123
We once wrote such a tool using Mono Cecil.
With Cecil you can emit IL code into existing assemblies. This way you can add calls to a managed DLL of yours at the beginning of each method.
However the IL-injection is quite tricky as there are many cases to consider, but it is feasible. On the bright side: Once your managed DLL was called all your code can be written in a high-level way (e.g. C#), so the "only" tricky part is weaving the calls to your API.
A workflow using Cecil instrumentation could look like this:
Upvotes: 1