Code Analysis from Common Intermediate Language (CIL)

551 Views Asked by At

I would like to do some fairly basic program analysis on my .NET code (which is a combination of .dlls, .exe and C# code). Using Microsoft's Common Compiler Infrastructure, I first converted the code to it's IL form using which I would like to construct a call graph. Once I have the call graph, are there some standard tools that can be leveraged in order to gain insights in code complexity, identifying bottlenecks, memory footprint etc.? Any pointers would be really appreciated!

1

There are 1 best solutions below

5
On

I think what you want is pretty much impossible. The count of object allocations could vary wildly depending on specific input.

For example, imagine there was a method in your program that allocated a lot of objects, but it would run only under some condition. If your analysis was to asses the count of object allocations accurately, it would need to know whether the method ran. And the only way to do that is to actually evaluate that condition, which means you would actually need to run the program.

And memory footprint is probably even more difficult: it would require you to track the complete object graph and simulate the GC.

In short: the best way to find out performance characteristics of your program is to actually run it. Doing the same using static analysis would be hard and inaccurate. Don't forget that it's impossible to find out whether program completes using static analysis. I think what you want is even more difficult.