From 4af4bc221ad7860fade7929e97856271f3c8cc8b Mon Sep 17 00:00:00 2001 From: Brice Dutheil Date: Mon, 6 Jul 2026 15:34:46 +0200 Subject: [PATCH] chore: Allow to profile workers with async-profiler --- build.gradle.kts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 254d9927817..38ec379320f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -108,6 +108,24 @@ allprojects { } } + System.getProperty("datadog.forkedAsyncProfiler")?.let { raw -> + val options = if (raw.isBlank() || raw == "true") "all" else raw.removePrefix("start,") + val lib = + System.getProperty("datadog.forkedAsyncProfilerLib", "/opt/homebrew/lib/libasyncProfiler.dylib") + val libFile = file(lib) + if (!libFile.exists()) { + logger.warn("async-profiler library not found at: $lib") + logger.warn("To install async-profiler on macOS, run: 'brew install async-profiler'") + logger.warn("Skipping async-profiler configuration for tests") + } else { + val outDir = System.getProperty("datadog.forkedAsyncProfilerDir", "/tmp") + tasks.withType().configureEach { + // %p keeps one recording per worker JVM (maxParallelForks / forkEvery may spawn several). + jvmArgs("-agentpath:$lib=start,$options,file=$outDir/async-${project.name}-%p.jfr") + } + } + } + // Disable CDS to avoid SIGSEGVs on Linux arm64. if (isLinuxArm64) { tasks.withType().configureEach {