Indexing diagnostics: count time in the indexing suspended state.
authorSergey Patrikeev <Sergey.Patrikeev@jetbrains.com>
Wed, 12 Aug 2020 11:16:34 +0000 (14:16 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 13 Aug 2020 08:08:59 +0000 (08:08 +0000)
GitOrigin-RevId: 7b5a1661ad884732c64e7cb0ccf07fbc68dcd2f6

platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java
platform/lang-impl/src/com/intellij/util/indexing/diagnostic/ProjectIndexingHistory.kt
platform/lang-impl/src/com/intellij/util/indexing/diagnostic/dto/JsonConverter.kt
platform/lang-impl/src/com/intellij/util/indexing/diagnostic/dto/JsonProjectIndexingHistoryTimes.kt

index 3d22bda535f63fb8f2e1f7d8c659ecc402ed1efd..38f19c85b64f84fa413f0852e1c34cf339bd05bd 100644 (file)
@@ -41,6 +41,7 @@ import com.intellij.util.progress.ConcurrentTasksProgressManager;
 import com.intellij.util.progress.SubTaskProgressIndicator;
 import org.jetbrains.annotations.NotNull;
 
+import java.time.Duration;
 import java.time.Instant;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
@@ -84,8 +85,12 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
   private void updateUnindexedFiles(@NotNull ProjectIndexingHistory projectIndexingHistory, @NotNull ProgressIndicator indicator) {
     if (!IndexInfrastructure.hasIndices()) return;
 
+    ProgressSuspender suspender = ProgressSuspender.getSuspender(indicator);
+    if (suspender != null) {
+      listenToProgressSuspenderForSuspendedTimeDiagnostic(suspender, projectIndexingHistory);
+    }
+
     if (myStartSuspended) {
-      ProgressSuspender suspender = ProgressSuspender.getSuspender(indicator);
       if (suspender == null) {
         throw new IllegalStateException("Indexing progress indicator must be suspendable!");
       }
@@ -192,6 +197,34 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
     myIndex.dumpIndexStatistics();
   }
 
+  private void listenToProgressSuspenderForSuspendedTimeDiagnostic(@NotNull ProgressSuspender suspender,
+                                                                   @NotNull ProjectIndexingHistory projectIndexingHistory) {
+    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(this);
+    connection.subscribe(ProgressSuspender.TOPIC, new ProgressSuspender.SuspenderListener() {
+
+      private volatile Instant suspensionStart = null;
+
+      @Override
+      public void suspendedStatusChanged(@NotNull ProgressSuspender changedSuspender) {
+        if (suspender == changedSuspender) {
+          if (suspender.isSuspended()) {
+            suspensionStart = Instant.now();
+          } else {
+            Instant now = Instant.now();
+            Instant start = suspensionStart;
+            suspensionStart = null;
+            if (start != null && start.compareTo(now) < 0) {
+              Duration thisDuration = Duration.between(start, now);
+              Duration currentTotalDuration = projectIndexingHistory.getTimes().getSuspendedDuration();
+              Duration newTotalSuspendedDuration = currentTotalDuration != null ? currentTotalDuration.plus(thisDuration) : thisDuration;
+              projectIndexingHistory.getTimes().setSuspendedDuration(newTotalSuspendedDuration);
+            }
+          }
+        }
+      }
+    });
+  }
+
   static boolean isProjectContentFullyScanned(@NotNull Project project) {
     return Boolean.TRUE.equals(project.getUserData(CONTENT_SCANNED));
   }
index de03d6c28cb5a94b4b9ec0edbfe98484f909f76d..9421ad2fd8bfed810491a85ea982a2754bce8d86 100644 (file)
@@ -3,6 +3,7 @@ package com.intellij.util.indexing.diagnostic
 
 import com.intellij.util.indexing.diagnostic.dto.JsonFileProviderIndexStatistics
 import com.intellij.util.indexing.diagnostic.dto.createProviderJsonStatistics
+import java.time.Duration
 import java.time.Instant
 
 typealias TimeMillis = Long
@@ -93,6 +94,7 @@ data class ProjectIndexingHistory(val projectName: String) {
     var indexExtensionsEnd: Instant? = null,
     var scanFilesStart: Instant? = null,
     var scanFilesEnd: Instant? = null,
+    var suspendedDuration: Duration? = null,
     var wasInterrupted: Boolean = false
   )
 }
\ No newline at end of file
index 70433dfd051c888c35daba5505982bf5a6211eb0..70808ffd69907f4358b2bbb634357c50d1a30b39 100644 (file)
@@ -80,6 +80,7 @@ fun ProjectIndexingHistory.IndexingTimes.toJson() =
     nullableJsonDuration(indexExtensionsStart, indexExtensionsEnd),
     JsonDateTime(indexingStart!!),
     JsonDateTime(indexingEnd!!),
+    suspendedDuration?.let { JsonDuration(it.toNanos()) },
     wasInterrupted
   )
 
index e2bfb42370d33ed60e0cd2e4e406bb65d540c9f6..33944627f7ab50849c29336ca3df53b26c09ea00 100644 (file)
@@ -13,5 +13,6 @@ data class JsonProjectIndexingHistoryTimes(
 
   val indexingStart: JsonDateTime,
   val indexingEnd: JsonDateTime,
+  val totalSuspendedTime: JsonDuration?,
   val wasInterrupted: Boolean
 )
\ No newline at end of file