Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile only a class library?

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?

like image 658
Superbest Avatar asked Nov 05 '12 20:11

Superbest


People also ask

Can I use the same class library projects on different platforms?

This means that each platform can only use class libraries that are targeted to the same profile so they would appear to require separate class library projects for each platform. There are three major approaches to code sharing that address this problem: .NET Standard projects, Shared Asset Projects, and Portable Class Library (PCL) projects.

What is a class profile?

Class Profile is another tool to provide a snapshot of the class strengths, stretches, class-wide goals, as well as individual needs.

How do I add a portable class library to my solution?

Adding a Portable Class Library to your solution is very similar to adding a regular Library project. In the New Project dialog select the Multiplatform > Library > Portable Library option: When a PCL is created in Visual Studio for Mac it is automatically configured with a Profile that works for Xamarin.iOS and Xamarin.Android.

What is a class library?

Class libraries are the shared library concept for .NET. They enable you to componentize useful functionality into modules that can be used by multiple applications. They can also be used as a means of loading functionality that is not needed or not known at application startup. Class libraries are described using the .NET Assembly file format.


1 Answers

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)

like image 184
Richard Smith Avatar answered Oct 27 '22 01:10

Richard Smith