Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active December 25, 2024 04:49
Show Gist options
  • Save dkandalov/232dcfe2b328d6ea46c4b1ac48810a6e to your computer and use it in GitHub Desktop.
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)
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