2019-09-10 19:53:23 +03:00
|
|
|
package org.enso.build
|
|
|
|
|
2019-08-28 18:40:08 +03:00
|
|
|
import sbt._
|
|
|
|
|
2019-09-10 19:53:23 +03:00
|
|
|
/** Command allowing to run a task with additional JVM-level flags.
|
|
|
|
* Supported tasks are run and benchOnly.
|
|
|
|
* Supported flags are:
|
2019-08-28 18:40:08 +03:00
|
|
|
* * `--dumpGraphs`: dumps IGV output of the program
|
|
|
|
* * `--showCompilations`: prints Truffle compilation traces
|
|
|
|
* * `--printAssembly`: prints the disassembler output
|
2019-09-10 19:53:23 +03:00
|
|
|
* Any task arguments should be passed following `--` like so:
|
2019-08-28 18:40:08 +03:00
|
|
|
* {{{
|
2019-09-10 19:53:23 +03:00
|
|
|
* withDebug run --dumpGraphs --printAssembly -- --run myFile.enso
|
|
|
|
* withDebug benchOnly --showCompilations -- myBenchmark
|
2019-08-28 18:40:08 +03:00
|
|
|
* }}}
|
|
|
|
*/
|
2019-09-10 19:53:23 +03:00
|
|
|
object WithDebugCommand {
|
2023-05-18 16:00:52 +03:00
|
|
|
val DEBUG_OPTION =
|
|
|
|
"-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y";
|
2019-08-28 18:40:08 +03:00
|
|
|
|
|
|
|
val truffleNoBackgroundCompilationOptions = Seq(
|
2020-03-06 16:40:29 +03:00
|
|
|
"-Dpolyglot.engine.BackgroundCompilation=false"
|
2019-08-28 18:40:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
val truffleDumpGraphsOptions = Seq(
|
|
|
|
"-Dgraal.PrintGraph=Network",
|
|
|
|
"-Dgraal.Dump=Truffle:2"
|
|
|
|
)
|
|
|
|
|
|
|
|
val truffleShowCompilationsOptions = Seq(
|
2020-03-06 16:40:29 +03:00
|
|
|
"-Dpolyglot.engine.TraceCompilation=true",
|
2022-12-08 23:30:19 +03:00
|
|
|
"-Dpolyglot.engine.TraceCompilationAST=true",
|
2020-03-06 16:40:29 +03:00
|
|
|
"-Dpolyglot.engine.TraceInlining=true",
|
2020-06-29 17:11:03 +03:00
|
|
|
"-Dpolyglot.engine.TracePerformanceWarnings=all"
|
2019-08-28 18:40:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
val trufflePrintAssemblyOptions = Seq(
|
2019-11-05 19:01:50 +03:00
|
|
|
"-XX:+UnlockDiagnosticVMOptions",
|
|
|
|
"-XX:+PrintAssembly"
|
2019-08-28 18:40:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
val dumpGraphsOption = "--dumpGraphs"
|
|
|
|
|
|
|
|
val showCompilationsOptions = "--showCompilations"
|
|
|
|
|
|
|
|
val printAssemblyOption = "--printAssembly"
|
|
|
|
|
2020-08-05 23:16:44 +03:00
|
|
|
val debuggerOption = "--debugger"
|
|
|
|
|
2019-08-28 18:40:08 +03:00
|
|
|
val argSeparator = "--"
|
|
|
|
|
2019-09-10 19:53:23 +03:00
|
|
|
val commandName = "withDebug"
|
|
|
|
|
|
|
|
val benchOnlyCommandName = "benchOnly"
|
|
|
|
val runCommandName = "run"
|
2020-08-05 23:16:44 +03:00
|
|
|
val testOnlyCommandName = "testOnly"
|
2019-08-28 18:40:08 +03:00
|
|
|
|
|
|
|
/** The main logic for parsing and transforming the debug flags into JVM level flags */
|
2020-08-05 23:16:44 +03:00
|
|
|
def withDebug: Command =
|
|
|
|
Command.args(commandName, "<arguments>") { (state, args) =>
|
2019-08-28 18:40:08 +03:00
|
|
|
val (debugFlags, prefixedRunArgs) = args.span(_ != argSeparator)
|
|
|
|
val runArgs = " " + prefixedRunArgs.drop(1).mkString(" ")
|
2019-09-10 19:53:23 +03:00
|
|
|
|
|
|
|
val taskKey =
|
|
|
|
if (debugFlags.contains(benchOnlyCommandName)) BenchTasks.benchOnly
|
|
|
|
else if (debugFlags.contains(runCommandName)) Compile / Keys.run
|
2020-08-05 23:16:44 +03:00
|
|
|
else if (debugFlags.contains(testOnlyCommandName)) Test / Keys.testOnly
|
2019-09-10 19:53:23 +03:00
|
|
|
else throw new IllegalArgumentException("Invalid command name.")
|
|
|
|
|
2019-08-28 18:40:08 +03:00
|
|
|
val dumpGraphsOpts =
|
|
|
|
if (debugFlags.contains(dumpGraphsOption)) truffleDumpGraphsOptions
|
|
|
|
else Seq()
|
|
|
|
val showCompilationsOpts =
|
|
|
|
if (debugFlags.contains(showCompilationsOptions))
|
|
|
|
truffleShowCompilationsOptions
|
|
|
|
else Seq()
|
|
|
|
val printAssemblyOpts =
|
|
|
|
if (debugFlags.contains(printAssemblyOption))
|
|
|
|
trufflePrintAssemblyOptions
|
|
|
|
else Seq()
|
2020-08-05 23:16:44 +03:00
|
|
|
val debuggerOpts =
|
|
|
|
if (debugFlags.contains(debuggerOption))
|
2023-05-18 16:00:52 +03:00
|
|
|
Seq(DEBUG_OPTION)
|
2020-08-05 23:16:44 +03:00
|
|
|
else Seq()
|
2019-08-28 18:40:08 +03:00
|
|
|
val javaOpts: Seq[String] = Seq(
|
|
|
|
truffleNoBackgroundCompilationOptions,
|
|
|
|
dumpGraphsOpts,
|
|
|
|
showCompilationsOpts,
|
2020-08-05 23:16:44 +03:00
|
|
|
printAssemblyOpts,
|
|
|
|
debuggerOpts
|
2019-08-28 18:40:08 +03:00
|
|
|
).flatten
|
|
|
|
|
|
|
|
val extracted = Project.extract(state)
|
|
|
|
val withJavaOpts = extracted.appendWithoutSession(
|
2019-09-10 19:53:23 +03:00
|
|
|
Seq(Compile / Keys.javaOptions ++= javaOpts),
|
2019-08-28 18:40:08 +03:00
|
|
|
state
|
|
|
|
)
|
|
|
|
Project
|
|
|
|
.extract(withJavaOpts)
|
2019-09-10 19:53:23 +03:00
|
|
|
.runInputTask(taskKey, runArgs, withJavaOpts)
|
2019-08-28 18:40:08 +03:00
|
|
|
state
|
2020-08-05 23:16:44 +03:00
|
|
|
}
|
2019-08-28 18:40:08 +03:00
|
|
|
}
|