Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions correctness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion scenarios/ddprof_inline/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions scenarios/ddprof_inline/expected_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion scenarios/ddprof_inline/inline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -34,7 +38,7 @@ int main() {
intensiveTask(intensiveEndTime);

auto moreIntensiveEndTime = totalStartTime + std::chrono::milliseconds(1000); // full second
moreIntensiveTask(moreIntensiveEndTime);
foo(moreIntensiveEndTime);
}
return 0;
}
Binary file added scenarios/ddprof_inline/inline_test
Binary file not shown.
31 changes: 31 additions & 0 deletions scenarios/java_11.0.20/CpuBurner.java
Original file line number Diff line number Diff line change
@@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Vulnerability

Use of insecure random values (...read more)

Functions as Math.random() and objects like java.util.Random() do not provide strong enough randomness. Consider using java.security.SecureRandom() instead.

View in Datadog  Leave us feedback  Documentation

}
});
}

try {
Thread.sleep(executionTimeSec * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

executor.shutdownNow();
System.out.println("CPU intensive tasks stopped.");
}
}
40 changes: 40 additions & 0 deletions scenarios/java_11.0.20/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions scenarios/java_11.0.20/expected_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_name": "java_basic",
"scale_by_duration": true,
"stacks": []
}
31 changes: 31 additions & 0 deletions scenarios/java_alpine3.21.3_Java21/CpuBurner.java
Original file line number Diff line number Diff line change
@@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Vulnerability

Use of insecure random values (...read more)

Functions as Math.random() and objects like java.util.Random() do not provide strong enough randomness. Consider using java.security.SecureRandom() instead.

View in Datadog  Leave us feedback  Documentation

}
});
}

try {
Thread.sleep(executionTimeSec * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

executor.shutdownNow();
System.out.println("CPU intensive tasks stopped.");
}
}
38 changes: 38 additions & 0 deletions scenarios/java_alpine3.21.3_Java21/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions scenarios/java_alpine3.21.3_Java21/expected_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_name": "java_basic",
"scale_by_duration": true,
"stacks": []
}
32 changes: 32 additions & 0 deletions scenarios/java_basic/CpuBurner.java
Original file line number Diff line number Diff line change
@@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Vulnerability

Use of insecure random values (...read more)

Functions as Math.random() and objects like java.util.Random() do not provide strong enough randomness. Consider using java.security.SecureRandom() instead.

View in Datadog  Leave us feedback  Documentation

}
});
}

try {
Thread.sleep(executionTimeSec * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

executor.shutdownNow();
System.out.println("CPU intensive tasks stopped.");
}
}
24 changes: 24 additions & 0 deletions scenarios/java_basic/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions scenarios/java_basic/expected_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_name": "java_basic",
"scale_by_duration": true,
"stacks": []
}