NUnit usage

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
madman
Posts: 2
Joined: Wed Aug 17, 2011 5:54 am

NUnit usage

Post by madman » Wed Aug 17, 2011 6:23 am

Newbe question...

I am using Ranorex automation tool + NUnit to run testcases. I have in code this part:

using NUnit.Framework;

[TestFixture, RequiresSTA]
public class TestCase1
{
[TestFixtureSetUp]
public void Init()
{
}

[Test]
public void Test1()
{
}

[TestFixtureTearDown]
public void Dispose()
{
}
}
I would like to profile the memory usage of the application under test (beginning and end value)

Few questions:
- is this the code which should start the profiling my AUT:

class Program
{
static void Main()
{
ProfilerApplicationCore application = new ProfilerApplicationCore();

// Define the process that should be profiled.
ProfileProcessStartInfo startInfo = new ProfileProcessStartInfo(
ProfilingType.Application,
"<path to executable>" );

// Create a new session (ActiveSession is derived from ProfilerSession)
using( ActiveSession session = application.CreateSession( startInfo ) )
{
// Start the profiling.
session.Start( TimeSpan.FromMinutes( 1 ) );

// Wait for a while.
Thread.Sleep( TimeSpan.FromSeconds( 10 ) );

// And collect a snapshot.
// NOTE! The "internal" API (MemProfiler.FullSnapShot) is probably more suitable
// for collecting snapshots.
session.CollectSnapshot( false );

// Wait some more.
Thread.Sleep( TimeSpan.FromSeconds( 10 ) );

// And collect a second snapshot.
session.CollectSnapshot( false );

// Stop the profiling session (and terminate the profiled process).
session.Stop( true );

// Save the session (the second argument can be used
// to specify which snapshots to include in the saved session
// file).
session.Save( @"C:\Scrap\NewSession.prfsession", null, true );
}
}
}

I got this error when running the test:

Unexpected exception occured: SciTech.Profiler.ProfilerException: Failed to start application: Failed to create process
at B.hh.yx(ProfileProcessStartInfo K)
at B.hh.iZ(String& K)
at B.hh.SV(ProgressTracker K, TimeSpan T)
at SciTech.Profiler.ActiveSession.Tj(TimeSpan K, Object T, AsyncWorkerBase x)
at SciTech.Profiler.ActiveSession.Start(TimeSpan connectTimeout)

It refers to line:

// Start the profiling.
session.Start( TimeSpan.FromMinutes( 1 ) );

- is it so, that AUT is started "automatically" when profiling is started?

- .NET memory profiling is also started "automatically" when this test is started?

- does the example code work with 4.0 or should I try to use older version of .NET memory profiler?


Sorry for the very complex mail...basically I need the code which starts profiling AUT when I start running NUnit tests

Any help would be great

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

Re: NUnit usage

Post by Andreas Suurkuusk » Wed Aug 17, 2011 9:41 pm

The code example you provided should work, except that if you use .NET Memory Profiler 4.0 (which I recommend) a few changes needs to be done. You must include the namespace SciTech.Profiler (instead of SciTech.NetMemProfiler) and the call to session.CollectSnapshot( false ) should be replaced with session.CollectSnapshot( SnapshotCollection.FullGC ).

The exception you get indicates that there's something wrong with the path to your executable. How do you initiate the executable path?

If you don't have a specific need to run the profiler using the API, I recommend that you start profiling using command line arguments. You should be able to use NetMemProfilerConsole.exe or NmpCore.exe. For more information see my reply to a related post, and the information about NmpCore and command line arguments.
Best regards,

Andreas Suurkuusk
SciTech Software AB

madman
Posts: 2
Joined: Wed Aug 17, 2011 5:54 am

Re: NUnit usage

Post by madman » Fri Aug 19, 2011 7:22 am

Thank you very much for your post!!

Very good help; I will start to looking to these!

madman2

Re: NUnit usage

Post by madman2 » Wed Aug 24, 2011 8:09 am

There maybe some really easy solution to this error (I am trying to profile notepad.exe which was started) but got this error:

Unexpected exception occured: System.TimeoutException: Connection to the profiled process timed out.
at B.hh.Sj(TimeSpan K, String T)
at B.hh.SV(ProgressTracker K, TimeSpan T)
at SciTech.Profiler.ActiveSession.Tj(TimeSpan K, Object T, AsyncWorkerBase x)
at SciTech.Profiler.ActiveSession.Start(TimeSpan connectTimeout)

-> refer to line: session.Start( TimeSpan.FromMinutes( 1 ) );

What could be the problem here? :oops:

madman3

Re: NUnit usage

Post by madman3 » Wed Aug 24, 2011 11:10 am

Same problem occurs "Starting session...please wait Waiting for profiled process to start" when trying to start profile application from .NET Memory Profiler

madman4

Re: NUnit usage

Post by madman4 » Wed Aug 24, 2011 12:04 pm

I got it working with application under test so no problems anymore!

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

Re: NUnit usage

Post by Andreas Suurkuusk » Wed Aug 24, 2011 9:02 pm

Just for your information, Notepad.exe is not a .NET application, so the profiler will not be loaded into the process and profiling will not start. That's why you get the TimeoutException, and the "Waiting for profiled process to start" message (the "Waiting for..." message is a bit misleading, since it is actually waiting for the .NET runtime to be loaded into the process).
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests