Excluding parts of the application from profiling

Not all parts of your application might be interesting to be profiled. For example if you do a lot of setup activity on the database, or execute other activity on the database you will never need in a snapshot, you can mark these parts to be excluded.

// ...
// code which is profiled
// ...
InterceptorCore.BeginIgnoredSection();
// ...
// code which is not profiled
// ...
InterceptorCore.EndIgnoredSection();
// ...
// code which is profiled
// ...

This is per-thread, so all messages created for the executing thread which calls BeginIgnoredSection are not created nor sent. This overrules the global EnableMessageSending, in such a way that even if global message sending is enabled, an ignored section is always ignored.

ASP.NET specific

BeginIgnoredSection and EndIgnoredSection should be executed within the same scope. It's OK to execute them in separate methods executed from the same parent method, but it's not OK to execute them from methods which might be executed in different requests, as the methods use a thread static variable, which can't be guaranteed to have the expected value if the methods are (indirectly) executed from different scopes/requests, because ASP.NET uses a thread-pool and recycles threads for requests.