Open API-generated snapshot in dotMemory UI app?

I use dotMemory in conjunction with a very basic memory analysis tool in my application that makes it easy to tell when a memory leak is occuring.

 

I'm trying to figure out if there's a way I can initiate taking a snapshot from within the application itself, and have it automatically open in my locally installed dotMemory. This feature (the memory tool) is not available in client builds so I don't need to worry about clients having or not having dotMemory, since they can't use this. I'm looking at the documentation (which seems very sparse, and does not seem very helpful) and I can't tell if this is possible. There's a DotMemory.Config object that has a .OpenDotMemory() method but calling this doesn't do anything.

 

Clicking the above dotMemory: Take Snapshot button calls this:

private async void TakeSnapshot_Click(object sender, RoutedEventArgs e)
{
IsBusy = true;
IsBusyText = "Ensuring dotMemory";
DotMemory.Config conf = new DotMemory.Config();
conf.SaveToDir(Path.GetTempPath());
await DotMemory.EnsurePrerequisiteAsync();
IsBusyText = "Taking snapshot";
DotMemory.GetSnapshotOnce(conf);
conf.OpenDotMemory();
IsBusy = false;
}

 

The app freezes but nothing happens. Am I missing something? How do I make this work? The documentation could use more actual real world examples, preferably where all methods are used. OpenDotMemory() has no example so I have no idea how to actually use it.

3 comments
Comment actions Permalink

Hello,

You should specify all configuration settings including OpenDotMemory before profiling start, please change your code this way:

```

private async void dotMemorySelfApi_Click(object sender, RoutedEventArgs e)
{
IsBusy = true;
IsBusyText = "Ensuring dotMemory";
DotMemory.Config conf = new DotMemory.Config();
conf.SaveToDir(Path.GetTempPath()).OpenDotMemory();
await DotMemory.EnsurePrerequisiteAsync();
IsBusyText = "Taking snapshot";
DotMemory.GetSnapshotOnce(conf);
IsBusy = false;
}

```

Please note that dotMemory must be installed on this computer. Otherwise, you can find saved workspace in Path.GetTempPath() folder and open it on other machine manually.
 
0
Comment actions Permalink

I see. That worked. Why are the configurations options methods? Its setting strings and booleans. Shouldn't these be properties or fields? A method named .OpenDotMemory() sounds pretty misleading, it sounds like a verb, an action, that calling it is going to do something. Maybe if it was SetOpenDotMemory(bool val), which communicates that a variable is being set instead, but the current naming and types don't really make sense. I don't feel in the documentation having the config option fully set up was obvious - I mean, it seems logical or should be obvious - but then you have a methods named SaveToDir() and OpenDotMemory() which are things that might sound you like you do after taking a snapshot, and none of the examples seem to use more than one option. A real example containing multiple options (in a real world scenario, like they do in microsoft documentation) would help a lot. I guess it makes sense if it's a builder pattern, but I didn't see any mention of that either in the documentation. I guess what I'm saying is the API uses confusing types and names compared to what I see elsewhere in the C# ecosystem.

Anyways, it works now, so I'm happy. Thanks!

0
Comment actions Permalink


OpenDotMemory() - Specifies "whether to open" the generated workspace in JetBrains dotMemory (not "to open"). Thus, it'll work when next workspace is generated.
You can find this description on API Reference page or when hover mouse to this method in IDE.

> A method naked .OpenDotMemory() sounds pretty misleading

Yes, it really sounds misleading, sorry for the inconvenience.

 

0

Please sign in to leave a comment.