Page 1 of 1

API: write dump/session to disk?

Posted: Fri Oct 12, 2018 2:08 pm
by s.kuklau
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.

Re: API: write dump/session to disk?

Posted: Fri Oct 12, 2018 2:50 pm
by s.kuklau
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?

Re: API: write dump/session to disk?

Posted: Mon Oct 15, 2018 9:48 am
by Andreas Suurkuusk
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.

Re: API: write dump/session to disk?

Posted: Mon Dec 17, 2018 3:23 pm
by Killam
Is it recommended to collect more than one snapshot btw, Andreas?

Re: API: write dump/session to disk?

Posted: Thu Dec 20, 2018 5:38 pm
by Andreas Suurkuusk
Yes, it is normally recommended to collect more than one snapshot. This way you can more easily identify memory usage trends, e.g. see if there are types with additional instances in each new snapshot. With instance tracking enabled, you will also see the specific instances that are new in each snapshot.