How to profile only a class library?

2019-06-27 18:43发布

I want to profile the CPU usage of a class library project which is compiled into a dll with VS2012.

When I go into Analyze -> Launch Performance Wizard, I can choose which project to profile but it only lets me profile executables, so I can't profile my library.

If I profile both of my projects (one is a very simple Form which runs functions from my library and shows some output) then System.Windows.Forms.Application.Run takes up 97% of my samples - I don't really care about the performance cost of the form, and it overwhelms everything else.

How can I see the performance data for just my dll?

1条回答
相关推荐>>
2楼-- · 2019-06-27 19:27

You need to create a unit test which exercises the various library functions you are interested in profiling.

You can then right click on the test in the "Test Explorer" and then select "Profile Test".

Screenshot

This should kick off a performance analysis session for the selected test. I not sure why they hid this very useful feature so well!

In VS2012, this option may be grayed out. In this case you can enable it by deleting your %localappdata%\Microsoft\VisualStudio\11.0\ComponentModelCache folder and restarting Visual Studio. (source)

查看更多
登录 后发表回答