Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Profiling in Docker container

To profile a .NET application or a server running in a Docker container, you should run it with the profiler agent, and then use remote profiling in the profiler UI, as described below.

Enable profiling in Linux Docker images

  • Add a new stage to your Dockerfile. For example:

    FROM alpine as yourkit-stage
    RUN wget -q https://www.yourkit.com/dotnet/download/docker/YourKit-NetProfiler-2022.3-docker.zip
    RUN unzip -q YourKit-NetProfiler-2022.3-docker.zip
  • Copy profiler files and enable profiling in your image. For example:

    # Copy profiler files from the previous stage
    COPY --from=yourkit-stage /YourKit-NetProfiler /YourKit-NetProfiler
    
    # Enable profiling
    ENV CORECLR_ENABLE_PROFILING="1" \
        CORECLR_PROFILER="{E5A4ADC4-C749-400D-B066-6AC8C1D3790A}" \
        CORECLR_PROFILER_PATH_64="/YourKit-NetProfiler/bin/linux-x86-64/libynpagent.so" \
        YNP_STARTUP_OPTIONS="listen=all,port=10001"

    Please choose an appropriate agent path for your docker architecture. The path in the example above corresponds to Linux x64 (glibc), please replace it if your docker architecture differs.

    Platform Agent path
    Linux (glibc), x86-64 /YourKit-NetProfiler/bin/linux-x86-64/libynpagent.so
    Alpine Linux (musl), x86-64 /YourKit-NetProfiler/bin/linux-musl-x86-64/libynpagent.so

Enable profiling in Windows Docker images

  • Add a new stage to your Dockerfile. For example:

    FROM mcr.microsoft.com/windows/nanoserver:2004 as yourkit-stage
    RUN curl -fLOSs https://www.yourkit.com/dotnet/download/docker/YourKit-NetProfiler-2022.3-docker.zip
    RUN tar xf YourKit-NetProfiler-2022.3-docker.zip -C c:
  • Copy profiler files and enable profiling in your image. For example:

    # Copy profiler files from the previous stage
    COPY --from=yourkit-stage /YourKit-NetProfiler /YourKit-NetProfiler
    
    # Enable profiling
    ENV CORECLR_ENABLE_PROFILING="1" \
        CORECLR_PROFILER="{E5A4ADC4-C749-400D-B066-6AC8C1D3790A}" \
        CORECLR_PROFILER_PATH_32="C:\YourKit-NetProfiler\bin\win32\ynpagent.dll" \
        CORECLR_PROFILER_PATH_64="C:\YourKit-NetProfiler\bin\win64\ynpagent.dll" \
        COR_ENABLE_PROFILING="1" \
        COR_PROFILER="{E5A4ADC4-C749-400D-B066-6AC8C1D3790A}" \
        COR_PROFILER_PATH_32="C:\YourKit-NetProfiler\bin\win32\ynpagent.dll" \
        COR_PROFILER_PATH_64="C:\YourKit-NetProfiler\bin\win64\ynpagent.dll" \
        YNP_STARTUP_OPTIONS="listen=all,port=10001"

Run Docker container

In this example, the agent is configured to use port=10001. Make sure that the port is available outside of Docker with the -p flag when running the container:

docker run -p 10001:10001 my_container

Connect to the profiled application

When the application is running in the container, connect to it from the profiler UI using the mapped port.

If you run Docker container and the profiler UI on the same machine, create a remote connection to localhost.

Collect profiler snapshots and logs

If you can't or don't want to connect the profiler UI to the Docker container, and instead automatically control profiling and snapshot capturing, you may want to use the startup option dir to override default snapshot directory. Map this directory in Docker, for example with -v flag, and analyze snapshots later.

Should you need the agent log file for troubleshooting purposes, map a host directory to the container and specify it with the startup option logdir.

Complete example

  • Dockerfile content:

    FROM alpine as yourkit-stage
    RUN wget -q https://www.yourkit.com/dotnet/download/docker/YourKit-NetProfiler-2022.3-docker.zip
    RUN unzip -q YourKit-NetProfiler-2022.3-docker.zip
    
    FROM mcr.microsoft.com/dotnet/samples:aspnetapp
    
    # Copy profiler files from the previous stage
    COPY --from=yourkit-stage /YourKit-NetProfiler /YourKit-NetProfiler
    
    # Enable profiling
    ENV CORECLR_ENABLE_PROFILING="1" \
        CORECLR_PROFILER="{E5A4ADC4-C749-400D-B066-6AC8C1D3790A}" \
        CORECLR_PROFILER_PATH_64="/YourKit-NetProfiler/bin/linux-x86-64/libynpagent.so" \
        YNP_STARTUP_OPTIONS="listen=all,logdir=/logs,dir=/snapshots,sampling"
  • Command line:

    mkdir -p $(pwd)/logs
    mkdir -p $(pwd)/snapshots
    docker build $(pwd) -t yourkit-demo
    docker run -p 10001-10010:10001-10010 -v $(pwd)/logs:/logs -v $(pwd)/snapshots:/snapshots yourkit-demo

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.