6

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?

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

5

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.

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
  • Thanks for the answer, and it works like a charm. Could you help me out this question also? - http://stackoverflow.com/questions/4965173/generating-coverage-file-programmatic-way-with-visual-studio-2010 – prosseek Feb 11 '11 at 02:51
  • Zam!!!!!!! "vsperfcmd is just a controller/launcher for vsperfmon" was the hint I needed. – granadaCoder Apr 28 '16 at 23:29
0

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
Maslow
  • 18,464
  • 20
  • 106
  • 193