|
| 1 | +import sbt.complete.DefaultParsers.OptSpace |
| 2 | +import sbt.complete.Parser |
| 3 | + |
1 | 4 | name := "compiler-benchmark"
|
2 | 5 |
|
3 | 6 | version := "1.0-SNAPSHOT"
|
@@ -93,6 +96,41 @@ addCommandAlias("hot", "compilation/jmh:run HotScalacBenchmark -foe true")
|
93 | 96 |
|
94 | 97 | addCommandAlias("cold", "compilation/jmh:run ColdScalacBenchmark -foe true")
|
95 | 98 |
|
| 99 | + |
| 100 | +def profParser(s: State): Parser[String] = { |
| 101 | + import Parser._ |
| 102 | + token("prof" ~> OptSpace) flatMap { _ => matched(s.combinedParser)} map (_.trim) |
| 103 | +} |
| 104 | + |
| 105 | +commands += Command.custom((s: State) => Command.applyEffect(profParser(s))((line: String) => { |
| 106 | + val flameGraphOpts = s"--minwidth,1,--colors,java,--cp,--width,1800" |
| 107 | + abstract class Profiler(val name: String) { |
| 108 | + def command(outDir: File): String |
| 109 | + } |
| 110 | + |
| 111 | + object basic extends Profiler("basic") { |
| 112 | + def command(outDir: File): String = "-jvmArgs -Xprof -prof hs_comp -prof hs_gc -prof stack -prof hs_rt" |
| 113 | + } |
| 114 | + object jfr extends Profiler("jfr") { |
| 115 | + def command(outDir: File): String = s"-prof jmh.extras.JFR:dir=${outDir.getAbsolutePath};flameGraphOpts=$flameGraphOpts;verbose=true'" |
| 116 | + } |
| 117 | + object async extends Profiler("async") { |
| 118 | + def command(outDir: File): String = s"-prof jmh.extras.Async:dir=${outDir.getAbsolutePath};flameGraphOpts=$flameGraphOpts;verbose=true;event=cpu" // + ";simpleName=true" TODO add this after upgrading next sbt-jmh release |
| 119 | + } |
| 120 | + object perfNorm extends Profiler("perfNorm") { |
| 121 | + def command(outDir: File): String = "-prof perfnorm" |
| 122 | + } |
| 123 | + |
| 124 | + val profs = List(perfNorm, basic, async, jfr) |
| 125 | + val commands: List[String] = profs.flatMap { (prof: Profiler) => |
| 126 | + val outDir = file(s"target/profile-${prof.name}") |
| 127 | + IO.createDirectory(outDir) |
| 128 | + List(line + " -jvmArgs -Dsun.reflect.inflationThreshold=0 " + prof.command(outDir) + s" -o ${(outDir / "jmh.log").getAbsolutePath} -rf json -rff ${(outDir / "result.json").getAbsolutePath}", BasicCommandStrings.FailureWall) |
| 129 | + } |
| 130 | + s.copy(remainingCommands = BasicCommandStrings.ClearOnFailure :: commands ++ s.remainingCommands) |
| 131 | +})) |
| 132 | + |
| 133 | + |
96 | 134 | def addJmh(project: Project): Project = {
|
97 | 135 | // IntelliJ SBT project import doesn't like sbt-jmh's default setup, which results the prod and test
|
98 | 136 | // output paths overlapping. This is because sbt-jmh declares the `jmh` config as extending `test`, but
|
|
0 commit comments