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.