API: write dump/session to disk?

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
s.kuklau
Posts: 2
Joined: Fri Oct 12, 2018 1:49 pm

API: write dump/session to disk?

Post by s.kuklau » Fri Oct 12, 2018 2:08 pm

I've been using .NET Memory Profiler to significantly cut down on memory leaks due to non-disposed objects, stray event handlers, etc. Very nice.

Now, I have a customer with a memory issue I've failed to reproduce, and I'm considering embedding the SciTech.MemProfilerApi library in the shipping application in order to help track this down. (I think this is covered by the professional license?)

As such, I thought I could start with a button that takes a memory snapshot* and saves the result to disk, presumably using the .prfsession format. However, while NmpCore can apparently do this from the command-line (while also providing some form of UI), such functionality appears missing in the API. Is this not (yet?) a supported scenario, or am I approaching this wrong?

Should I instead ship NmpCore with the app, and make a button that launches it?

*) Comparison snapshots, etc. will be interesting for later, but for now, I'm mostly just interested in browsing through what instances currently exist.

s.kuklau
Posts: 2
Joined: Fri Oct 12, 2018 1:49 pm

Re: API: write dump/session to disk?

Post by s.kuklau » Fri Oct 12, 2018 2:50 pm

Never mind; I think I understand now. Starting the profiling session at all isn't actually supported by the API; rather, I need to initiate it from either the full NMP app, or NmpCore. Right?

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

Re: API: write dump/session to disk?

Post by Andreas Suurkuusk » Mon Oct 15, 2018 9:48 am

Yes, you are correct. The profiler API is intended to control the profiler from within the profiled process, it cannot be used to initiate profiling by itself.

There's an external API that can be used, but this API requires the full profiler to be installed on the machine which I assume will not work for you, since you want to create sessions on a customer's machine.

Triggering NmpCore as an external process can be solution, e.g. by using something like:

Code: Select all

Process.Start( "NmpCore", "/a:<my pid> /ac1 /cs /sf \"<path to session file>\"");
Note that as long as you only collect a single snapshot, the information available will be almost the same as if you create a memory dump file and then import it into the profiler. A memory dump file may be easier to create, since it does not require NmpCore on the customer's machine, but the file will be bigger than a session file, and if you want to collect more than one snapshot, it will not support instance tracking.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 14 guests