.NET Profiler API + Run Tests under the Profiler

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

.NET Profiler API + Run Tests under the Profiler

Post by dcerny » Wed Feb 13, 2019 8:20 am

Hello, I have NET Memory Profiler Enterprise edition v 5.6.46.0. I want to profile unit tests in VS.NET and use profiler API.

I use "Profiler > Run Tests under the Profiler" command, profiler session starts, then I start the test in VS.NET Test Explorer, the test finishes, but profiler collects no data and MemProfiler.IsProfiling has 'false' value.

I use VS.NET 2017 Professional + NUnit 2 test Adapter
what is wrong?

thank you

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Thu Feb 14, 2019 6:42 am

Unfortunately, the “Run tests under Profiler” command is not always working correctly under later releases of Visual Studio 2017. This is due to an implementation change in the test runner in Visual Studio 2017, and we’re trying to find a solution for this. If we cannot find a solution, this feature may be removed from the profiler.

However, version 5.6 includes well integrated support for the DevExpress CodeRush test runner, and this is the recommended way of running interactive unit tests under the profiler. For more information about the CodeRush test runner, see the features page.

To use CodeRush, you need to purchase a separate CodeRush license from DevExpress (but it is significantly cheaper than the .NET Memory Profiler license).
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Thu Feb 14, 2019 8:47 am

Hello and thanx for answer. Feature "Run Tests under the Profiler" (in VS.NET) was the only reason, why we have upgraded to enterprise edition. When it will be fixed?
thank you

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Fri Feb 15, 2019 1:18 pm

We're currently working on .NET Memory Profiler 6.0, but we are planning to release a maintenance release of version 5.6 within the next month. The release will mainly include support for Visual Studio 2019 and a few fixes. But, we will also look into the ""Run tests under profiler" feature and see if we can get it working again under Visual Studio 2017/2019. I cannot promise that we will be able to fix this, but hopefully we can come up with a solution.

If we cannot solve this, you can contact us at sales@scitech.se if you wish a refund for your upgrade to the Enterprise edition.
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Fri Feb 15, 2019 4:25 pm

I have tried the API with trial license of CodeRush.
This code:

public class MemProfilerTests
{
[Test]
public void MemLeakTest()
{
Assert.IsTrue(MemProfiler.IsProfiling);
MemProfiler.FastSnapshot();
MemAssertion.NoNewInstances(typeof(Player));
}
}

fails with exception:

System.NullReferenceException: Object reference not set to an instance of an object
SciTech.NetMemProfiler.TypeNameBuilder.AppendPrettyTypeString(StringBuilder dest, Type type)
SciTech.NetMemProfiler.MemAssertion.CreateTypeString(Type type, Boolean forApi)
SciTech.NetMemProfiler.MemAssertion.NoNewInstancesHelper(MemSnapshot comparisonSnapshot, Boolean snapshotSpecified, Type type, AssertionsThread assertionsThread, Boolean includeSubclasses, Int32 callStackId)
SciTech.NetMemProfiler.MemAssertion.NoNewInstances(Type type)
Legends.Tests.MemProfilerTests.MemLeakTest() in PerformanceTests.cs

Did I anything wrong?
thank you

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Mon Feb 18, 2019 9:34 am

Your code looks fine. I don't understand how you can get a NullReferenceException when performing your assertions. We have investigated the API code and added a few more null-checks, but as far as I can see they should not be necessary.

Anyway, can you test with the latest build of the profiler API? If you have installed it using Nuget, you can update to the latest build using the package manger command below:

Code: Select all

Install-Package SciTech.MemProfilerApi -Version 5.6.2-prerelease
I have also attached a zip-file with the API libraries to this post.

Can you provide some additional information about your test project? Are you using .NET Core or the standard .NET Framework? What .NET version are you using? What does the "Player" class look like? Is it a nested type, private, etc?
Attachments
MemProfilerAPI_5.6.2.zip
(76.01 KiB) Downloaded 28 times
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Mon Feb 18, 2019 10:52 am

Hello,
the update of nuget package didn't help. The exception is the same.
The project uses .NET Framework 4.6.1.
Player class is not nested, declaration:
sealed class Player : AgentHuman, IAgentAttributeItem

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Mon Feb 18, 2019 10:57 am

Thanks for the information. At the moment I don't know how this can occur. We will investigate this further and see if we can come up with an explanation/fix. I will get back to this thread as soon as we have some more information.
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Fri Mar 01, 2019 9:51 am

Hello guys,
any update?
Without this feature we will have to downgrade and ask refund.
Can you simply add some quick fix like try/catch in AppendPrettyTypeString() and when it fails return "less pretty" type string (e.g. Type.Name)
Or, if you send me source code, I can debug it..
thank you

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Fri Mar 01, 2019 2:52 pm

I'm sorry for the delay. We have been working on the maintenance release of .NET Memory Profiler 5.6, with support for Visual Studio 2019. Now we have built a new version and we will probably release it in the beginning of the next week. Unfortunately, we have not been able to find a solution for the "Run tests under memory profiler" problem, so you will still need to use CodeRush.

This release includes several bug fixes and minor improvements, and an update of SciTech.MemProfilerApi (v5.6.4). We have added some additional safety checks in this API version.


You can download the latest build of .NET Memory Profiler from http://memprofilerwe.blob.core.windows. ... 5_6_49.exe.

The latest version of the API is still unlisted, but you can install it using:

Code: Select all

Install-Package SciTech.MemProfilerApi -Version 5.6.4
Can you download and test the latest version of the profiler and the API and see if it works better?
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Fri Mar 01, 2019 3:52 pm

v5.6.4 throws the same exception.

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Fri Mar 01, 2019 3:54 pm

That's really strange. Can your provide the call stack of the exception?
Best regards,

Andreas Suurkuusk
SciTech Software AB

dcerny
Posts: 7
Joined: Wed Feb 13, 2019 8:15 am

Re: .NET Profiler API + Run Tests under the Profiler

Post by dcerny » Fri Mar 01, 2019 4:14 pm

the call stack is above (it is the same exception).
I've decompiled and debugged your code.
The problem is, that type Player has no namespace, therefore type.Namespace=null in method SciTech.NetMemProfiler.TypeNameBuilder.AppendPrettyTypeString(StringBuilder dest, Type type)
Looking forward for quick fix..

Andreas Suurkuusk
Posts: 1025
Joined: Wed Mar 02, 2005 7:53 pm

Re: .NET Profiler API + Run Tests under the Profiler

Post by Andreas Suurkuusk » Fri Mar 01, 2019 6:02 pm

Thank you very much and I really appreciate your effort. It's a bit embarrassing that I missed that Namespace could return null, I just assumed that it would return an empty string in case there's no namespace (the documentation clearly states that null will be returned).

I have now fixed this issue. You can install the latest version of the API using

Code: Select all

Install-Package SciTech.MemProfilerApi -Version 5.6.5
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 11 guests