

So now you can for instance start counting which methods get called the most across any namespace you want to monitor - which by the way is one of the typical performance killers for developers who are fond of Linq without actually understanding how it works under the covers.Often times, we have to write code to perform tasks whose complexity vary from mundane, such as retrieving and organizing data, to highly complex, such as simulations CFD simulations comprising the spine of a project. MonitorInstrumentationFlags.MethodArguments | MonitorInstrumentationFlags.UnwindMethod,// | MonitorInstrumentationFlags.EnterLeaveMethod | Using (var process = Process.Start(startInfo))ĬontrollerSetUp.SetMonitoringEnvironmentVariables(

StartInfo.EnvironmentVariables = (string)de.Value SetMonitoringEnvironment(userAssembly, userType, env) Var startInfo = new ProcessStartInfo(application, null) Var application = args // For instance, ConsoleApplication1.exe

Here are a few code snippets from the initialization: The “Tracing” sample contains a ready-made implementation of a CLR profiler in C# that you can extend to fit your purposes. In order to get to that, you will have to download and install the original PEX and then go to this folder:Ĭ:\Program Files\Microsoft Pex\Documentation\pex.samples\samples\ExtendedReflection The was primarily for PEX to use, but a little bit of documentation was released along with a few samples. And to do that, they implemented the C++ profiling interfaces and wrapped it all up in the publicly available.

In order for PEX to work its magic - and if you don’t know what that is, you should follow the link above and also check out the Code Digger VS Extension - the team needed to be able to instrument every single bit of code produced by the C# compiler. That’s all been made possible because of the excellent work done by the Microsoft Research team that built PEX (and Moles) a couple of years ago. However, it is feasible to build a CLR profiler in C# that can be used during development and testing for things such as memory and code analysis on servers where Visual Studio is not available. If you are interested in knowing more about how to build one, here are two excellent sources: Before we go any further, I’d like to clarify something: It is not feasible to create a high-performance live CLR profiler in C#, because of the way the core profiling API and the CLR works.
