Using dot memory API to take multiple snapshot on same .dmv file

748 Views Asked by At

I am trying to profile my specific code using dot memory api. When I call the dump() method my expectation is to take snapshot and save it to dir.

I am trying to take two snapshot here one before executing my code and after executing my code by calling dump() method.

Is it possible to create the both snapshot in the same output file as we option to do it from Stand alone dot memory?

Appreciate your suggestion. following is the code snippet

SelfAttach.Attach(new SaveSnapshotProfilingConfig
{
   ProfilingControlKind = ProfilingControlKind.Api,
   SaveDir = "D:\\SelfProfiling",
   RedistDir = "D:\\Softwares\\JetBrains.Profiler.SelfSdk.2017.2.2",
   ProfilingType = ProfilingType.Memory,
   ListFile = "D:\\snapshot_list.xml" 
});

while (SelfAttach.State != SelfApiState.Active)
{
     Thread.Sleep(250);  // wait until API starts
}

if (MemoryProfiler.IsActive)
{
   MemoryProfiler.Dump();
   MyMethodTobeProfiled();
   MemoryProfiler.Dump();
}

if (MemoryProfiler.CanDetach)
   MemoryProfiler.Detach();
2

There are 2 best solutions below

2
On

Is it possible to create the both snapshot in the same output file as we option to do it from Stand alone dot memory?

A snapshot is normally a bunch of files. .dmw is an archive of a snapshot. This is the design now. The reason is to ability to start sending a snapshot immediately to a remote host. This is the R# requirement.

0
On

I guess you can use dotMemory Command Line Profiler instead of "Self profiling" API to reach your needs.

Launch dotMemory command line profiler. Determine that profiler is already attached to your app, for that you need to analyze dotMemory CLT process output.

So, pseudo code to get what you need

dotMemory.exe attach --service-output --use-api "your_app_PID"

// then the message will be printed to output
// ##dotMemory["connected",{"pid":your_app_PID,"name":"your_app_NAME.exe"}]
wait for this message

// the rest of your code remains the same
// and you need only JetBrains.Profiler.Windows.Api.dll
// no more need JetBrains.Profiler.Windows.SelfApi.dll
if (MemoryProfiler.IsActive)
{
    MemoryProfiler.Dump();
    MyMethodTobeProfiled();
    MemoryProfiler.Dump();
}

if (MemoryProfiler.CanDetach)
   MemoryProfiler.Detach();

Read more about dotMemory command line profiler here