dotMemory 2024.2 Help

Profile Application in Docker Container

To profile a .NET application running inside a Docker container, use the dotMemory command-line profiler. To download the profiler and start a profiling session, you should have access to the container shell.

  1. Log in to the host machine running Docker.

  2. To be able to communicate with the application container, we must know either its ID or name. To get them, run:

    docker ps

    Sample output:

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e58110265dd6 my-aspnet-app "dotnet MyAspNetApp.…" 22 hours ago Up 22 hours 0.0.0.0:5142->5142/tcp my-aspnet-app-container

    Here e58110265dd6 is the container ID and my-aspnet-app-container is the name.

  3. Start a shell session inside the Docker container. You can use different command-line interpreters depending on the image OS, for example, sh or /bin/bash.

    docker exec -it {container_ID_or_name} sh

    For example:

    docker exec -it my-aspnet-app-container sh
  4. In the container, download and unzip the dotMemory command-line tool, for example, to the dotMemoryclt folder:

    apt-get update -y && apt-get install -y wget && \ wget -O dotMemoryclt.zip https://www.nuget.org/api/v2/package/JetBrains.dotMemory.Console.linux-x64 && \ apt-get install -y unzip && \ unzip dotMemoryclt.zip -d ./dotMemoryclt && \ chmod +x -R dotMemoryclt/*

    Here:

    • apt is the package manager for Debian-based systems. If your OS uses other package manager, use it instead of apt.

    • JetBrains.dotMemory.Console.linux-x64 is the package name for the Linux x64 systems. This name will vary depending on a target platform. Here you can find the full list of packages for various platforms.

  5. Before you can attach to the process you want to profile, you must get the process ID:

    ps aux

    If the ps command is not available in your Linux distribution, install it with:

    apt-get update && apt-get install procps

    Sample output:

    # ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 1.2 276055932 200960 ? Ssl Mar23 0:21 dotnet MyAspNetApp.dll --urls http://*:5142 root 914 0.0 0.0 2480 580 pts/0 Ss 05:33 0:00 sh root 2171 0.0 0.0 6756 2940 pts/0 R+ 12:55 0:00 ps aux
  6. Profile the process. For example:

    • To instantly get a snapshot of the process with PID 1:

      ./dotMemoryclt/tools/dotmemory get-snapshot 1
    • To attach to the process with PID 1:

      ./dotMemoryclt/tools/dotmemory attach 1

      To get snapshots, use stdin messages:

      ##dotMemory["get-snapshot"]

    For more information about working with the command-line tool, refer to the corresponding topic.

  7. To stop profiling and save collected data, press Ctrl+C.

  8. To end the shell session in the container, run exit.

  9. Copy the workspace file to the host machine. To do this, run the following command on the host machine:

    docker cp {container_ID_or_name}:/{path_to_workspace_file} {path_to_folder_on_host_machine}

    For example:

    docker cp my-aspnet-app-container:/app/[1]-dotnet.2023-03-24T16-10-18.136.dmw "/home/username/Documents/Workspaces"
  10. Analyze the collected snapshots.

Last modified: 21 March 2024