API Ability to "query" snapshots?

Use this forum to discuss and/or suggest future improvements of .NET Memory Profiler and to report bugs.

Moderator: SciTech Software

API Ability to "query" snapshots?

Postby kellyconway » Fri Nov 18, 2011 4:47 pm

Is there any chance that we may be able to do something like this at some point using the API?

Code: Select all
MemSnapshot snapshotInitial = MemProfiler.FullSnapShot("Initial");


MemSnapshot snapshotFinal = MemProfiler.FullSnapShot("Final");

// The parts that would not work today follow...

if (snapshotFinal.TotalLiveBytes - snapsnot.Initial.TotalLiveBytes > someNumberOfBytes)
    // report potential memory leak

// OR maybe

if (snapshotFinal.DeltaLiveBytes > someNumberOfBytes)
    // report potential memory leak

IOW, will we at some point be able to "query" snapshots for info?

Also food for thought...

Code: Select all
int instancesInMemory = snapshotFinal.LiveInstances("My.Namespace.And.Type");
Posts: 10
Joined: Wed Nov 09, 2011 8:49 pm

Re: API Ability to "query" snapshots?

Postby Andreas Suurkuusk » Tue Nov 22, 2011 8:39 am

At the moment there's no possibility to query snapshots using the in-process profiler API (using the MemProfiler and MemAssertion classes).

However, if you use the AssertionsDefinition class you can use the MaxNewBytes or MaxNewInstances assertion methods to assert that the additional memory usage is below a treshold.

So for your first example you could use:
Code: Select all
using( MemAssertion.BeginAssertions() )
  AssertionsDefinition ad = new AssertionsDefinition();
  ad.MaxNewBytes( TypeSet.All, someNumberOfBytes );

  MemAssertion.Assert( snapshot.Initial, ad );

(Using the MemAssertion.BeginAssertions method is not required, but it can avoid side effects and improve performance.)

As a sidenote, I recommend that you use the AssertionsDefinition class and the MemAssertion.Assert method when performing your assertions, instead of the other MemAssertion assertion methods. The AssertionDefinitions class provides more control over the assertions and have better performance if more than one assertion is performed.

Still, even if you can use the MaxNewBytes and MaxNewInstances assertions, actual information from the snapshots can of course also be useful. As this information is easily available for the profiler, we will probably add a few query properties and methods in a future version of the profiler.

Thanks for the suggestion.
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
Posts: 995
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden

Return to Future Improvements

Who is online

Users browsing this forum: No registered users and 1 guest

SciTech Software logo

© Copyright 2001-2016. SciTech Software AB
All rights reserved.

SciTech Software AB
Kartvägen 21
SE-175 46 Järfälla

E-mail: mail@scitech.se

Telephone: +46-706868081