Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile performance for a single unit test using Visual Studio 2013 Professional?

Tags:

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?

like image 224
GaTechThomas Avatar asked Apr 24 '15 18:04

GaTechThomas


People also ask

How do I run a performance profiler in Visual Studio?

Open the Performance Profiler by choosing Debug > Performance Profiler (or Alt + F2). For more information on using the CPU Usage or Memory usage tool in the Performance Profiler vs. the debugger-integrated tools, see Run profiling tools with or without the debugger.

How do I run a single unit test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

How do I debug a single test in Visual Studio?

To debug a single test: Click on a test method name, then press Ctrl+R, Ctrl+T. (Or go to Test / Debug / Tests in Current Context.)


1 Answers

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.

like image 77
GaTechThomas Avatar answered Nov 15 '22 11:11

GaTechThomas