diff --git a/correctness_test.go b/correctness_test.go index f99990b..e80f9b9 100644 --- a/correctness_test.go +++ b/correctness_test.go @@ -142,6 +142,11 @@ func runTestApp(t *testing.T, dockerTag string, folder string) string { } args = append(args, "-e", "DD_SERVICE=prof-correctness-"+strings.Split(folder, "/")[1]) args = append(args, "test-app:latest") + // default socket path for Datadog + // socketPath := "/var/run/containerd/containerd.sock" + // if _, err := os.Stat(socketPath); err == nil { + // args = append(args, "-v", socketPath+":"+socketPath) + // } t.Log("Docker run command: docker ", strings.Join(args, " ")) cmd := exec.Command("docker", args...) out, err := cmd.CombinedOutput() diff --git a/scenarios/ddprof_inline/Dockerfile b/scenarios/ddprof_inline/Dockerfile index 3d31307..5d130e2 100644 --- a/scenarios/ddprof_inline/Dockerfile +++ b/scenarios/ddprof_inline/Dockerfile @@ -5,4 +5,4 @@ ADD ./scenarios/ddprof_inline/inline.cc . ADD ./scenarios/ddprof_inline/build.sh . RUN ./build.sh -CMD /app/run_ddprof.sh -l notice --show_config ./inline_test +CMD /app/run_ddprof.sh -l notice --inlined_functions true --show_config ./inline_test diff --git a/scenarios/ddprof_inline/expected_profile.json b/scenarios/ddprof_inline/expected_profile.json index 422355d..ec941e8 100644 --- a/scenarios/ddprof_inline/expected_profile.json +++ b/scenarios/ddprof_inline/expected_profile.json @@ -8,6 +8,11 @@ "regular_expression": ";_start;__libc_start_main;main;intensiveTask.*", "percent": 33, "error_margin": 3 + }, + { + "regular_expression": ";_start;__libc_start_main;main;foo;moreIntensiveTask.*", + "percent": 66, + "error_margin": 3 } ] } diff --git a/scenarios/ddprof_inline/inline.cc b/scenarios/ddprof_inline/inline.cc index 89da297..fcc7cd9 100644 --- a/scenarios/ddprof_inline/inline.cc +++ b/scenarios/ddprof_inline/inline.cc @@ -20,6 +20,10 @@ inline void moreIntensiveTask(std::chrono::steady_clock::time_point endTime) { } } +inline void foo(std::chrono::steady_clock::time_point endTime) { + moreIntensiveTask(endTime); +} + int main() { const char* envVar = std::getenv("EXECUTION_TIME_SEC"); if (!envVar) { @@ -34,7 +38,7 @@ int main() { intensiveTask(intensiveEndTime); auto moreIntensiveEndTime = totalStartTime + std::chrono::milliseconds(1000); // full second - moreIntensiveTask(moreIntensiveEndTime); + foo(moreIntensiveEndTime); } return 0; } diff --git a/scenarios/ddprof_inline/inline_test b/scenarios/ddprof_inline/inline_test new file mode 100755 index 0000000..901084f Binary files /dev/null and b/scenarios/ddprof_inline/inline_test differ diff --git a/scenarios/java_11.0.20/CpuBurner.java b/scenarios/java_11.0.20/CpuBurner.java new file mode 100644 index 0000000..d865219 --- /dev/null +++ b/scenarios/java_11.0.20/CpuBurner.java @@ -0,0 +1,31 @@ +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + +public class CpuBurner { + public static void main(String[] args) { + int numThreads = 2; + ExecutorService executor = Executors.newFixedThreadPool(numThreads); + + int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); + + System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); + + for (int i = 0; i < numThreads; i++) { + executor.submit(() -> { + while (!Thread.currentThread().isInterrupted()) { + double value = Math.pow(Math.random(), Math.random()); + } + }); + } + + try { + Thread.sleep(executionTimeSec * 1000L); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + executor.shutdownNow(); + System.out.println("CPU intensive tasks stopped."); + } +} diff --git a/scenarios/java_11.0.20/Dockerfile b/scenarios/java_11.0.20/Dockerfile new file mode 100644 index 0000000..5634be6 --- /dev/null +++ b/scenarios/java_11.0.20/Dockerfile @@ -0,0 +1,40 @@ +# Use Rocky Linux 9.3 as base image +FROM rockylinux:9.3 + +# Install Temurin JDK 11.0.20.1+1 +RUN dnf install -y \ + glibc-langpack-en \ + && dnf clean all \ + && curl -LO https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.20.1%2B1/OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz \ + && tar -xzf OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz -C /opt/ \ + && rm OpenJDK11U-jdk_x64_linux_hotspot_11.0.20.1_1.tar.gz + +# Set JAVA_HOME environment variable +ENV JAVA_HOME=/opt/jdk-11.0.20.1+1 +ENV PATH="${JAVA_HOME}/bin:${PATH}" + +# Set environment variables for Datadog +ENV DD_SERVICE=cpu-burner-app +ENV DD_ENV=production +ENV DD_PROFILING_ENABLED=true +ENV DD_LOGS_INJECTION=true +ENV DD_TRACE_DEBUG=true +ENV DD_PROFILING_LOG_LEVEL=debug +ENV KEEP_JFRS=true + +# Install Datadog Java agent +RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar + +# Set working directory +WORKDIR /app + +# Copy Java application to the container +COPY ./scenarios/java_basic/CpuBurner.java . + +# Compile Java application +RUN javac CpuBurner.java + + +ENV DD_PROFILING_DDPROF_ENABLED=true +# Run the application with Datadog profiler +CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] diff --git a/scenarios/java_11.0.20/expected_profile.json b/scenarios/java_11.0.20/expected_profile.json new file mode 100644 index 0000000..9608c96 --- /dev/null +++ b/scenarios/java_11.0.20/expected_profile.json @@ -0,0 +1,5 @@ +{ + "test_name": "java_basic", + "scale_by_duration": true, + "stacks": [] +} diff --git a/scenarios/java_alpine3.21.3_Java21/CpuBurner.java b/scenarios/java_alpine3.21.3_Java21/CpuBurner.java new file mode 100644 index 0000000..d865219 --- /dev/null +++ b/scenarios/java_alpine3.21.3_Java21/CpuBurner.java @@ -0,0 +1,31 @@ +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + +public class CpuBurner { + public static void main(String[] args) { + int numThreads = 2; + ExecutorService executor = Executors.newFixedThreadPool(numThreads); + + int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); + + System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); + + for (int i = 0; i < numThreads; i++) { + executor.submit(() -> { + while (!Thread.currentThread().isInterrupted()) { + double value = Math.pow(Math.random(), Math.random()); + } + }); + } + + try { + Thread.sleep(executionTimeSec * 1000L); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + executor.shutdownNow(); + System.out.println("CPU intensive tasks stopped."); + } +} diff --git a/scenarios/java_alpine3.21.3_Java21/Dockerfile b/scenarios/java_alpine3.21.3_Java21/Dockerfile new file mode 100644 index 0000000..f5eefe5 --- /dev/null +++ b/scenarios/java_alpine3.21.3_Java21/Dockerfile @@ -0,0 +1,38 @@ +# Use Alpine latest as base image +FROM alpine:3.21.3 + + +# Install dependencies and Temurin JDK 21.0.6+7 +RUN apk add --no-cache \ + bash \ + curl \ + openjdk21 \ + && ln -sf /usr/lib/jvm/java-21-openjdk /opt/jdk-21.0.6+7 + +# Set JAVA_HOME environment variable +ENV JAVA_HOME=/opt/jdk-21.0.6+7 +ENV PATH="${JAVA_HOME}/bin:${PATH}" + +# Set environment variables for Datadog +ENV DD_SERVICE=cpu-burner-app +ENV DD_ENV=production +ENV DD_PROFILING_ENABLED=true +ENV DD_LOGS_INJECTION=true +ENV DD_TRACE_DEBUG=true +ENV DD_PROFILING_LOG_LEVEL=debug +ENV KEEP_JFRS=true + +# Install Datadog Java agent +RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar + +# Set working directory +WORKDIR /app + +# Copy Java application to the container +COPY ./scenarios/java_basic/CpuBurner.java . + +# Compile Java application +RUN javac CpuBurner.java + +# Run the application with Datadog profiler +CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] diff --git a/scenarios/java_alpine3.21.3_Java21/expected_profile.json b/scenarios/java_alpine3.21.3_Java21/expected_profile.json new file mode 100644 index 0000000..9608c96 --- /dev/null +++ b/scenarios/java_alpine3.21.3_Java21/expected_profile.json @@ -0,0 +1,5 @@ +{ + "test_name": "java_basic", + "scale_by_duration": true, + "stacks": [] +} diff --git a/scenarios/java_basic/CpuBurner.java b/scenarios/java_basic/CpuBurner.java new file mode 100644 index 0000000..25bda9e --- /dev/null +++ b/scenarios/java_basic/CpuBurner.java @@ -0,0 +1,32 @@ +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + +public class CpuBurner { + public static void main(String[] args) { + // int numThreads = Runtime.getRuntime().availableProcessors(); + int numThreads = 2; // avoid overloading system + ExecutorService executor = Executors.newFixedThreadPool(numThreads); + + int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60")); + + System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds..."); + + for (int i = 0; i < numThreads; i++) { + executor.submit(() -> { + while (!Thread.currentThread().isInterrupted()) { + double value = Math.pow(Math.random(), Math.random()); + } + }); + } + + try { + Thread.sleep(executionTimeSec * 1000L); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + executor.shutdownNow(); + System.out.println("CPU intensive tasks stopped."); + } +} diff --git a/scenarios/java_basic/Dockerfile b/scenarios/java_basic/Dockerfile new file mode 100644 index 0000000..a0da490 --- /dev/null +++ b/scenarios/java_basic/Dockerfile @@ -0,0 +1,24 @@ +# Use OpenJDK 18 as base image +FROM openjdk:18-jdk + +# Set environment variables for Datadog +ENV DD_SERVICE=cpu-burner-app +ENV DD_ENV=production +ENV DD_PROFILING_ENABLED=true +ENV DD_LOGS_INJECTION=true +ENV DD_TRACE_DEBUG=true +ENV DD_PROFILING_LOG_LEVEL=debug +ENV KEEP_JFRS=true + +# Install Datadog Java agent +RUN curl -LO https://dtdg.co/latest-java-tracer && mv latest-java-tracer dd-java-agent.jar + +# Copy Java application to the container +WORKDIR /app +COPY ./scenarios/java_basic/CpuBurner.java . + +# Compile Java application +RUN javac CpuBurner.java + +# Run the application with Datadog profiler +CMD ["java", "-javaagent:/dd-java-agent.jar", "CpuBurner"] diff --git a/scenarios/java_basic/expected_profile.json b/scenarios/java_basic/expected_profile.json new file mode 100644 index 0000000..9608c96 --- /dev/null +++ b/scenarios/java_basic/expected_profile.json @@ -0,0 +1,5 @@ +{ + "test_name": "java_basic", + "scale_by_duration": true, + "stacks": [] +}