26

I would like to run the Visual Studio 2013 Professional edition profiler for a single automated test. It is not clear from other questions here on how to do so using the Professional edition.

Is this possible and if so, how?

GaTechThomas
  • 5,421
  • 5
  • 43
  • 69

2 Answers2

32

Ok, so I figured out how to do it for profiler sampling (not instrumentation)...

  1. Launch Visual Studio (VS) and open the project that has the automated test that you would like to profile.
  2. Put a breakpoint on the first line of the test that will be profiled.
  3. Debug the test.
  4. Start a second instance of VS.
  5. Open Performance Explorer (depending on your version of VS2013 this will be at either Tools->Analyze->Windows->Performance Explorer or Analyze->Windows->Performance Explorer).
  6. In Performance Explorer, click Actions->Attach and attach to vstest.executionengine.*.
  7. Go back to the first VS instance (currently at a breakpoint) and run the test to completion.
  8. Go back to the second VS instance. The profiler will detect that the unit test process has exited and complete its profiling.

One thing that could be improved would be to do this with instrumentation, but it is not currently clear to me how that could be done in VS Professional edition.

GaTechThomas
  • 5,421
  • 5
  • 43
  • 69
  • 2
    Thanks! This procedure also works for me in VS 2012 Professional. Knowing that you have to connect to the process named vstest... was the key. However, I also have not figured out how to use instrumentation profiling with a unit test. – Paul Chernoch Nov 18 '15 at 14:58
  • 1
    If you are using Resharper to run tests, the process would be "JetBrains.ReSharper.TaskRunner.CLR45.x64.exe" or similar – Ivan Krivyakov Jan 05 '16 at 03:08
  • 2
    In Visual Studio 2015 Community, the one you need to select is [TE.ProcessHost.Managed](http://i.stack.imgur.com/1Wko1.png). Unfortunately, there appear to be two of them, so you must select the one with higher CPU usage. (See image.) – Mateen Ulhaq Feb 29 '16 at 17:09
  • 1
    Works for Visual Studio 2015 Enterprise as well. – GraehamF Sep 13 '16 at 18:33
  • 1
    Instrumentation requires the re-writing of the .net binary on disk before launching the profiler, so I dont think you can ever do instrumentation via attach becasue the code is already JIT-ed into memory. – PhillipH Nov 06 '16 at 16:56
  • In VS 2017 it says "Unable to Attach to the process. A debugger is already attached." Can anybody suggest an approach with VS 2017 please? Thanks! – Kalin Krastev Jun 13 '17 at 12:18
  • @KalinKrastev Interesting. Are you trying to attach to vstest.executionengine.*? – GaTechThomas Aug 04 '17 at 17:29
  • Works for me in VS 2017 - with F# code! I attached to vstest.executionengine. – Kit Jan 31 '18 at 08:58
  • 2
    For VS 2017 it seems to be the process "testhost.x86.exe" – Wolf5 Feb 15 '18 at 11:53
  • 3
    @GraehamF if you have Visual Studio 2015 Enterprise you can right click on a test in the Test Explorer window where you will find a "Profile Test" option. – mark_h May 24 '18 at 11:10
17

To run performance analysis on a unit test, I just create a console application that I call the unit test method from, then use that as the target project for the performance analysis. This is probably easier than firing up two instances of VS and attaching.

MarkPflug
  • 28,292
  • 8
  • 46
  • 54