Skip to content

Commit

Permalink
IDEA-289922 git: FUS - report git stash operations duration
Browse files Browse the repository at this point in the history
GitOrigin-RevId: e3ed909dc13f0f0d0f4895fd54e0a9ff31c778b3
  • Loading branch information
AMPivovarov authored and intellij-monorepo-bot committed Mar 2, 2022
1 parent b1deb1c commit 43601aa
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/git4idea/resources/META-INF/plugin.xml
Expand Up @@ -536,6 +536,7 @@
<vcsAnnotationGutterActionProvider implementation="git4idea.actions.GitToggleAnnotationOptionsActionProvider"/>
<statistics.projectUsagesCollector implementation="git4idea.GitStatisticsCollector"/>
<statistics.counterUsagesCollector implementationClass="git4idea.GitBranchesUsageCollector"/>
<statistics.counterUsagesCollector implementationClass="git4idea.GitStashUsageCollector"/>
<statistics.notificationIdsHolder implementation="git4idea.GitNotificationIdsHolder"/>
<vcsRepositoryInitializer implementation="git4idea.repo.GitRepositoryInitializer"/>
<gitRepositoryInitializer implementation="git4idea.repo.GitRepositoryInitializerImpl"/>
Expand Down
30 changes: 30 additions & 0 deletions plugins/git4idea/src/git4idea/GitStashUsageCollector.kt
@@ -0,0 +1,30 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package git4idea

import com.intellij.internal.statistic.eventLog.EventLogGroup
import com.intellij.internal.statistic.eventLog.events.EventFields
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector

class GitStashUsageCollector : CounterUsagesCollector() {
override fun getGroup(): EventLogGroup = GROUP

companion object {
private val GROUP: EventLogGroup = EventLogGroup("stash.interactions", 1)

private val STASH_PUSH = GROUP.registerEvent("stash_push",
EventFields.DurationMs)

private val STASH_POP = GROUP.registerEvent("stash_pop",
EventFields.DurationMs)

@JvmStatic
fun logStashPush(startMs: Long) {
STASH_PUSH.log(System.currentTimeMillis() - startMs)
}

@JvmStatic
fun logStashPop(startMs: Long) {
STASH_POP.log(System.currentTimeMillis() - startMs)
}
}
}
4 changes: 4 additions & 0 deletions plugins/git4idea/src/git4idea/actions/GitStash.java
Expand Up @@ -13,6 +13,7 @@
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitStashUsageCollector;
import git4idea.GitUtil;
import git4idea.commands.Git;
import git4idea.commands.GitCommandResult;
Expand Down Expand Up @@ -57,7 +58,10 @@ public void run(@NotNull ProgressIndicator indicator) {
Collection<VirtualFile> successfulRoots = new ArrayList<>();
Map<VirtualFile, @Nls String> failedRoots = new LinkedHashMap<>();
for (VirtualFile root : roots) {
long startTime = System.currentTimeMillis();
GitCommandResult result = Git.getInstance().runCommand(createHandler.apply(root));
GitStashUsageCollector.logStashPush(startTime);

if (result.success()) {
successfulRoots.add(root);
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java
Expand Up @@ -13,6 +13,7 @@
import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.Hash;
import git4idea.GitStashUsageCollector;
import git4idea.GitUtil;
import git4idea.commands.Git;
import git4idea.commands.GitCommand;
Expand Down Expand Up @@ -62,7 +63,10 @@ protected void save(@NotNull Collection<? extends VirtualFile> rootsToSave) thro
LOG.error("Repository is null for root " + root);
}
else {
long startTime = System.currentTimeMillis();
GitCommandResult result = myGit.stashSave(repository, myStashMessage);
GitStashUsageCollector.logStashPush(startTime);

if (result.success() && somethingWasStashed(result)) {
myStashedRoots.put(root, myGit.resolveReference(repository, "stash@{0}"));
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/git4idea/src/git4idea/stash/GitStashUtils.kt
Expand Up @@ -31,6 +31,7 @@ import git4idea.GitCommit
import git4idea.GitNotificationIdsHolder
import git4idea.GitNotificationIdsHolder.Companion.STASH_LOCAL_CHANGES_DETECTED
import git4idea.GitNotificationIdsHolder.Companion.UNSTASH_FAILED
import git4idea.GitStashUsageCollector
import git4idea.GitUtil
import git4idea.changes.GitChangeUtils
import git4idea.commands.*
Expand Down Expand Up @@ -178,7 +179,9 @@ object GitStashOperations {
handler.addLineListener(untrackedFilesDetector)
handler.addLineListener(localChangesDetector)

val startTime = System.currentTimeMillis()
val result = Git.getInstance().runCommand(handler)
GitStashUsageCollector.logStashPop(startTime)

if (hash != null) refreshUnstashedChanges(project, hash, root)
GitRepositoryManager.getInstance(project).getRepositoryForFileQuick(root)?.repositoryFiles?.refreshIndexFile()
Expand Down

0 comments on commit 43601aa

Please sign in to comment.