Indexing diagnostics: reuse FileIndexingStatistics and remove a similar class from FileBasedIndexImpl.

GitOrigin-RevId: 2f1e1b6d75a5b31da72f86541e115a8367ab3549
This commit is contained in:
Sergey Patrikeev
2021-01-04 09:23:31 +00:00
committed by intellij-monorepo-bot
parent 572a5abe32
commit 649fa0cab9
3 changed files with 32 additions and 54 deletions
@@ -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<ID<?, ?>, Long> updateTimesPerIndexer;
public final Map<ID<?, ?>, Long> deletionTimesPerIndexer;
public final FileType fileType;
public final Set<ID<?, ?>> indexesProvidedByExtensions;
public final boolean wasFullyIndexedByExtensions;
private FileIndexingResult(boolean setIndexedStatus,
@NotNull Map<ID<?, ?>, Long> updateTimesPerIndexer,
@NotNull Map<ID<?, ?>, Long> deletionTimesPerIndexer,
@NotNull FileType type,
@NotNull Set<ID<?, ?>> 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<Boolean, FileIndexingStatistics> doIndexFileContent(@Nullable Project project, @NotNull CachedFileContent content) {
ProgressManager.checkCanceled();
final VirtualFile file = content.getVirtualFile();
Ref<Boolean> 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) {
@@ -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<ID<*, *>>,
val wasFullyIndexedByExtensions: Boolean,
val perIndexerTimes: Map<ID<*, *>, TimeNano>
)
val perIndexerUpdateTimes: Map<ID<*, *>, TimeNano>,
val perIndexerDeleteTimes: Map<ID<*, *>, TimeNano>
) {
val indexingTime: TimeNano
get() = perIndexerUpdateTimes.values.sum() + perIndexerDeleteTimes.values.sum()
}
@@ -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)
}