From 3f9d838a5e70bcebc0f75ccf1deabf6bcac20a9a Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Sun, 31 Dec 2023 16:59:17 -0800 Subject: [PATCH] Pass & Filter pattern Filter pattern in GlobalBenchmarkSetup Test that -Dbenchmark.pattern works in CI Pass pattern to GlobalBenchmarkSetup Run benchmarks in parallel Renaming job names --- .github/workflows/ci.yml | 14 +++++++++++--- build.sbt | 5 +++-- .../scala/xsbt/GlobalBenchmarkSetup.scala | 19 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4b04acca8..1b18c1855f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: - os: ubuntu-latest java: 21 jobtype: 4 + - os: ubuntu-latest + java: 21 + jobtype: 5 runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -50,9 +53,14 @@ jobs: if: ${{ matrix.jobtype == 3 }} shell: bash run: | - sbt -v -Dfile.encoding=UTF-8 "runBenchmarks" - - name: Build and test (4) + sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck + - name: Benchmark (Scalac) (4) if: ${{ matrix.jobtype == 4 }} shell: bash run: | - sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck + sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "runBenchmarks" + - name: Benchmark (Shapeless) (5) + if: ${{ matrix.jobtype == 5 }} + shell: bash + run: | + sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks" diff --git a/build.sbt b/build.sbt index 9ed5b59df8..3ef7e3925e 100644 --- a/build.sbt +++ b/build.sbt @@ -697,11 +697,12 @@ crossTestBridges := (compilerBridgeTest.jvm(scala213) / Test / test).dependsOn(p addCommandAlias( "runBenchmarks", { val dir = IO.createTemporaryDirectory.getAbsolutePath + val pattern = sys.props.getOrElse("benchmark.pattern", "") Seq( s"${compilerBridge213.id}/packageBin", s"${compilerBridge212.id}/packageBin", - s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir", - s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true", + s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir $pattern", + s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true $pattern", s"""eval IO.delete(file("$dir"))""", ).mkString(";", ";", "") } diff --git a/internal/zinc-benchmarks/src/test/scala/xsbt/GlobalBenchmarkSetup.scala b/internal/zinc-benchmarks/src/test/scala/xsbt/GlobalBenchmarkSetup.scala index adebb4a9ec..59eecf109b 100644 --- a/internal/zinc-benchmarks/src/test/scala/xsbt/GlobalBenchmarkSetup.scala +++ b/internal/zinc-benchmarks/src/test/scala/xsbt/GlobalBenchmarkSetup.scala @@ -18,13 +18,15 @@ import xsbt.BenchmarkProjects.{ Scalac, Shapeless } object GlobalBenchmarkSetup { /** Update this list every time you add a new benchmark. */ - val projects = List(Scalac, Shapeless) + val projects = Map("Scalac" -> Scalac, "Shapeless" -> Shapeless) - def runSetup(setupDir: File): (Int, String) = { - val projectsPreparation = projects.map { project => - val benchmark = new ZincBenchmark(project) - project -> benchmark.writeSetup(new File(setupDir, project.repo)) - } + def runSetup(setupDir: File, pattern: String): (Int, String) = { + val projectsPreparation = projects + .filterKeys { _.matches(pattern) } + .map { case (_, project) => + val benchmark = new ZincBenchmark(project) + project -> benchmark.writeSetup(new File(setupDir, project.repo)) + } val failedToPrepare = projectsPreparation.filter(_._2.isLeft) if (failedToPrepare.isEmpty) @@ -43,11 +45,12 @@ object GlobalBenchmarkSetup { if (args.isEmpty) fail("Missing directory to host project setups.") - else if (args.length > 1) + else if (args.length > 2) fail("Too many arguments. Pass the directory to host project setups.") else { val setupDir = new File(args(0)) - val (exitCode, status) = runSetup(setupDir) + val pattern = if (args.length == 1) ".*" else args(1) + val (exitCode, status) = runSetup(setupDir, pattern) println(status) println("The benchmark setup has finished.") System.exit(exitCode)