Team System Developer Center > Visual Studio Team System Forums > Visual Studio Performance Tools (Profiler) > Code coverage for C++: thousands of "Global Functions" in coverage results
Ask a questionAsk a question
 

AnswerCode coverage for C++: thousands of "Global Functions" in coverage results

  • Tuesday, September 02, 2008 8:54 PMSteve Hines Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm working on a project in C++ for which we have unit test harnesses written using CppUnit. The unit test harnesses are linked with /profile, and an automated script automatically runs vsinstr on them, starts the profiler, runs the tests, and shuts down the profiler.

     

    The .coverage file that results has a line item for each unit test harness named "Global Functions" that includes thousands of functions from the CRT library. Can someone tell me if there any way to exclude these CRT library functions from code coverage results?

     

     

    Thanks,

    Steve

Answers

  • Thursday, September 11, 2008 6:07 AMChris SchmichMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Unfortunately, the only filtering we currently have is name-based.  You can specify /exclude multiple times, though, so you could specifically exclude each global CRT function.  For example, you could create a response file (call it foo.rsp) with the following contents:

     

    /exclude:CRTGlobalFunc1

    /exclude:CRTGlobalFunc2

    ...

    /exclude:CRTGlobalFuncN

    mybinary.exe

     

    Then, you could invoke vsinstr as such:

     

    vsinstr @foo.rsp

     

    Taking a step back, are you statically linking the CRT?  If you dynamically link it instead, the global CRT functions should be in a separate, non-instrumented DLL and then you shouldn't get coverage numbers for them.  Is this the case?

     

    This is actually the correct forum for this issue.  The instrumentation/collection technology behind code coverage shares a lot with the profiler, so we handle support issues for both.

     

    Regards,

    Chris

All Replies

  • Wednesday, September 03, 2008 1:15 AMBruce Taimana MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Moving to code coverage forum

  • Friday, September 05, 2008 9:36 AMBill.WangMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Moved to Profiler.

     

    Hi Steve

     

    When you view the code coverage report in Visual Studio, you can use Filter to filter some unwanted function. For more information, see Profiler Report View Filter. But I don't see a easy way to filter all CLR functions. 

  • Thursday, September 11, 2008 4:53 AMChris SchmichMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    The filtering mentioned by Bill only works for performance profiles (.vsp).  This does not work for coverage.  Also, the performance filter does not let you filter based on function name.

     

    The only way, currently, to filter functions from coverage is to not instrument them in the first place.  Check out vsinstr's /exclude command-line option.  You can /exclude functions that you don't want to show up in your coverage numbers.  * is treated as a wildcard.

     

    Regards,

    Chris

  • Thursday, September 11, 2008 5:54 AMSteve Hines Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have used the /EXCLUDE command line option, but in order to be effective it needs to refer to a namespace. When I ask about excluding global functions, I mean to ask if its possible to exclude the global namespace en-masse or if the CRT functions have some property that that allow them to be excluded as a whole. As far as I can tell, there is no naming pattern common to all CRT functions, so I don't see how wildcard matches will help.

    Also, can someone please move this back to the correct forum (where I posted it originally) that deals with code coverage/unit test questions. Thanks.
  • Thursday, September 11, 2008 6:07 AMChris SchmichMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Unfortunately, the only filtering we currently have is name-based.  You can specify /exclude multiple times, though, so you could specifically exclude each global CRT function.  For example, you could create a response file (call it foo.rsp) with the following contents:

     

    /exclude:CRTGlobalFunc1

    /exclude:CRTGlobalFunc2

    ...

    /exclude:CRTGlobalFuncN

    mybinary.exe

     

    Then, you could invoke vsinstr as such:

     

    vsinstr @foo.rsp

     

    Taking a step back, are you statically linking the CRT?  If you dynamically link it instead, the global CRT functions should be in a separate, non-instrumented DLL and then you shouldn't get coverage numbers for them.  Is this the case?

     

    This is actually the correct forum for this issue.  The instrumentation/collection technology behind code coverage shares a lot with the profiler, so we handle support issues for both.

     

    Regards,

    Chris

  • Thursday, September 11, 2008 6:32 AMSteve Hines Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Well, I can look into get a listing of all the CRT functions and passing them via a response file. There are about 11,000 of them. Does vsinstr have any kind of limit on the number of functions it can exclude?

    As for linking with the CRT, yes, we are statically linking to it. This is how the production binaries will ship. As much as I dislike having the code coverage results polluted with CRT functions, I'm not willing to run all our tests under different conditions simply to address this problem.

    Ultimately, the real issue is that VS2008 just doesn't have a rich enough interface for processing code coverage results or for exporting them to an application that could do so (such as Excel).
  • Friday, September 12, 2008 1:34 AMChris SchmichMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Command-lines have a limit on the number of characters they can handle, but if you use response files, you can get around that.  vsinstr has no known limit on the number of functions you can exclude.

     

    I agree, code coverage filtering from the UI is lacking and needed.  You can export the coverage results to an XML-formatted file for post-processing, however.  To avoid skew in the coverage numbers, though, I would recommend doing the instrumentation-based exclusions.

  • Wednesday, October 01, 2008 8:45 PMTim VarcakMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Steve,

    I've marked Chris's response here as the answer so that we can keep better track of open issues on the forum since it looks like it did answer your questions. If this isn't the case feel free to un-mark it as the answer and add the details about what issues you're facing with this. Or if you like you can open a completely new thread and let us know the details of the issue you're facing and we'll do our best to help you out.

     

    Thanks,

    Tim

     

  • Friday, December 19, 2008 11:43 AMJangid Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is there any way to exclude MFC classes in code coverage?
    मनोज कुमार जांगिड
  • Monday, October 12, 2009 11:35 AMBijayThakur Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes we can exclude MFC classes. we have to create a .rsp file and mansion all MFC  those you want to exclude.

    like:

    /coverage

    /exclude (MFC)filename

    bijaybinary.exe

    Thanks