Page 1 of 1

.NET Profiler API + Run Tests under the Profiler

Posted: Wed Feb 13, 2019 8:20 am
by dcerny
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

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

Posted: Thu Feb 14, 2019 6:42 am
by Andreas Suurkuusk
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).

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

Posted: Thu Feb 14, 2019 8:47 am
by dcerny
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

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

Posted: Fri Feb 15, 2019 1:18 pm
by Andreas Suurkuusk
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.

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

Posted: Fri Feb 15, 2019 4:25 pm
by dcerny
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

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

Posted: Mon Feb 18, 2019 9:34 am
by Andreas Suurkuusk
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?

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

Posted: Mon Feb 18, 2019 10:52 am
by dcerny
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

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

Posted: Mon Feb 18, 2019 10:57 am
by Andreas Suurkuusk
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.

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

Posted: Fri Mar 01, 2019 9:51 am
by dcerny
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

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

Posted: Fri Mar 01, 2019 2:52 pm
by Andreas Suurkuusk
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?

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

Posted: Fri Mar 01, 2019 3:52 pm
by dcerny
v5.6.4 throws the same exception.

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

Posted: Fri Mar 01, 2019 3:54 pm
by Andreas Suurkuusk
That's really strange. Can your provide the call stack of the exception?

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

Posted: Fri Mar 01, 2019 4:14 pm
by dcerny
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..

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

Posted: Fri Mar 01, 2019 6:02 pm
by Andreas Suurkuusk
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