From 649fa0cab9b83fbef931a66076ff5153e63589a5 Mon Sep 17 00:00:00 2001 From: Sergey Patrikeev Date: Mon, 4 Jan 2021 12:22:57 +0300 Subject: [PATCH] Indexing diagnostics: reuse FileIndexingStatistics and remove a similar class from FileBasedIndexImpl. GitOrigin-RevId: 2f1e1b6d75a5b31da72f86541e115a8367ab3549 --- .../util/indexing/FileBasedIndexImpl.java | 75 +++++++------------ .../diagnostic/FileIndexingStatistics.kt | 9 ++- .../diagnostic/IndexingJobStatistics.kt | 2 +- 3 files changed, 32 insertions(+), 54 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index 34d091252e0d..132b1feac619 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1194,7 +1194,8 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { VirtualFile file = content.getVirtualFile(); final int fileId = getFileId(file); - FileIndexingResult indexingResult; + boolean setIndexedStatus; + FileIndexingStatistics indexingStatistics; try { boolean isValid = file.isValid(); // if file was scheduled for update due to vfs events then it is present in myFilesToUpdate @@ -1208,67 +1209,38 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { isIndexesDeleted = true; ProgressManager.checkCanceled(); removeDataFromIndicesForFile(fileId, file); - indexingResult = new FileIndexingResult(true, - Collections.emptyMap(), - Collections.emptyMap(), - file.getFileType(), - Collections.emptySet(), - false); + setIndexedStatus = true; + indexingStatistics = new FileIndexingStatistics(file.getFileType(), + Collections.emptySet(), + false, + Collections.emptyMap(), + Collections.emptyMap()); } else { isIndexesDeleted = false; - indexingResult = doIndexFileContent(project, content); + var pair = doIndexFileContent(project, content); + setIndexedStatus = pair.first; + indexingStatistics = pair.second; } - if (indexingResult.setIndexedStatus && file instanceof VirtualFileSystemEntry) { + if (setIndexedStatus && file instanceof VirtualFileSystemEntry) { ((VirtualFileSystemEntry)file).setFileIndexed(true); } if (VfsEventsMerger.LOG != null) { VfsEventsMerger.LOG.info("File " + file + - " indexes have been updated for indexes " + indexingResult.updateTimesPerIndexer.keySet() + - " and deleted for " + indexingResult.deletionTimesPerIndexer.keySet() + + " indexes have been updated for indexes " + indexingStatistics.getPerIndexerUpdateTimes().keySet() + + " and deleted for " + indexingStatistics.getPerIndexerDeleteTimes().keySet() + ". Indexes was wiped = " + isIndexesDeleted + "; is file valid = " + isValid); } getChangedFilesCollector().removeFileIdFromFilesScheduledForUpdate(fileId); - // Indexing time takes only input data mapping time into account. - long indexingTime = - indexingResult.updateTimesPerIndexer.values().stream().mapToLong(e -> e).sum() + - indexingResult.deletionTimesPerIndexer.values().stream().mapToLong(e -> e).sum(); - return new FileIndexingStatistics(indexingTime, - indexingResult.fileType, - indexingResult.indexesProvidedByExtensions, - indexingResult.wasFullyIndexedByExtensions, - ContainerUtil.union(indexingResult.updateTimesPerIndexer, indexingResult.deletionTimesPerIndexer)); + return indexingStatistics; } finally { IndexingStamp.flushCache(fileId); } } - private static final class FileIndexingResult { - public final boolean setIndexedStatus; - public final Map, Long> updateTimesPerIndexer; - public final Map, Long> deletionTimesPerIndexer; - public final FileType fileType; - public final Set> indexesProvidedByExtensions; - public final boolean wasFullyIndexedByExtensions; - - private FileIndexingResult(boolean setIndexedStatus, - @NotNull Map, Long> updateTimesPerIndexer, - @NotNull Map, Long> deletionTimesPerIndexer, - @NotNull FileType type, - @NotNull Set> indexesProvidedByExtensions, - boolean wasFullyIndexedByExtensions) { - this.setIndexedStatus = setIndexedStatus; - this.updateTimesPerIndexer = updateTimesPerIndexer; - this.deletionTimesPerIndexer = deletionTimesPerIndexer; - this.fileType = type; - this.indexesProvidedByExtensions = indexesProvidedByExtensions; - this.wasFullyIndexedByExtensions = wasFullyIndexedByExtensions; - } - } - private static final class SingleIndexUpdateStats { public final long mapInputTime; public final boolean indexWasProvidedByExtension; @@ -1280,7 +1252,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } @NotNull - private FileBasedIndexImpl.FileIndexingResult doIndexFileContent(@Nullable Project project, @NotNull CachedFileContent content) { + private Pair doIndexFileContent(@Nullable Project project, @NotNull CachedFileContent content) { ProgressManager.checkCanceled(); final VirtualFile file = content.getVirtualFile(); Ref setIndexedStatus = Ref.create(Boolean.TRUE); @@ -1367,12 +1339,15 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { }); file.putUserData(IndexingDataKeys.REBUILD_REQUESTED, null); - return new FileIndexingResult(setIndexedStatus.get(), - perIndexerUpdateTimes, - perIndexerDeletionTimes, - fileTypeRef.get(), - indexesProvidedByExtensions, - wasFullyIndexedByInfrastructureExtensions.get()); + return Pair.create( + setIndexedStatus.get(), + new FileIndexingStatistics( + fileTypeRef.get(), + indexesProvidedByExtensions, + wasFullyIndexedByInfrastructureExtensions.get(), + perIndexerUpdateTimes, + perIndexerDeletionTimes + )); } private static byte @NotNull[] getBytesOrNull(@NotNull CachedFileContent content) { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/FileIndexingStatistics.kt b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/FileIndexingStatistics.kt index 87449f610e84..d64326f6b34d 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/FileIndexingStatistics.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/FileIndexingStatistics.kt @@ -5,9 +5,12 @@ import com.intellij.openapi.fileTypes.FileType import com.intellij.util.indexing.ID class FileIndexingStatistics( - val indexingTime: TimeNano, val fileType: FileType, val indexesProvidedByExtensions: Set>, val wasFullyIndexedByExtensions: Boolean, - val perIndexerTimes: Map, TimeNano> -) \ No newline at end of file + val perIndexerUpdateTimes: Map, TimeNano>, + val perIndexerDeleteTimes: Map, TimeNano> +) { + val indexingTime: TimeNano + get() = perIndexerUpdateTimes.values.sum() + perIndexerDeleteTimes.values.sum() +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/IndexingJobStatistics.kt b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/IndexingJobStatistics.kt index f3fbcbdb3cfd..5f49459eb8ef 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/IndexingJobStatistics.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/IndexingJobStatistics.kt @@ -51,7 +51,7 @@ class IndexingJobStatistics(private val project: Project, val fileSetName: Strin if (fileStatistics.wasFullyIndexedByExtensions) { numberOfFilesFullyIndexedByExtensions++ } - fileStatistics.perIndexerTimes.forEach { (indexId, time) -> + (fileStatistics.perIndexerUpdateTimes + fileStatistics.perIndexerDeleteTimes).forEach { (indexId, time) -> val stats = statsPerIndexer.getOrPut(indexId.name) { StatsPerIndexer(TimeStats(), 0, 0, 0) }