diff --git a/plugins/git4idea/src/git4idea/performanceTesting/GitCommandProvider.java b/plugins/git4idea/src/git4idea/performanceTesting/GitCommandProvider.java index 32b326164eee..8643e662dd8d 100644 --- a/plugins/git4idea/src/git4idea/performanceTesting/GitCommandProvider.java +++ b/plugins/git4idea/src/git4idea/performanceTesting/GitCommandProvider.java @@ -19,7 +19,8 @@ public final class GitCommandProvider implements CommandProvider { Map.entry(ShowFileAnnotationCommand.PREFIX, ShowFileAnnotationCommand::new), Map.entry(CheckGitLogIndexedCommand.PREFIX, CheckGitLogIndexedCommand::new), Map.entry(WaitVcsLogIndexingCommand.PREFIX, WaitVcsLogIndexingCommand::new), - Map.entry(WaitForVcsLogUpdateCommand.PREFIX, WaitForVcsLogUpdateCommand::new) + Map.entry(WaitForVcsLogUpdateCommand.PREFIX, WaitForVcsLogUpdateCommand::new), + Map.entry(GitRollbackCommand.PREFIX, GitRollbackCommand::new) ); } } diff --git a/plugins/git4idea/src/git4idea/performanceTesting/GitRollbackCommand.kt b/plugins/git4idea/src/git4idea/performanceTesting/GitRollbackCommand.kt new file mode 100644 index 000000000000..c1fe5df3dbfd --- /dev/null +++ b/plugins/git4idea/src/git4idea/performanceTesting/GitRollbackCommand.kt @@ -0,0 +1,46 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package git4idea.performanceTesting + +import com.intellij.openapi.application.EDT +import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.ui.playback.PlaybackContext +import com.intellij.openapi.util.ActionCallback +import com.intellij.openapi.vcs.changes.ChangeListManager +import com.intellij.openapi.vcs.changes.ui.RollbackWorker +import com.intellij.vcsUtil.RollbackUtil +import com.jetbrains.performancePlugin.commands.OpenFileCommand +import com.jetbrains.performancePlugin.commands.PerformanceCommandCoroutineAdapter +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.jetbrains.concurrency.await +import org.jetbrains.concurrency.toPromise + +class GitRollbackCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) { + companion object { + const val NAME = "gitRollback" + const val PREFIX = "$CMD_PREFIX$NAME" + } + + override suspend fun doExecute(context: PlaybackContext) { + val project = context.project + val filePath = extractCommandArgument(PREFIX) + withContext(Dispatchers.EDT) { + val file = OpenFileCommand.findFile(filePath, project) ?: throw IllegalArgumentException("There is no file ${filePath}") + val changes = ChangeListManager.getInstance(project).defaultChangeList.changes + val fileChanges = changes.filter { it.virtualFile == file } + FileDocumentManager.getInstance().saveAllDocuments() + val operationName = RollbackUtil.getRollbackOperationName(project) + val actionCallback = ActionCallback() + RollbackWorker(project, operationName, false) + .doRollback(fileChanges, false, Runnable { + actionCallback.setDone() + }, null) + + actionCallback.toPromise().await() + } + } + + override fun getName(): String { + return NAME + } +} \ No newline at end of file diff --git a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt index e031252943af..097e41426a5e 100644 --- a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt +++ b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt @@ -1071,6 +1071,10 @@ fun T.gitCommitFile(pathToFile: String, commitMessage: String addCommand("${CMD_PREFIX}gitCommit ${pathToFile},${commitMessage}") } +fun T.gitRollbackFile(pathToFile: String): T = apply { + addCommand("${CMD_PREFIX}gitRollback ${pathToFile}") +} + fun T.replaceText(startOffset: Int? = null, endOffset: Int? = null, newText: String? = null): T = apply { val options = StringBuilder() if (startOffset != null) { @@ -1162,4 +1166,12 @@ fun T.waitForProjectView(): T = apply { */ fun T.expandProjectView(relativePath: String): T = apply { addCommand("${CMD_PREFIX}expandProjectView $relativePath") +} + +/** + * The first call will create and start span. + * The second call with the same spanName will stop span. + * */ +fun T.handleSpan(spanName: String): T = apply { + addCommand("${CMD_PREFIX}handleSpan $spanName") } \ No newline at end of file diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index 080f260ccebc..285cc33465fe 100644 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -120,7 +120,8 @@ public final class BaseCommandProvider implements CommandProvider { Map.entry(WaitForProjectViewCommand.PREFIX, WaitForProjectViewCommand::new), Map.entry(ExpandProjectViewCommand.PREFIX, ExpandProjectViewCommand::new), Map.entry(DebugToggleBreakpointCommand.PREFIX, DebugToggleBreakpointCommand::new), - Map.entry(MoveFilesCommand.PREFIX, MoveFilesCommand::new) + Map.entry(MoveFilesCommand.PREFIX, MoveFilesCommand::new), + Map.entry(HandleSpanCommand.PREFIX, HandleSpanCommand::new) ); } } diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/HandleSpanCommand.kt b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/HandleSpanCommand.kt new file mode 100644 index 000000000000..1ba1cfe462f0 --- /dev/null +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/HandleSpanCommand.kt @@ -0,0 +1,37 @@ +package com.jetbrains.performancePlugin.commands + +import com.intellij.openapi.ui.playback.PlaybackContext +import com.intellij.platform.diagnostic.telemetry.Scope +import com.intellij.platform.diagnostic.telemetry.TelemetryManager +import io.opentelemetry.api.trace.Span + +/** + * The first call will create and start span. + * The second call with the same spanName will stop span. + * */ +class HandleSpanCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) { + companion object { + const val NAME = "handleSpan" + const val PREFIX = "$CMD_PREFIX$NAME" + + private val CREATED_SPANS: MutableMap = mutableMapOf() + } + + override suspend fun doExecute(context: PlaybackContext) { + val spanName = extractCommandArgument(PREFIX) + val span = CREATED_SPANS[spanName] + if (span != null) { + span.end() + CREATED_SPANS.remove(spanName) + } else { + val newSpan = TelemetryManager.getTracer(Scope("HandleSpanCommand")) + .spanBuilder(spanName) + .startSpan() + CREATED_SPANS[spanName] = newSpan + } + } + + override fun getName(): String { + return NAME + } +} \ No newline at end of file