build.gradle.kts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
  2. import me.champeau.jmh.JMHTask
  3. import net.ltgt.gradle.errorprone.errorprone
  4. plugins {
  5. id("otel.java-conventions")
  6. id("otel.jmh-conventions")
  7. }
  8. dependencies {
  9. jmhImplementation("org.springframework.boot:spring-boot-starter-web:3.3.0")
  10. }
  11. tasks {
  12. // TODO(trask) without disabling errorprone, jmh task fails with
  13. // Task :testing-overhead-jmh:jmhCompileGeneratedClasses FAILED
  14. // error: plug-in not found: ErrorProne
  15. withType<JavaCompile>().configureEach {
  16. options.errorprone {
  17. isEnabled.set(false)
  18. }
  19. }
  20. // TODO(trask) move to otel.jmh-conventions?
  21. val jmhFork = gradle.startParameter.projectProperties["jmh.fork"]?.toInt()
  22. val jmhWarmupIterations = gradle.startParameter.projectProperties["jmh.warmupIterations"]?.toInt()
  23. val jmhIterations = gradle.startParameter.projectProperties["jmh.iterations"]?.toInt()
  24. val jmhIncludes = gradle.startParameter.projectProperties["jmh.includes"]
  25. // note: if you want to capture a flight recording for a single benchmark, try
  26. // -Pjmh.fork=1
  27. // -Pjmh.warmupIterations=5
  28. // -Pjmh.iterations=5
  29. // -Pjmh.includes=<benchmark>
  30. // -Pjmh.startFlightRecording=settings=profile.jfc,delay=50s,duration=50s,filename=output.jfr
  31. // since each iteration is 10 seconds, the flight recording produced will approximately cover the
  32. // (post-warmup) benchmarking iterations
  33. val jmhStartFlightRecording = gradle.startParameter.projectProperties.get("jmh.startFlightRecording")
  34. named<JMHTask>("jmh") {
  35. val shadowTask = project(":javaagent").tasks.named<ShadowJar>("shadowJar").get()
  36. inputs.files(layout.files(shadowTask))
  37. // note: without an exporter, toSpanData() won't even be called
  38. // (which is good for benchmarking the instrumentation itself)
  39. val args = mutableListOf(
  40. "-javaagent:${shadowTask.archiveFile.get()}",
  41. "-Dotel.traces.exporter=none",
  42. "-Dotel.metrics.exporter=none",
  43. // avoid instrumenting HttpURLConnection for now since it is used to make the requests
  44. // and this benchmark is focused on servlet overhead for now
  45. "-Dotel.instrumentation.http-url-connection.enabled=false",
  46. )
  47. if (jmhStartFlightRecording != null) {
  48. args.addAll(
  49. listOf(
  50. "-XX:+FlightRecorder",
  51. "-XX:StartFlightRecording=$jmhStartFlightRecording",
  52. // enabling profiling at non-safepoints helps with micro-profiling
  53. "-XX:+UnlockDiagnosticVMOptions",
  54. "-XX:+DebugNonSafepoints",
  55. ),
  56. )
  57. }
  58. // see https://github.com/melix/jmh-gradle-plugin/issues/200
  59. jvmArgsPrepend.add(args.joinToString(" "))
  60. if (jmhFork != null) {
  61. fork.set(jmhFork)
  62. }
  63. if (jmhWarmupIterations != null) {
  64. warmupIterations.set(jmhWarmupIterations)
  65. }
  66. if (jmhIterations != null) {
  67. iterations.set(jmhIterations)
  68. }
  69. if (jmhIncludes != null) {
  70. includes.addAll(jmhIncludes.split(','))
  71. }
  72. // TODO(trask) is this ok? if it's ok, move to otel.jmh-conventions?
  73. outputs.upToDateWhen { false }
  74. }
  75. }