Page 1 of 1

NUnit usage

Posted: Wed Aug 17, 2011 6:23 am
by madman
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

Re: NUnit usage

Posted: Wed Aug 17, 2011 9:41 pm
by Andreas Suurkuusk
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.

Re: NUnit usage

Posted: Fri Aug 19, 2011 7:22 am
by madman
Thank you very much for your post!!

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

Re: NUnit usage

Posted: Wed Aug 24, 2011 8:09 am
by madman2
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:

Re: NUnit usage

Posted: Wed Aug 24, 2011 11:10 am
by madman3
Same problem occurs "Starting session...please wait Waiting for profiled process to start" when trying to start profile application from .NET Memory Profiler

Re: NUnit usage

Posted: Wed Aug 24, 2011 12:04 pm
by madman4
I got it working with application under test so no problems anymore!

Re: NUnit usage

Posted: Wed Aug 24, 2011 9:02 pm
by Andreas Suurkuusk
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).