Skip to content

Commit cf77dde

Browse files
committed
Run Java JFR scenario with Datadog profiler
1 parent 321758f commit cf77dde

4 files changed

Lines changed: 42 additions & 21 deletions

File tree

analysis/jfr.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ func FromJFR(data []byte) (*ProfileSet, error) {
4242
continue
4343
}
4444

45-
fields, err := decodeJFREventFields(event.Type, event.Data, &p.TypeMap)
46-
if err != nil {
47-
return nil, fmt.Errorf("jfr decode %s: %w", event.Type.Name, err)
48-
}
49-
5045
switch event.Type.Name {
5146
case "jdk.ExecutionSample", "datadog.ExecutionSample":
47+
fields, err := decodeJFREventFields(event.Type, event.Data, &p.TypeMap)
48+
if err != nil {
49+
return nil, fmt.Errorf("jfr decode %s: %w", event.Type.Name, err)
50+
}
5251
addJFRCPU(ps, p, fields)
5352
}
5453
}

scenarios/java_cpu_jfr/Dockerfile

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@ FROM eclipse-temurin:21-jdk
22

33
WORKDIR /app
44

5-
# Copy and compile the Java source
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends curl ca-certificates \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Install the Datadog Java tracer, which carries the Datadog native Java
10+
# profiler (ddprof). The profiler writes Datadog-specific JFR events such as
11+
# datadog.ExecutionSample; this scenario validates that prof-correctness can
12+
# consume those recordings directly.
13+
RUN curl -fsSL -o /app/dd-java-agent.jar https://dtdg.co/latest-java-tracer
14+
615
COPY ./scenarios/java_cpu_jfr/DummyApp.java .
716
RUN javac DummyApp.java
817

9-
# Force re-run of the next layer when the cache date changes.
10-
ARG CACHE_DATE=2024-01-01
11-
12-
# EXECUTION_TIME_SEC is injected by the test harness; default to 30 s.
13-
ENV EXECUTION_TIME_SEC=30
18+
# EXECUTION_TIME_SEC is injected by the test harness; default to 60 s.
19+
ENV EXECUTION_TIME_SEC=60
1420

15-
# Run with built-in JFR.
16-
# -XX:+FlightRecorder : enable JFR (no-op on JDK 11+ where it's always on)
17-
# -XX:StartFlightRecording=... : start a continuous recording; dump on JVM exit.
18-
# settings=profile : enable CPU/alloc/lock profiling at low overhead.
19-
CMD java \
20-
-XX:+FlightRecorder \
21-
"-XX:StartFlightRecording=filename=/app/data/profile.jfr,dumponexit=true,settings=profile,name=correctness" \
22-
DummyApp
21+
# Run the app under the Datadog Java profiler and use the tracer's built-in
22+
# debug dump path to persist the JFR snapshot locally. The prof-correctness
23+
# harness finds the timestamped dd-profiler-debug-*.jfr file by regex.
24+
CMD sh -eu -c '\
25+
mkdir -p /app/data/dumps /app/data/tmp; \
26+
java \
27+
-javaagent:/app/dd-java-agent.jar \
28+
-Ddd.service=prof-correctness-java-cpu-jfr \
29+
-Ddd.env=local \
30+
-Ddd.trace.enabled=false \
31+
-Ddd.profiling.enabled=true \
32+
-Ddd.profiling.ddprof.enabled=true \
33+
-Ddd.profiling.ddprof.cpu.enabled=true \
34+
-Ddd.profiling.ddprof.wall.enabled=false \
35+
-Ddd.profiling.upload.period=30 \
36+
-Ddd.profiling.upload.timeout=1 \
37+
-Ddd.profiling.start-force-first=true \
38+
-Ddd.profiling.tempdir=/app/data/tmp \
39+
-Ddd.profiling.debug.dump_path=/app/data/dumps \
40+
-Ddd.profiling.url=http://127.0.0.1:8126/ \
41+
-Ddd.telemetry.enabled=false \
42+
-Ddd.jmxfetch.enabled=false \
43+
DummyApp \
44+
'

scenarios/java_cpu_jfr/DummyApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Simple CPU-intensive app for JFR correctness testing.
33
*
44
* Continuously computes Fibonacci numbers to keep the CPU busy.
5-
* The JFR recording is started by the JVM flags passed on the command line;
5+
* The Datadog Java profiler is started by the JVM flags passed on the command line;
66
* this app just runs for the requested duration and exits.
77
*
88
* The EXECUTION_TIME_SEC environment variable (default: 30) controls how long

scenarios/java_cpu_jfr/expected_profile.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"test_name": "java_cpu_jfr",
3-
"pprof-regex": ".*\\.jfr$",
3+
"pprof-regex": "^dd-profiler-debug-.*\\.jfr$",
44
"stacks": [
55
{
66
"profile-type": "cpu",

0 commit comments

Comments
 (0)