dotMemory Command Line Tools

Posted on by Alexey Totin

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

or

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:

    ##dotMemory["disconnect"]

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.

Comments below can no longer be edited.

35 Responses to dotMemory Command Line Tools

  1. Dew Drop – March 9, 2016 (#2204) | Morning Dew says:

    March 9, 2016

    […] ReSharper Ultimate 10.1 EAP 5 (Dmitry Matveev) […]

  2. Mike-EEE says:

    March 9, 2016

    You’re doing great work, Team ReSharper! Very happy and proud to use your product!

  3. Laurent Kempé says:

    March 9, 2016

    Great!

    What about reformatting code when saving a file, in a non-blocking way, that would be just fantastic!

    • Dmitry Matveev says:

      March 9, 2016

      Hi Laurent,
      We have this request in our issue tracker. Please feel free to watch, comment and upvote.

  4. Richard Moss says:

    March 9, 2016

    Regarding TypeScript, are there any plans for improving the formatting of TSX files? I’m finding Resharper currently doesn’t do very little with JSX elements, and generally doesn’t seem to reformat TSX files well at all.

    • Dmitry Matveev says:

      March 10, 2016

      Hi Richard,
      This is once again a known issue. Unfortunately, this one will not make it into 10.1 but hopefully, we’ll fix it in the next version. Please don’t hesitate to watch and upvote the issue.

  5. Mike-EEE says:

    March 9, 2016

    Ahhh… I just installed EAP5 and it seems to have uninstalled all my Ultimate Extensions. Is this a known issue? This seems like something that should be warned about before installing if so. Now I have to go through and find all the extensions I had installed again. 🙁

    • Mike-EEE says:

      March 9, 2016

      And on that note… I had xUnit runner installed and it looks like it is no longer available? I do not see any of my xUnit tests anymore and cannot run them. Bummer. It would be nice to see all the extensions I lost, but I will be returning to 10.0.2 for now.

    • Mike-EEE says:

      March 9, 2016

      Sorry for being chatty here (if you used Disqus — http://disqus.com — for your community engagement I could simply edit my previous comment with this new information, FWIW!), but reverting back to 10.0.2 restored all my extensions… WHEW!

    • Mike-EEE says:

      March 15, 2016

      Since no one from JetBrains replied to this. 😛 I will make it clear here and specify that EAP5 appears to install into a different “hive” that is basically a different environment from what the current RTM is installed. So, you will “lose” any extensions installed as you are essentially/basically working in a new environment. Uninstalling the EAP will return you back to your previous environment with your extensions intact.

      It would definitely be great to see some sort of warning/description about this during the install process from JB so that newbs like me to this process are not taken aback. If there is already a warning/description then I was too busy/careless to read/see it FWIW. :p

  6. The Morning Brew - Chris Alcock » The Morning Brew #2049 says:

    March 10, 2016

    […] ReSharper Ultimate 10.1 EAP 5 – Dmitry Matveev […]

  7. Firefox 45, Meteor Galaxy für alle & Joomla! 3.5 RC says:

    March 10, 2016

    […] an dotCover und dotMemory Unit 2.2 durchgeführt. Weitere Informationen bietet der zugehörige Blogbeitrag; dort steht ReSharper Ultimate 10.1 EAP 5 auch zum Download zur […]

  8. Drew Noakes says:

    March 11, 2016

    Looks like this is going to be a great release. It’s nice to see these blog posts along with each EAP version too.

    On the reformat code feature, Ctrl+Alt+L is already used for focussing the Solution Explorer. That’s already burned into the memory of anyone who tries to avoid using the mouse as much as possible. Why not extend Ctrl+Alt+F with Ctrl+Alt+Shift+F?

    • Dmitry Matveev says:

      March 11, 2016

      Hi Drew,
      Thanks for the feedback. Ctrl+Alt+L is used in IntelliJ IDEA scheme because it’s the default shortcut for reformatting code in all products based on IntelliJ platform. And the shortuct for locating current document in Solution/Assembly Explorer is Shift+Alt+L (at least since ReSharper 8.0).

  9. Sebastian says:

    March 11, 2016

    Unfortunately, solution wide analysis gets worse with every version. It just reported 980 errors on a solution that builds totally fine (and where R# 10.0.2 didn’t report any errors – as there are none). Not even a rebuild or restarting Visual Studio helps anymore. Hope that this gets fixed for the final version.

    • Dmitry Matveev says:

      March 11, 2016

      Thanks for your feedback, Sebastian.
      Things like that can happen after upgrade because of stale caches. Please try Resharper > Options > Environment > General > Clear Caches and then
      Restart Visual Studio. If thins doesn’t help, could you plese share what kind of projects are affected and what kind of false errors are there?

  10. Beu Alexandru says:

    March 15, 2016

    Great work.

  11. Dew Drop - May 17, 2017 (#2481) - Morning Dew says:

    May 17, 2017

    […] dotMemory Command Line Tools (Alexey Totin) […]

  12. Constantine Colotiline says:

    June 1, 2017

    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?

    • Alexey Totin says:

      June 2, 2017

      Hi Constantine,
      Yes, currently, you can view profiling results only in dotMemory.

  13. David Banks says:

    December 1, 2017

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

    • Alexey Totin says:

      December 4, 2017

      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.

  14. Manivas says:

    March 23, 2018

    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:

      March 23, 2018

      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:

      March 26, 2018

      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: https://www.jetbrains.com/help/dotmemory-unit/Comparing_Snapshots0.html

      • MCI says:

        September 20, 2019

        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.

        • Alexey Totin says:

          September 23, 2019

          Hi,
          currently, it’s not possible. We have it in plans but with no exact date yet

  15. .NET Blog says:

    September 7, 2018

    […] dotMemory Command Line Tools by Alexey Totin. […]

  16. Gautami Khandekar says:

    August 21, 2019

    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:

      August 21, 2019

      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

      • Alexey Totin says:

        September 5, 2019

        Hi Guatami,
        could you please provide an example of the script you use?

  17. Farhad Mammadli says:

    March 3, 2020

    –trigger-mem-inc=50%
    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:

      March 3, 2020

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

      • Alexey Totin says:

        March 3, 2020

        Hi Farhad,
        it’s quite strange. It should work with the single percent symbol:
        –trigger-mem-inc=50%
        Just checked it with 2019.3.4
        Could you please download 2019.3.4 and try it?

      • Alexey Totin says:

        March 3, 2020

        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 (%).

Subscribe

Subscribe to .NET Tools updates