Can CCI be used for profiling?

Jun 10, 2011 at 12:49 PM


I am profiling Asp.Net applications. I use the .Net profiling API (COM interfaces) for profiling. I stumbled upon this project. I am curious to know if profiling can be done with CCI. I read that IL rewriting is possible, so if you can let me know if any profiling is possible? 


Jun 10, 2011 at 1:56 PM

You can certainly use CCI to rewrite assemblies so that they contain instrumentation that will gather a profile when run. In fact, I'm currently working on an Edge profiler. I'll put that out as a sample when I'm done (perhaps in a week or so).

It may, however, be quite a bit of work to provide infrastructure that works with the .NET profiling API and all the VS goodies that come with it. I have no immediate plans to work on that.

Jun 13, 2011 at 9:29 AM

Thanks a lot, Herman. I would love to see the Edge profiler. Let us know when it is ready.. Thanks for sharing.. 

Jun 16, 2011 at 9:36 PM

I have now checked in a sample application, EdgeProfiler, that takes a single executable file (*.exe) and rewrites it as an *.instrumented.exe, which when run produces *.profile, which is a binary file containing a count for every basic block to basic block edge traversed during the last execution. The existing CdfgToText sample has now been enhanced to read in such profiles, if available, and to incorporate the counts in the textual output.

Not supremely useful by itself, but it should suffice to illustrate IL level rewriting using the control and data flow graph library.

Sep 2, 2011 at 3:34 PM
Edited Sep 2, 2011 at 4:15 PM

Thanks for the very interesting sample. I was looking into what might be required to make a simple profiler using CCI and this example is both useful and interesting. I would be curious to hear any comments from people using CCI for hooking up profiling logic to existing assemblies. It would be particularly helpful if the sample could be extended to a primitive profiler that included method execution time data.

I spent some time today trying to do just that, and I made some progress but I'm expecting to not get much further without committing more time than I have right now. I modified the Logger class to use a StackTrace to recover information about the method being profiled, which is appended with "_CountersXXX.DumpCounters()" (XXX is a number). I was experimenting with tracking hit counts with a dictionary using this string as a key but I am not sure how to get the dictionary to be dumped to the log when the application exits. Presumably, a hook would need to be added somewhere else - is there a way to hook into the app during the shutdown operation? Also, I'm not sure how to determine the execution time of a method because the existing sample seems to only trigger log events when methods are entered; presumably I would need to pair each entry with an exit in order to track the elapsed time. Anyone have an idea how this might be achieved?

Thanks for any suggestions!