From dfaa6e1e696bb25f0bcfe53cf7f549d90468c4b2 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Thu, 22 Oct 2026 16:51:43 +0200 Subject: [PATCH 1/2] fix: document Gradle fork build and warn when native library is missing under CodSpeed The README said to build the fork with Maven, which does not bundle the native libraries. The fork then silently ran as plain JMH and produced no results. Document the Gradle build with recursive submodule init, and print a warning when CODSPEED_ENV is set but the native library cannot load. --- AGENTS.md | 8 +++++--- README.md | 8 ++++---- .../instrument_hooks/InstrumentHooks.java | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 59a49fa..539f2ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,8 +30,10 @@ # Build JAR artifact only (useful for local profiling) ./gradlew :examples:example-gradle:jmhJar -# Build and install JMH fork to local Maven repo (required before Maven example) -cd jmh-fork && mvn clean install -DskipTests -q +# Build and install JMH fork to local Maven repo (required before Maven example). +# Must use Gradle: only the Gradle build compiles and bundles the native libraries. +git submodule update --init --recursive +./gradlew -p jmh-fork publishToMavenLocal # Build Maven example (after installing JMH fork) cd examples/example-maven && mvn package -q @@ -113,7 +115,7 @@ The repository combines Maven and Gradle via Gradle's composite build feature: 1. Make changes in `jmh-fork/` 2. Bump version: `cd jmh-fork && mvn versions:set -DnewVersion=X.Y.Z` -3. Publish locally: `cd jmh-fork && mvn clean install -DskipTests -q` +3. Publish locally: `./gradlew -p jmh-fork publishToMavenLocal` 4. Update version reference in root `build.gradle.kts` if needed 5. Test both Gradle and Maven examples to verify compatibility diff --git a/README.md b/README.md index db011fb..2188c8a 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,14 @@ For information on how to integrate it, see the [CodSpeed documentation](https:/ ### Prerequisites - JDK 21+ -- Maven (for building the JMH fork) -- Gradle +- A C toolchain (Linux only, to build the native libraries) ### Setup -1. Build and install the JMH fork to your local Maven repository: +1. Build and install the JMH fork to your local Maven repository. Use Gradle: only the Gradle build compiles and bundles the native libraries needed for CodSpeed measurements. ```bash -cd jmh-fork && mvn clean install -DskipTests -q +git submodule update --init --recursive +./gradlew -p jmh-fork publishToMavenLocal ``` 2. Run the example benchmarks: diff --git a/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java b/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java index 50ef867..c6f42f0 100644 --- a/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java +++ b/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java @@ -9,6 +9,9 @@ public class InstrumentHooks { + /** Set by the CodSpeed runner for every benchmark process. */ + private static final String CODSPEED_ENV_VAR = "CODSPEED_ENV"; + private static final boolean nativeAvailable; static { @@ -17,8 +20,16 @@ public class InstrumentHooks { loadNativeLibrary("/libinstrument_hooks_jni.so"); loaded = true; } catch (IOException | UnsatisfiedLinkError e) { - // Native library not available (e.g. non-Linux platform). - // All methods will gracefully no-op. + // Outside the CodSpeed runner (e.g. local runs, non-Linux), fall back to plain JMH quietly. + // Under the runner, a missing library means no results will be produced, so say why. + if (System.getenv(CODSPEED_ENV_VAR) != null) { + System.err.println( + "[CodSpeed] WARNING: could not load the native instrument-hooks library (" + + e.getMessage() + + "). Running as plain JMH: no CodSpeed results will be produced. Make sure the" + + " JMH fork was built with Gradle (./gradlew -p jmh-fork publishToMavenLocal)," + + " which bundles the native libraries."); + } } nativeAvailable = loaded; } From 29d18a78f24be89a307e8bf2c2a96bc35277ee56 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Thu, 22 Oct 2026 17:03:25 +0200 Subject: [PATCH 2/2] fix: shorten missing native library warning --- .../io/codspeed/instrument_hooks/InstrumentHooks.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java b/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java index c6f42f0..b09e000 100644 --- a/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java +++ b/jmh-fork/jmh-core/src/main/java/io/codspeed/instrument_hooks/InstrumentHooks.java @@ -9,7 +9,6 @@ public class InstrumentHooks { - /** Set by the CodSpeed runner for every benchmark process. */ private static final String CODSPEED_ENV_VAR = "CODSPEED_ENV"; private static final boolean nativeAvailable; @@ -20,15 +19,11 @@ public class InstrumentHooks { loadNativeLibrary("/libinstrument_hooks_jni.so"); loaded = true; } catch (IOException | UnsatisfiedLinkError e) { - // Outside the CodSpeed runner (e.g. local runs, non-Linux), fall back to plain JMH quietly. - // Under the runner, a missing library means no results will be produced, so say why. + // Expected on non-Linux hosts, so only warn when running under the CodSpeed runner. if (System.getenv(CODSPEED_ENV_VAR) != null) { System.err.println( - "[CodSpeed] WARNING: could not load the native instrument-hooks library (" - + e.getMessage() - + "). Running as plain JMH: no CodSpeed results will be produced. Make sure the" - + " JMH fork was built with Gradle (./gradlew -p jmh-fork publishToMavenLocal)," - + " which bundles the native libraries."); + "[CodSpeed] Failed to load instrument-hooks, running without CodSpeed: " + + e.getMessage()); } } nativeAvailable = loaded;