Skip to content
Open
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ jobs:
mode: walltime
run: ./gradlew :examples:example-gradle:jmh

walltime-benchmarks-flamegraph:
runs-on: codspeed-macro
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: 'gradle'
- name: Run FibFlamegraphBenchmark
uses: CodSpeedHQ/action@main
env:
CODSPEED_BENCH_GROUP: flamegraph
with:
mode: walltime
run: ./gradlew :examples:example-gradle:jmh

check:
runs-on: ubuntu-latest
if: always()
Expand All @@ -111,6 +130,7 @@ jobs:
- build-and-run-gradle
- build-and-run-maven
- walltime-benchmarks
- walltime-benchmarks-flamegraph
steps:
- uses: re-actors/alls-green@release/v1
with:
Expand Down
14 changes: 11 additions & 3 deletions examples/example-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ jmh {
// me.champeau.jmh joins `includes` with commas into a single positional
// regex passed to JMH, so multiple entries collapse to one pattern with
// literal commas and match nothing. Use a single alternation instead.
includes.set(listOf(
".*(SleepBenchmark|BacktrackingBenchmark|FibBenchmark).*",
))
//
// CODSPEED_BENCH_GROUP=flamegraph selects the macOS-only
// FibFlamegraphBenchmark used to exercise the flamegraph pipeline.
// Default is the regular benchmark set.
// TODO(COD-2715): Run all benches on MacOS
val pattern = if (System.getenv("CODSPEED_BENCH_GROUP") == "flamegraph") {
".*FibFlamegraphBenchmark.*"
} else {
".*(SleepBenchmark|BacktrackingBenchmark|FibBenchmark).*"
}
includes.set(listOf(pattern))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bench;

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*;

/**
* macOS-only benchmark whose recursion shape produces an easily-recognisable flamegraph. Gated to
* macOS via Gradle excludes in {@code build.gradle.kts}.
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class FibFlamegraphBenchmark {

@Param({"30"})
private int n;

@Benchmark
public long fib() {
return fib(n);
}

private static long fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
}
Loading