From 8100a67c40ba855d2ca8df97c1379a4e740068d3 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 16 Feb 2024 09:03:53 -0800 Subject: [PATCH] Temporarily log regurgitator and vfs related events 1. Log regurgitator events sent to the sink 2. Log regurgitator file watcher configuration 3. Log VFS events 4. Add an internal action to log the list of directories in the VFS Use loggers with `_diag_vfs` suffix to simplify filtering relevant messages. (cherry picked from commit e8332feb234e475ca034ebbfaedc9bb943198dea) --- base/src/META-INF/blaze-base.xml | 7 ++ .../base/actions/internal/AswbDumpVfs.java | 109 ++++++++++++++++++ .../FileWatcherNotificationSinkCompat.java | 17 +++ .../FileWatcherNotificationSinkCompat.java | 17 +++ .../FileWatcherNotificationSinkCompat.java | 17 +++ .../FileWatcherNotificationSinkCompat.java | 17 +++ 6 files changed, 184 insertions(+) create mode 100644 base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java create mode 100644 sdkcompat/v223/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java create mode 100644 sdkcompat/v231/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java create mode 100644 sdkcompat/v232/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java create mode 100644 sdkcompat/v233/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml index 685b9a8ef12..b13a2eb85eb 100644 --- a/base/src/META-INF/blaze-base.xml +++ b/base/src/META-INF/blaze-base.xml @@ -203,10 +203,17 @@ + + + + + diff --git a/base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java b/base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java new file mode 100644 index 00000000000..3ca7fc544bd --- /dev/null +++ b/base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java @@ -0,0 +1,109 @@ +/* + * Copyright 2024 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.base.actions.internal; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.Task; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; +import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.events.VFileEvent; +import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +class AswbDumpVfs extends DumbAwareAction { + + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + new Task.Backgroundable(anActionEvent.getProject(), "Enumerating the VFS...") { + @Override + public void run(@NotNull ProgressIndicator progressIndicator) { + try { + dumpChildrenInDbRecursively(VfsUtil.findFile(Path.of("/"), false)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + }.queue(); + } + + private static void dumpChildrenInDbRecursively(VirtualFile dir) throws IOException { + try (PrintStream out = + new PrintStream( + new BufferedOutputStream( + Files.newOutputStream(PathManager.getLogDir().resolve("vfs.txt"))), + false)) { + if (!(dir instanceof NewVirtualFile)) { + out.println(dir.getPresentableUrl() + ": not in db (" + dir.getClass().getName() + ")"); + return; + } + + PersistentFS pfs = PersistentFS.getInstance(); + List dirs = new ArrayList<>(); + dirs.add(dir); + while (!dirs.isEmpty()) { + ProgressManager.checkCanceled(); + dir = dirs.remove(0); + if (pfs.wereChildrenAccessed(dir)) { + out.println(dir.getPath()); + for (String name : pfs.listPersisted(dir)) { + NewVirtualFile child = ((NewVirtualFile) dir).findChildIfCached(name); + if (child == null) { + out.println(dir.getPath() + "/" + name + " - ?? (not found in db)"); + continue; + } + if (child.isDirectory()) { + dirs.add(child); + } + } + } + } + } + } + + static class BulkListener implements BulkFileListener { + private static final Logger vfsDiagLogger = + Logger.getInstance("#" + BulkListener.class.getName() + "_vfs_diag"); + + @Override + public void before(List events) { + vfsDiagLogger.info(String.format("VFS Events: (%d)", events.size())); + for (int i = 0; i < events.size(); i++) { + VFileEvent event = events.get(i); + vfsDiagLogger.info(" " + event); + if (i > 1000) { + vfsDiagLogger.info(" ...more"); + break; + } + } + vfsDiagLogger.info(" end."); + } + } +} diff --git a/sdkcompat/v223/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java b/sdkcompat/v223/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java new file mode 100644 index 00000000000..3ff8a2a8e14 --- /dev/null +++ b/sdkcompat/v223/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java @@ -0,0 +1,17 @@ +package com.google.idea.sdkcompat.platform; + +import com.google.common.collect.ImmutableList; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.local.FileWatcherNotificationSink; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; + +/** A compatibility wrapper for {@link FileWatcherNotificationSink}. */ +public interface FileWatcherNotificationSinkCompat extends FileWatcherNotificationSink { + void notifyMappingCompat(Collection> collection); + + @Override + default void notifyMapping(@NotNull Collection> collection) { + notifyMappingCompat(ImmutableList.copyOf(collection)); + } +} diff --git a/sdkcompat/v231/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java b/sdkcompat/v231/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java new file mode 100644 index 00000000000..a6f29c6fbf9 --- /dev/null +++ b/sdkcompat/v231/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java @@ -0,0 +1,17 @@ +package com.google.idea.sdkcompat.platform; + +import com.google.common.collect.ImmutableList; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.local.FileWatcherNotificationSink; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; + +/** A compatibility wrapper for {@link FileWatcherNotificationSink}. */ +public interface FileWatcherNotificationSinkCompat extends FileWatcherNotificationSink { + void notifyMappingCompat(Collection> collection); + + @Override + default void notifyMapping(@NotNull Collection> collection) { + notifyMappingCompat(ImmutableList.copyOf(collection)); + } +} diff --git a/sdkcompat/v232/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java b/sdkcompat/v232/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java new file mode 100644 index 00000000000..a6f29c6fbf9 --- /dev/null +++ b/sdkcompat/v232/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java @@ -0,0 +1,17 @@ +package com.google.idea.sdkcompat.platform; + +import com.google.common.collect.ImmutableList; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.local.FileWatcherNotificationSink; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; + +/** A compatibility wrapper for {@link FileWatcherNotificationSink}. */ +public interface FileWatcherNotificationSinkCompat extends FileWatcherNotificationSink { + void notifyMappingCompat(Collection> collection); + + @Override + default void notifyMapping(@NotNull Collection> collection) { + notifyMappingCompat(ImmutableList.copyOf(collection)); + } +} diff --git a/sdkcompat/v233/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java b/sdkcompat/v233/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java new file mode 100644 index 00000000000..a6f29c6fbf9 --- /dev/null +++ b/sdkcompat/v233/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java @@ -0,0 +1,17 @@ +package com.google.idea.sdkcompat.platform; + +import com.google.common.collect.ImmutableList; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.local.FileWatcherNotificationSink; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; + +/** A compatibility wrapper for {@link FileWatcherNotificationSink}. */ +public interface FileWatcherNotificationSinkCompat extends FileWatcherNotificationSink { + void notifyMappingCompat(Collection> collection); + + @Override + default void notifyMapping(@NotNull Collection> collection) { + notifyMappingCompat(ImmutableList.copyOf(collection)); + } +}