Search code examples
visual-studiovisual-studio-2010debuggingbreakpointslines-of-code

Count lines of code while debugging in Visual Studio


Is there some way in Visual Studio 2010 to count the number of lines of code that are executed while debugging? If so, is there a way to count something like the total LOC executed between 2 breakpoints?

I'm aware that Visual Studio can count LOC for whole project(s)/solution, and has code coverage metrics based on unit tests, but unfortunately the code I'm trying to get LOC for does not have any associated unit tests.


Solution

  • If you dont have any unit tests you can still instrument the assembly you would like to profile and get coverage data on it.

    Using Visual Studio tools you can do:

    vsinstr /coverage %PROJECT%
    
    vsperfcmd /start:coverage /output:"%OUTPUT_FILE_NAME%.coverage"
    
    //run your test
    
    vsperfcmd /shutdown
    

    Now you can check the out file with the coverage based on your test

    For .Net stuff you usually get block of code which are slightly different than LOC but you can add LOC when viewing the .coverage file