Indexing stats: propagate indexing reason down to UnindexedFilesIndexer

GitOrigin-RevId: 6dedb233d9ff5fc40d5017a1a0a2a7f699360410
This commit is contained in:
Andrei.Kuznetsov
2023-01-23 15:57:52 +01:00
committed by intellij-monorepo-bot
parent 1b51234983
commit fb9d572513
5 changed files with 20 additions and 11 deletions

View File

@@ -76,8 +76,9 @@ public final class FileBasedIndexProjectHandler {
indicator.setIndeterminate(false);
indicator.setText(IndexingBundle.message("progress.indexing.updating"));
String indexingReason = "On refresh of files in " + myProject.getName();
ProjectIndexingHistoryImpl projectIndexingHistory = new ProjectIndexingHistoryImpl(myProject,
"On refresh of files in " + myProject.getName(),
indexingReason,
ScanningType.REFRESH);
IndexDiagnosticDumper.getInstance().onIndexingStarted(projectIndexingHistory);
@@ -109,7 +110,7 @@ public final class FileBasedIndexProjectHandler {
//
// Fair amount of FileBasedIndexProjectHandler.scheduleReindexingInDumbMode invocations are observed during massive refresh (e.g. branch change).
// In practice, we observe 2-3 scanning tasks followed by a single indexing task.
new UnindexedFilesIndexer(myProject, files).indexFiles(projectIndexingHistory, indicator);
new UnindexedFilesIndexer(myProject, files, indexingReason).indexFiles(projectIndexingHistory, indicator);
}
catch (Exception e) {
projectIndexingHistory.setWasInterrupted(true);

View File

@@ -201,11 +201,11 @@ class PerProjectIndexingQueue(private val project: Project) : Disposable {
}
}
fun flushNow() {
fun flushNow(reason: String) {
val (filesInQueue, totalFiles, currentLatch) = getAndResetQueuedFiles()
try {
if (totalFiles > 0) {
UnindexedFilesIndexer(project, filesInQueue).queue(project)
UnindexedFilesIndexer(project, filesInQueue, reason).queue(project)
}
else {
LOG.info("Finished for " + project.name + ". No files to index with loading content.")
@@ -219,7 +219,8 @@ class PerProjectIndexingQueue(private val project: Project) : Disposable {
val (filesInQueue, totalFiles, currentLatch) = getAndResetQueuedFiles()
try {
if (totalFiles > 0) {
UnindexedFilesIndexer(project, filesInQueue).indexFiles(projectIndexingHistory, indicator)
val indexingReason = projectIndexingHistory.indexingReason ?: "Flushing queue of project ${project.name}"
UnindexedFilesIndexer(project, filesInQueue, indexingReason).indexFiles(projectIndexingHistory, indicator)
}
else {
LOG.info("Finished for " + project.name + ". No files to index with loading content.")

View File

@@ -22,6 +22,7 @@ import com.intellij.util.indexing.diagnostic.ProjectIndexingHistoryImpl;
import com.intellij.util.indexing.diagnostic.ScanningType;
import com.intellij.util.indexing.roots.IndexableFilesIterator;
import com.intellij.util.indexing.snapshot.SnapshotInputMappingsStatistics;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -33,12 +34,15 @@ class UnindexedFilesIndexer extends DumbModeTask {
private final Project myProject;
private final FileBasedIndexImpl myIndex;
private final Map<IndexableFilesIterator, Collection<VirtualFile>> providerToFiles;
private final @NonNls @NotNull String indexingReason;
UnindexedFilesIndexer(Project project,
Map<IndexableFilesIterator, Collection<VirtualFile>> providerToFiles) {
Map<IndexableFilesIterator, Collection<VirtualFile>> providerToFiles,
@NonNls @NotNull String indexingReason) {
myProject = project;
myIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
this.providerToFiles = providerToFiles;
this.indexingReason = indexingReason;
}
void indexFiles(@NotNull ProjectIndexingHistoryImpl projectIndexingHistory,
@@ -124,7 +128,7 @@ class UnindexedFilesIndexer extends DumbModeTask {
if (!IndexInfrastructure.hasIndices()) {
return;
}
ProjectIndexingHistoryImpl projectIndexingHistory = new ProjectIndexingHistoryImpl(myProject, "Async indexing", ScanningType.REFRESH);
ProjectIndexingHistoryImpl projectIndexingHistory = new ProjectIndexingHistoryImpl(myProject, indexingReason, ScanningType.REFRESH);
IndexDiagnosticDumper.getInstance().onIndexingStarted(projectIndexingHistory);
ProgressSuspender suspender = ProgressSuspender.getSuspender(indicator);
if (suspender != null) {
@@ -173,7 +177,10 @@ class UnindexedFilesIndexer extends DumbModeTask {
mergedFilesToIndex.put(e.getKey(), mergedList);
}
return new UnindexedFilesIndexer(myProject, mergedFilesToIndex);
String mergedReason = "Merged " + StringUtil.trimStart(indexingReason, "Merged ") +
" with " + StringUtil.trimStart(otherIndexingTask.indexingReason, "Merged ");
return new UnindexedFilesIndexer(myProject, mergedFilesToIndex, mergedReason);
}
private static double getPowerForSmoothProgressIndicator() {

View File

@@ -259,7 +259,7 @@ public class UnindexedFilesScanner implements MergeableQueueTask<UnindexedFilesS
if (shouldScanInSmartMode()) {
// Switch to dumb mode and index
myProject.getService(PerProjectIndexingQueue.class).flushNow();
myProject.getService(PerProjectIndexingQueue.class).flushNow(myIndexingReason);
}
else {
// Already in dumb mode. Just invoke indexer

View File

@@ -51,8 +51,8 @@ public class ScanningIndexingTasksMergeTest extends LightPlatformTestCase {
map2.put(iter2, f2);
map2.put(iterShared, fShared.subList(1, 3));
task1 = new UnindexedFilesIndexer(getProject(), map1);
task2 = new UnindexedFilesIndexer(getProject(), map2);
task1 = new UnindexedFilesIndexer(getProject(), map1, "test task1");
task2 = new UnindexedFilesIndexer(getProject(), map2, "test task2");
}
public void testTryMergeIndexingTasks() {