Search code examples
visual-studio-2010code-coverage

Batch running of VS code coverage tools


I came up a batch file to generate code coverage file as is written in this post.

cl /Zi hello.cpp -link /Profile
vsinstr -coverage hello.exe
start vsperfmon /coverage /output:run.coverage
hello
vsperfcmd /shutdown

However, I got this error message when I run the batch file.

enter image description here

I had to run vsperfcmd /shutdown manually to finish it. What might be wrong?


Solution

  • This is just a timing issue.

    The start vsperfmon /coverage /output:run.coverage command starts up vsperfmon.exe in a separate process.

    Concurrently, your script goes on to run hello. If hello is a really simple program, it is possible that it executes and completes before vsperfmon.exe is running and fully initialized. If your script hits vsperfcmd /shutdown before the monitor is up and running, you will get the error you're showing.

    vsperfcmd is just a controller/launcher for vsperfmon, so you can use that exclusively in your batch file:

    cl /Zi hello.cpp -link /Profile
    vsinstr -coverage hello.exe
    vsperfcmd /start:coverage /output:run.coverage
    hello
    vsperfcmd /shutdown
    

    In this case, the first call to vsperfcmd will block until the monitor is up and fully running.