Batch running of VS code coverage tools

2020-02-11 05:43发布

问题:

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.

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

回答1:

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.



回答2:

To do this for already instrumented files with an IIS Express application: Get the name of the site from C:\Users\<your user>\Documents\IISExpress\config\applicationhost.config

vsperfcmd /start:coverage /output:run.coverage
"c:\Program Files (x86)\IIS Express\iisexpress.exe" /site:"<that thing you got from applicationhost.config>"

a browser will likely auto launch. click around in your code, do your manual tests.

then to finish

vsperfcmd /shutdown