dotTrace 2024.1 Help

Profile Application in Docker Container

To profile a .NET application running inside a Docker container, use the dotTrace 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>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 dotTrace command-line tool, for example, to the dotTrace folder:

    apt-get update -y && apt-get install -y wget && \ wget -O && \ apt-get install -y unzip && \ unzip -d ./dotTrace && \ chmod +x -R dotTrace/*


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

    • JetBrains.dotTrace.CommandLineTools.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 attach to the process with PID 1 and use stdin message to get snapshots:

    ./dotTrace/tools/dottrace attach 1 --service-input=stdin

    To get a snapshot, send:


    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 snapshot files to the host machine. Note that dotTrace saves snapshot as multiple files, e.g., somename.dtp, somename.dtp.0000, somename.dtp.0001, and so on. Therefore, you should first put them to an archive in the container. On the host machine:

    1. Create an archive:

      docker exec my-aspnet-app-container sh -c "tar -czf /tmp/snapshot.tar.gz /app/somename.dtp*"
    2. Copy the archive to the host:

      docker cp my-aspnet-app-container:/tmp/snapshot.tar.gz /home/username/Snapshots/snapshot.tar.gz
    3. Unpack the archive:

      tar -xzf /home/username/Snapshots/snapshot.tar.gz -C /home/username/Snapshots
  10. Analyze the collected snapshots.

Last modified: 10 April 2024