Last active
December 25, 2024 04:49
-
-
Save dkandalov/232dcfe2b328d6ea46c4b1ac48810a6e to your computer and use it in GitHub Desktop.
Mini-plugin to measure the duration of tests in IntelliJ IDEs (because test runners don't show the actual time)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.execution.ExecutionListener | |
import com.intellij.execution.ExecutionManager.Companion.EXECUTION_TOPIC | |
import com.intellij.execution.process.ProcessHandler | |
import com.intellij.execution.runners.ExecutionEnvironment | |
import java.util.concurrent.ConcurrentHashMap | |
val startTimeByRunProfile = ConcurrentHashMap<String, Long>() | |
project!!.messageBus.connect(pluginDisposable) | |
.subscribe(EXECUTION_TOPIC, object : ExecutionListener { | |
override fun processStarting(executorId: String, env: ExecutionEnvironment) { | |
startTimeByRunProfile[env.runProfile.name] = System.currentTimeMillis() | |
liveplugin.show("${env.runProfile.name} started") | |
} | |
override fun processTerminated(executorId: String, env: ExecutionEnvironment, handler: ProcessHandler, exitCode: Int) { | |
val startTime = startTimeByRunProfile.remove(env.runProfile.name) ?: return | |
val duration = System.currentTimeMillis() - startTime | |
liveplugin.show("${env.runProfile.name} finished in $duration ms") | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment