mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin-plugin] measure time in OpenFileCommand like first highlighting
GitOrigin-RevId: d575250647f3c3a95546f6bbf4f3a3fde235b86c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1b2c9aa5ab
commit
77da7682df
+11
-5
@@ -7,11 +7,14 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.guessProjectDir
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext
|
||||
import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.jetbrains.performancePlugin.PerformanceTestSpan
|
||||
import com.jetbrains.performancePlugin.PerformanceTestingBundle
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.annotations.NonNls
|
||||
@@ -20,6 +23,7 @@ import java.util.concurrent.CompletableFuture
|
||||
internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) {
|
||||
companion object {
|
||||
const val PREFIX: @NonNls String = CMD_PREFIX + "openFile"
|
||||
const val SPAN_NAME: @NonNls String = "firstHighlight"
|
||||
|
||||
@JvmStatic
|
||||
fun findFile(filePath: String, project: Project): VirtualFile? {
|
||||
@@ -35,12 +39,10 @@ internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCorouti
|
||||
val filePath = text.split(' ', limit = 2)[1]
|
||||
val project = context.project
|
||||
val file = findFile(filePath, project) ?: error(PerformanceTestingBundle.message("command.file.not.found", filePath))
|
||||
withContext(Dispatchers.EDT) {
|
||||
FileEditorManager.getInstance(project).openFile(file, true)
|
||||
}
|
||||
|
||||
val job = CompletableFuture<Unit>()
|
||||
val connection = project.messageBus.simpleConnect()
|
||||
val span = PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME).setParent(PerformanceTestSpan.getContext())
|
||||
val spanRef = Ref<Span>()
|
||||
connection.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, object : DaemonCodeAnalyzer.DaemonListener {
|
||||
override fun daemonFinished() {
|
||||
try {
|
||||
@@ -48,11 +50,15 @@ internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCorouti
|
||||
context.message(PerformanceTestingBundle.message("command.file.opened", file.name), line)
|
||||
}
|
||||
finally {
|
||||
spanRef.get()?.end()
|
||||
job.complete(Unit)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
withContext(Dispatchers.EDT) {
|
||||
spanRef.set(span.startSpan())
|
||||
FileEditorManager.getInstance(project).openFile(file, true)
|
||||
}
|
||||
job.join()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user