Reputation: 131
imagine that you are given a big nice app in C#, with full source code. So you want to figure out what methods are executed when you do a user event, e.g. press a button or press a hotkey or whatever. The codebase is so big that you don't feel like looking for the relevant part of the code manually, e.g. tracking down the event handler for that button.
Well, is there a straightforward automated way to obtain some sort of a log of methods being executed beginning with time T (which is when I press the button)? Could you explain and/or provide links to articles dealing specifically with this situation?
Upvotes: 1
Views: 636
Reputation: 13944
A code coverage tool, which others describe, leverages the ability to profile code. The underpinnings of a code coverage tool are that it uses an application profiler, and is programmed to perform source code matching and line hit counts as part of its profiling. In the case of .NET, code coverage and other profiling tools will be leveraging the .NET Profiling API. Even NCover.
Other tools exist which may provide you more of a log-activity that you are looking for, rather than line-hit-counts. You can even work on programming your own profiling application which might log to a special XML file, and then digitally sign it, timestamp it, and upload it to a server process.
Consider looking for code profiling tools, not simply code coverage tools, which are one use case for a profiler.
Upvotes: 2
Reputation: 28824
I'm sure somebody could write a macro that will programatically add break points to all event handlers!!
visual studio 2010 has the method hierarchy view which is reallly nice, but it's not available in 2008
Upvotes: 0
Reputation: 838116
You can use C# Visual Studio Express and set a breakpoint in the code, then use step debugging from the IDE. You can also find out what code is executed when a button is pressed by double-clicking the button in designer mode. It takes you straight to the relevant code, and you can just put a break point there and then run the application.
There's no rule that says you can't use VS to debug an open source app, even though VS is closed source. And it's free, so why not?
Upvotes: 0
Reputation: 56113
The list of methods executed is called "code coverage".
There are tools called "code coverage analyzers" which log the methods called: this is useful when testing code, when you have one or more test cases and want to know what methods the tests are 'covering'.
One example of such a tool for C# is called NCover: for links to this and other tools, see Code Coverage for C#/.net.
Upvotes: 1