Memory profiling on Linux and macOS with dotMemory 2020.2
Version 2020.2 EAP01 finally brings dotMemory to Linux and macOS! For these systems, dotMemory is currently available only as a command-line tool. The tool is free and lets you take and save memory snapshots. To analyze the snapshots, you still need the standalone version of dotMemory, which is only available on Windows.
What you can profile
Here’s the dotMemory compatibility list for Linux and macOS:
How it is distributed
The command-line tool is distributed in two forms:
- A .tar.gz archive (macOS | Linux): Download it from the JetBrains website, unpack, and run
dotMemory.shwith the required arguments.
- A NuGet package at nuget.org (macOS | Linux): Using this could be more convenient in automation scenarios (e.g. on a CI/CD server): reference the package in your project, and run
nuget restoreto get the tool on your server.
How to use it
If you have already used the dotMemory command-line profiler on Windows, you will find almost no differences (the only difference is the reduced set of commands, as some types of apps like IIS are not available on Linux and macOS). For those who haven’t, let’s go through the basics.
Get a snapshot of a running .NET Core app
The fastest way to get a snapshot of a running process is to use the
get-snapshot command. For example, this command takes gets a snapshot of the process with ID 5589:
./dotMemory.sh get-snapshot 5589
Run a .NET Core app under profiling
Note that to perform
get-snapshot, dotMemory has to attach to the process, and therefore it has the same limitations as the
attach command: it’s applicable only to processes that use .NET Core version 3.0 or later on Linux or .NET 5 on macOS. So, to profile an app that uses .NET Core 2.2 or earlier, you should run this application under profiling with the
start-net-core command. For example:
./dotMemory.sh start-net-core MyKestrelAspApp.dll
But how can you get snapshots? One of the ways is to send commands to dotMemory’s stdin. For example, to get a snapshot, send:
Another way to get a snapshot is to set a condition for taking the snapshot. This can be great for monitoring applications. For example:
./dotMemory.sh start-net-core --trigger-timer=10h MyKestrelAspApp.dll
This will start MyKestrelAspApp.dll and take snapshots every 10 hours.
./dotMemory.sh start-net-core --trigger-mem-inc=50% --trigger-delay=5s MyKestrelAspApp.dll
This will start MyKestrelAspApp.dll and take snapshots when memory consumption increases by 50% compared to when the profiling session started. The 5-second delay is used to ignore the application’s startup activities.
We invite you to download the tool and try it on Linux and macOS for yourself. As always, your comments are greatly appreciated.
P.S. If you are looking at other possibilities for profiling your code, take a look at dotMemory self-profiling API. It lets you profile your application right from the source code, is distributed as a NuGet package, and works on all platforms.
Subscribe to Blog updates
Thanks, we've got you!
Another Look into the Future with Rider’s Predictive Debugger
In the 2023.2 release cycle, we’ve introduced the Predictive Debugger in ReSharper, which gives you predictions about code paths and variables beyond the current execution pointer. We’ve written extensively about its advantages compared to alternative debugging strategies like thorough thinking, log…
Visualize Entity Framework Relationships and Additional Query Analysis in ReSharper 2023.3
A lot of teams are using Entity Framework or EF Core to work with their database. As an Object-Relational Mapper (ORM), it bridges objects in code to a relational database model, so that as a developer you don’t have to worry too much about the actual database. We all know: that’s not entirely tr…
Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis
Slow web pages may make your users or customers abandon your web application, even before they’ve had a proper look at it. You’ve likely also been frustrated working with a web application that is slow to load. The good news is that the latest versions of ReSharper and JetBrains Rider’s Dynamic P…
OSS Power-Ups: MassTransit – Webinar Recording
The recording of our webinar, OSS Power-Ups: MassTransit, with Chris Patterson, is available. This was the thirteenth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.…