A customer recently asked me if the profiler included with Visual Studio Team System would allow you to profile an application while the debugger was attached. While I knew that it would (from talking with other team members) I had never actually tried this, so I set out to give it a go.
To make this scenario easier I chose to just debug and profile notepad.exe as opposed to a program of my own. First off I chose to profile in sampling mode, here are the steps that I used to collect my performance file:
1. Create a new performance session in Visual Studio
2. Right click on the Targets folder and select “Add New Binary” to add notepad.exe as a target for profiling
3. Click the launch button to launch notepad.exe with the profiler attached in sampling mode
4. In the IDE use Debug->Attach to Process to attach the debugger to the notepad.exe process that the profiler launched
5. Now you can profile your debugging session
So what do you do if you don’t want to wait to attach the debugger to your program that you are profiling? Then you can just launch the program with the debugger attached first (outside the performance explorer) and then use the “Attach” button in the performance explorer to attach the sampler to the running process. Instrumentation mode works just the same as sampling mode, except that you don’t have an “Attach” mode for instrumentation profiling.