diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index c820111..fd4a9eb 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -7,6 +7,7 @@ import de.steamwar.commands.database.DatabaseCommand import de.steamwar.commands.database.InfoCommand import de.steamwar.commands.database.ResetCommand import de.steamwar.commands.dev.DevCommand +import de.steamwar.commands.profiler.ProfilerCommand import de.steamwar.commands.user.UserCommand import de.steamwar.commands.user.UserInfoCommand import de.steamwar.commands.user.UserSearchCommand @@ -15,6 +16,7 @@ fun main(args: Array) = SteamWar() .subcommands( DatabaseCommand().subcommands(InfoCommand(), ResetCommand()), UserCommand().subcommands(UserInfoCommand(), UserSearchCommand()), - DevCommand() + DevCommand(), + ProfilerCommand() ) .main(args) \ No newline at end of file diff --git a/src/main/kotlin/commands/profiler/ProfilerCommand.kt b/src/main/kotlin/commands/profiler/ProfilerCommand.kt new file mode 100644 index 0000000..4b098dd --- /dev/null +++ b/src/main/kotlin/commands/profiler/ProfilerCommand.kt @@ -0,0 +1,38 @@ +package de.steamwar.commands.profiler + +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context +import com.github.ajalt.clikt.parameters.arguments.argument +import com.github.ajalt.clikt.parameters.arguments.help +import com.github.ajalt.clikt.parameters.arguments.optional +import com.github.ajalt.clikt.parameters.options.default +import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.types.int + +class ProfilerCommand: CliktCommand("profiler") { + val pid by argument().help("Process id").int().optional() + val port by option("--port", "-p").int().default(8543) + + override fun run() { + if (pid != null) { + ProcessBuilder() + .command("java", "-jar", "/jars/spark.java", pid.toString(), "port=$port") + .start() + .waitFor() + + ProcessBuilder() + .command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-p", port.toString(), "spark@localhost") + .inheritIO() + .start() + .waitFor() + } else { + ProcessBuilder() + .command("java", "-jar", "/jars/spark.java") + .inheritIO() + .start() + .waitFor() + } + } + + override fun help(context: Context): String = "Start a profiler" +} \ No newline at end of file