dotMemory Command Line Tools

In the 2017.1 release, dotMemory introduced a console profiler. Now, using the dotMemory.exe tool, you can perform memory profiling from the command line. Why would you? The short answer would be to automate the process of gathering memory snapshots. There are lots of possible use cases:

  • You want to speed up profiling routines, e.g. when you regularly profile the same application and do not want to start the dotMemory user interface each time.
  • You need to profile your application on someone’s computer you don’t have access to (e.g., your client’s) but don’t want to bother him with dotMemory installation and detailed profiling instructions.
  • Or maybe you want to include memory profiling into your continuous integration builds (though our dotMemory Unit framework could be much handier for this purpose).

Where can I get it?

dotMemory.exe is distributed separately from dotMemory. You can download the tool on the dotMemory download page. Note that dotMemory.exe is free and does not require you to have the full dotMemory installed.

Now let’s take a look at the most common usage scenarios.

Instantly get a snapshot

The most popular scenario is probably getting a snapshot of an already running application.

dotMemory.exe get-snapshot 1234 --save-to-dir=C:\Snapshots

1234 here is the process ID. Right after you run the command, dotMemory will attach to the process, take a snapshot, save it to C:\Snapshots, and detach from the process.
You can also specify the profiled application with its process name:

dotMemory.exe get-snapshot MyApp --with-max-mem


dotMemory.exe get-snapshot MyApp --all

--all and --with-max-mem options let you avoid ambiguity when multiple processes with the same name are running:

  • --with-max-mem – a process that consumes most of the memory will be profiled.
  • --all – all processes with the specified name will be profiled. dotMemory will take snapshots of all processes (snapshot per process).

Get snapshots by condition

Sometimes you may need to track application memory consumption during a long time interval. In this case, you can start your application under profiling and get snapshots only in case a particular condition is satisfied:

  • a periodic time interval ends (in the example, it’s 30 s):

    dotMemory.exe start --trigger-timer=30s C:\MyApp\MyApp.exe MyAppArg1

  • or memory consumption increases by a specified value (50% in the example below):

    dotMemory.exe start --trigger-mem-inc=50% --trigger-delay=5s C:\MyApp\MyApp.exe

    (--trigger-delay=5s here stands for the 5s delay required to skip application startup phase)

Note that in both examples, we use the start command to start the application. If you want to profile a ASP.NET application, you should use the start-iis command. In this case, IIS and all its application pools will be started under profiling. E.g.:

dotMemory.exe start-iis --trigger-timer=30s --open-url=localhost/myapp --use-browser=Chrome

What if the app you want to profile is already running but you still want to use triggers? Simply use the attach command:

dotMemory attach MyApp.exe --trigger-timer=30s

Get snapshots using stdin messages

If you want to take direct control over the profiling process (i.e., get snapshots at some exact moment), you can do this by sending messages to stdin of dotMemory.exe:

  • Get a snapshot:

    ##dotMemory["get-snapshot", {pid:1234}]

If pid is specified, dotMemory will take a snapshot of the process with the specified PID. Otherwise, dotMemory will take snapshots of all profiled processes.

  • Stop profiling and kill the profiled application:


These stdin messages work for all profiling sessions started with start, start-iis, or attach commands.

Moreover, if you want to write a profiling script, you may find it useful that dotMemory.exe is able to send service messages to stdout:

  • Start of the profiling session:

    ##dotMemory["connected", {pid: 1234}]

  • Saving the snapshot:

    ##dotMemory["workspace-saved", {path: "..."}]

Note that messages sent to stdin must always start from a new line and end with a carriage return. Both stdin and stdout messages have the format of a JSON array.

Get snapshots using API

Of course, we don’t forget about our profiling API. If you control profiling directly from your code using the dotMemory API, run dotMemory.exe with the -–use-api command. E.g.:

dotMemory.exe start --use-api C:\MyApp\MyApp.exe

We hope you’ll find the dotMemory console profiler useful and helpful in automating your profiling routines. As usual, we invite you to download the tool, try it on your own and share your experience.

This entry was posted in How-To's and tagged , , . Bookmark the permalink.

18 Responses to dotMemory Command Line Tools

  1. Pingback: Dew Drop - May 17, 2017 (#2481) - Morning Dew

  2. Constantine Colotiline says:

    Do you have a public specification of the dotMemory’s dmw file format or I can view a profiling’s result only in full dotMemory by design?

  3. David Banks says:

    Is the only way to analyse the snapshots through the dotMemory GUI?

    • Alexey Totin says:

      Hi David,
      Yes, only through the GUI. Though, in case of unit testing and CI, you can use dotMemory Unit to analyze snapshots right in your code.

  4. Manivas says:

    Do we have command line to compare to snapshot ? What we are looking for comparison of a given objects in two snapshot in command line.

    • Manivas says:

      I understand Command line tool is free license. We do have dotMemery full license. When we are worried about only particular objects. It would be nice if we have that under command line tool as well.

    • Alexey Totin says:

      Hi Manivas,
      the idea is that the command-line tool only gets profiling data. The analysis is performed in the standalone dotMemory. If you want to employ memory profiling for continuous integration, the best choice is dotMemory Unit. It allows writing “memory” tests: check for objects of the particular type, check traffic and, of course, compare snapshots:

      • MCI says:

        Is there a way to get a text output from the licensed dotmemory provided that you have a snapshot?
        I mean if I want this in my CI I want to be able to get a Jenkins graph of the snapshots and fail the builds based on output…
        Getting the snapshot files and then having to open them manually seems quite counterproductive!

        P.S DotMemory Unit does not help me because I need to run the whole program to get a comprehensive test.

  5. Pingback: .NET Blog

  6. Gautami Khandekar says:

    I am not able to get the snapshot when I use the command line :
    & .\StartupScripts\dotMemory.exe get-snapshot powershell –save-to-dir=D:\SnapShots

    I am using dotmemory command in a powershell script that runs as part of a startup script in visual studio project. I am able to get the snapshot when I run the script standalone, but it is not creating the snapshot when run as startup script when the project is started. I see that the dotmemory command is executed when it is run as startup scrip, but the snapshot is not getting created

    • Gautami Khandekar says:

      I just see this in the output:
      dotMemory Console Profiler 2019.1.3 build 191.0.20190709.205442. Copyright (C) 2017-2019 JetBrains s.r.o.
      Performs memory profiling of .NET applications

  7. Farhad Mammadli says:

    this is not working, tested on 2019.2.2
    However, it works with kb, mb, gb. Any workaround as a temp fix will be appreciated

    • Farhad Mammadli says:

      sorry, apparently cmd was omitting the percentage mark. to escape it I had to use –trigger-mem-inc=50%% in colsole

      • Alexey Totin says:

        Hi Farhad,
        it’s quite strange. It should work with the single percent symbol:
        Just checked it with 2019.3.4
        Could you please download 2019.3.4 and try it?

      • Alexey Totin says:

        Oh, sorry, I didn’t get it from the first time. You’re probably running dotMemory from a .bat file? Then yes, in a batch file, you have to use a double percent sign (%%) to yield a single percent sign (%).

Leave a Reply

Your email address will not be published. Required fields are marked *