Index diagnostic: simplify and prettify times.

GitOrigin-RevId: 4eab9aadc3336e58db83718f02b9b4040897baca
This commit is contained in:
Sergey Patrikeev
2020-05-28 14:21:02 +03:00
committed by intellij-monorepo-bot
parent 090af53064
commit 2e93b3abb0
5 changed files with 44 additions and 49 deletions
@@ -38,6 +38,7 @@ import com.intellij.util.progress.ConcurrentTasksProgressManager;
import com.intellij.util.progress.SubTaskProgressIndicator;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -75,7 +76,7 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
private void updateUnindexedFiles(ProgressIndicator indicator) {
if (!IndexInfrastructure.hasIndices()) return;
ProjectIndexingHistory projectIndexingHistory = new ProjectIndexingHistory(myProject.getName());
projectIndexingHistory.getTimes().setStartIndexing(nowMillis());
projectIndexingHistory.getTimes().setIndexingStart(Instant.now());
if (myStartSuspended) {
ProgressSuspender suspender = ProgressSuspender.getSuspender(indicator);
@@ -90,13 +91,13 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
indicator.setIndeterminate(true);
indicator.setText(IndexingBundle.message("progress.indexing.scanning"));
projectIndexingHistory.getTimes().setStartPushProperties(nowMillis());
projectIndexingHistory.getTimes().setPushPropertiesStart(Instant.now());
PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
myPusher.pushAllPropertiesNow();
boolean trackResponsiveness = !ApplicationManager.getApplication().isUnitTestMode();
projectIndexingHistory.getTimes().setEndPushProperties(nowMillis());
projectIndexingHistory.getTimes().setPushPropertiesEnd(Instant.now());
if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Pushing properties");
@@ -104,19 +105,19 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
snapshot = PerformanceWatcher.takeSnapshot();
projectIndexingHistory.getTimes().setStartIndexExtensions(nowMillis());
projectIndexingHistory.getTimes().setIndexExtensionsStart(Instant.now());
FileBasedIndexInfrastructureExtension.EP_NAME.extensions().forEach(ex -> ex.processIndexingProject(myProject, indicator));
projectIndexingHistory.getTimes().setEndIndexExtensions(nowMillis());
projectIndexingHistory.getTimes().setIndexExtensionsEnd(Instant.now());
projectIndexingHistory.getTimes().setStartScanFiles(nowMillis());
projectIndexingHistory.getTimes().setScanFilesStart(Instant.now());
List<IndexableFilesProvider> orderedProviders = myIndex.getOrderedIndexableFilesProviders(myProject);
Map<IndexableFilesProvider, List<VirtualFile>> providerToFiles = collectIndexableFilesConcurrently(myProject, indicator, orderedProviders);
projectIndexingHistory.getTimes().setEndScanFiles(nowMillis());
projectIndexingHistory.getTimes().setScanFilesEnd(Instant.now());
if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Indexable file iteration");
@@ -168,7 +169,7 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
}
}
projectIndexingHistory.getTimes().setEndIndexing(nowMillis());
projectIndexingHistory.getTimes().setIndexingEnd(Instant.now());
if (!ApplicationManager.getApplication().isUnitTestMode()) {
NonUrgentExecutor.getInstance().execute(() -> {
@@ -181,10 +182,6 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
myIndex.dumpIndexStatistics();
}
private static long nowMillis() {
return System.currentTimeMillis();
}
@NotNull
private Map<IndexableFilesProvider, List<VirtualFile>> collectIndexableFilesConcurrently(
@NotNull Project project,
@@ -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.toJson
import java.time.Instant
typealias TimeMillis = Long
typealias TimeNano = Long
@@ -74,16 +75,13 @@ data class ProjectIndexingHistory(val projectName: String) {
)
data class IndexingTimes(
var startIndexing: TimeMillis = 0,
var endIndexing: TimeMillis = 0,
var startPushProperties: TimeMillis = 0,
var endPushProperties: TimeMillis = 0,
var startIndexExtensions: TimeMillis = 0,
var endIndexExtensions: TimeMillis = 0,
var startScanFiles: TimeMillis = 0,
var endScanFiles: TimeMillis = 0
var indexingStart: Instant? = null,
var indexingEnd: Instant? = null,
var pushPropertiesStart: Instant? = null,
var pushPropertiesEnd: Instant? = null,
var indexExtensionsStart: Instant? = null,
var indexExtensionsEnd: Instant? = null,
var scanFilesStart: Instant? = null,
var scanFilesEnd: Instant? = null
)
}
@@ -3,6 +3,8 @@ package com.intellij.util.indexing.diagnostic.dto
import com.intellij.util.indexing.diagnostic.*
import com.intellij.util.text.DateFormatUtil
import java.time.Duration
import java.time.Instant
fun TimeNano.toMillis(): TimeMillis = this / 1_000_000
@@ -63,23 +65,23 @@ private fun FileProviderIndexStatistics.aggregateStatsPerIndexer(): List<JsonFil
}
}
private fun TimeMillis.toPresentableTime(): PresentableTime =
DateFormatUtil.getIso8601Format().format(this)
private fun Instant.toPresentableTime(): PresentableTime =
DateFormatUtil.getIso8601Format().format(this.toEpochMilli())
fun ProjectIndexingHistory.IndexingTimes.toJson() =
JsonProjectIndexingHistoryTimes(
startIndexing.toPresentableTime(),
endIndexing.toPresentableTime(),
JsonTime((endIndexing - startIndexing).toNano()),
startPushProperties.toPresentableTime(),
endPushProperties.toPresentableTime(),
JsonTime((endPushProperties - startPushProperties).toNano()),
startIndexExtensions.toPresentableTime(),
endIndexExtensions.toPresentableTime(),
JsonTime((endIndexExtensions - startIndexExtensions).toNano()),
startScanFiles.toPresentableTime(),
endScanFiles.toPresentableTime(),
JsonTime((endScanFiles - startScanFiles).toNano())
JsonTime(Duration.between(indexingStart, indexingEnd).toNanos()),
JsonTime(Duration.between(scanFilesStart, scanFilesEnd).toNanos()),
JsonTime(Duration.between(pushPropertiesStart, pushPropertiesEnd).toNanos()),
JsonTime(Duration.between(indexExtensionsStart, indexExtensionsEnd).toNanos()),
indexingStart!!.toPresentableTime(),
indexingEnd!!.toPresentableTime(),
pushPropertiesStart!!.toPresentableTime(),
pushPropertiesEnd!!.toPresentableTime(),
indexExtensionsStart!!.toPresentableTime(),
indexExtensionsEnd!!.toPresentableTime(),
scanFilesStart!!.toPresentableTime(),
scanFilesEnd!!.toPresentableTime()
)
private fun calculatePercentages(part: Long, total: Long): JsonPercentages =
@@ -5,7 +5,7 @@ data class JsonProjectIndexingHistory(
val projectName: String,
val numberOfFileProviders: Int,
val totalNumberOfFiles: Int,
val indexingTimes: JsonProjectIndexingHistoryTimes,
val times: JsonProjectIndexingHistoryTimes,
val totalStatsPerFileType: List<JsonStatsPerFileType>,
val totalStatsPerIndexer: List<JsonStatsPerIndexer>,
val fileProviderStatistics: List<JsonFileProviderIndexStatistics>
@@ -3,19 +3,17 @@ package com.intellij.util.indexing.diagnostic.dto
@Suppress("unused", "used for JSON")
data class JsonProjectIndexingHistoryTimes(
val startIndexing: PresentableTime,
val endIndexing: PresentableTime,
val indexingTime: JsonTime,
val startPushProperties: PresentableTime,
val endPushProperties: PresentableTime,
val scanFilesTime: JsonTime,
val pushPropertiesTime: JsonTime,
val startIndexExtensions: PresentableTime,
val endIndexExtensions: PresentableTime,
val indexExtensionsTime: JsonTime,
val startScanFiles: PresentableTime,
val endScanFiles: PresentableTime,
val scanFilesTime: JsonTime
val indexingStart: PresentableTime,
val indexingEnd: PresentableTime,
val pushPropertiesStart: PresentableTime,
val pushPropertiesEnd: PresentableTime,
val indexExtensionsStart: PresentableTime,
val indexExtensionsEnd: PresentableTime,
val scanFilesStart: PresentableTime,
val scanFilesEnd: PresentableTime
)