Enabling the Java Profiler

Enabling the Java Profiler

このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。

The Continuous Profiler is not available for the Datadog site.

The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and go directly to enabling the profiler.

Requirements

The Datadog Profiler requires JDK Flight Recorder. The Datadog Profiler library is supported in OpenJDK 11+, Oracle JDK 11+, OpenJDK 8 (version 8u262+) and Azul Zulu 8+ (version 8u212+). It is not supported in OpenJ9 as it doesn’t support the JDK Flight Recorder.

All JVM-based languages, such as Java, Scala, Groovy, Kotlin, and Clojure are supported.

Installation

To begin profiling applications:

  1. If you are already using Datadog, upgrade your Agent to version 7.20.2+ or 6.20.2+. If you don’t have APM enabled to set up your application to send data to Datadog, in your Agent, set the DD_APM_ENABLED environment variable to true and listening to the port 8126/TCP.

  2. Download dd-java-agent.jar, which contains the Java Agent class files:

    wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'
    

    Note: Profiler is available in the dd-java-agent.jar library in versions 0.55+.

  3. Set -Ddd.profiling.enabled flag or DD_PROFILING_ENABLED environment variable to true. Your service invocation should look like:

    java \
        -javaagent:dd-java-agent.jar \
        -Ddd.service=<YOUR_SERVICE> \
        -Ddd.env=<YOUR_ENVIRONMENT> \
        -Ddd.version=<YOUR_VERSION> \
        -Ddd.profiling.enabled=true \
        -XX:FlightRecorderOptions=stackdepth=256 \
        -jar <YOUR_SERVICE>.jar <YOUR_SERVICE_FLAGS>
    

    Recommendation: Specify dd.service, dd.env, and dd.version so you can slice and dice your profiles across these dimensions.

    You can also use environment variables to set the parameters as such:

    export DD_SERVICE=<YOUR_SERVICE>
    export DD_ENV=<YOUR_ENV>
    export DD_VERSION=<YOUR_VERSION>
    export DD_PROFILING_ENABLED=true
    java \
        -javaagent:dd-java-agent.jar \
        -XX:FlightRecorderOptions=stackdepth=256 \
        -jar <YOUR_SERVICE>.jar <YOUR_SERVICE_FLAGS>
    

    Note: The -javaagent argument needs to be before -jar, adding it as a JVM option rather than an application argument. For more information, see the Oracle documentation:

    # Good:
    java -javaagent:dd-java-agent.jar ... -jar my-service.jar -more-flags
    # Bad:
    java -jar my-service.jar -javaagent:dd-java-agent.jar ...
    
  4. After a minute or two, you can visualize your profiles on the Datadog APM > Profiling page.

Enabling the allocation profiler

In dd-java-agent v0.84.0+ and Java 15 and lower, the allocation profiler is opt-in because it can use excessive CPU in allocation-heavy applications. This isn’t common, so you may want to try it in a staging environment to see if it affects your application. To enable it, see Enabling the allocation profiler.

Configuration

You can configure the profiler using the following environment variables:

Environment variableTypeDescription
DD_PROFILING_ENABLEDBooleanAlternate for -Ddd.profiling.enabled argument. Set to true to enable profiler.
DD_PROFILING_ALLOCATION_ENABLEDBooleanAlternate for -Ddd.profiling.allocation.enabled argument. Set to true to enable the allocation profiler. It requires the profiler to be enabled already.
DD_SERVICEStringYour service name, for example, web-backend.
DD_ENVStringYour environment name, for example: production.
DD_VERSIONStringThe version of your service.
DD_TAGSStringTags to apply to an uploaded profile. Must be a list of <key>:<value> separated by commas such as: layer:api, team:intake.

Not sure what to do next?

The Getting Started with Profiler guide takes a sample service with a performance problem and shows you how to use Continuous Profiler to understand and fix the problem.

Further Reading