Skip to content

Commit

Permalink
Temporarily log regurgitator and vfs related events
Browse files Browse the repository at this point in the history
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 e8332fe)
  • Loading branch information
Googler authored and mai93 committed Feb 26, 2024
1 parent 612f947 commit 8100a67
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,17 @@
<action internal="true" id="Blaze.QSync.CleanDependencies" class="com.google.idea.blaze.base.qsync.action.CleanDependencies" text="QSync - Clean Dependencies" />
<action internal="true" id="Blaze.QSync.ReloadProject" class="com.google.idea.blaze.base.qsync.action.ReloadProject" text="QSync - Reload project" />
<action internal="true" id="Blaze.QSync.ShowPromo" class="com.google.idea.blaze.base.qsync.action.ShowPromoAction" text="Show qsync promo" />
<action internal="true" id="Blaze.VFS.DumpVfsDirs" class="com.google.idea.blaze.base.actions.internal.AswbDumpVfs" text="ASwB - Dump VFS Dirs"/>
<add-to-group group-id="Internal"/>
</group>
</actions>

<applicationListeners>
<listener
class="com.google.idea.blaze.base.actions.internal.AswbDumpVfs$BulkListener"
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/>
</applicationListeners>

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="com.google.idea.blaze.base.sync.BlazeSyncStartupActivity"/>
<postStartupActivity implementation="com.google.idea.blaze.base.project.DisableAndroidFrameworkActivity"/>
Expand Down
109 changes: 109 additions & 0 deletions base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java
Original file line number Diff line number Diff line change
@@ -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<VirtualFile> 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<? extends VFileEvent> 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.");
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Pair<String, String>> collection);

@Override
default void notifyMapping(@NotNull Collection<Pair<String, String>> collection) {
notifyMappingCompat(ImmutableList.copyOf(collection));
}
}
Original file line number Diff line number Diff line change
@@ -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<Pair<String, String>> collection);

@Override
default void notifyMapping(@NotNull Collection<? extends Pair<String, String>> collection) {
notifyMappingCompat(ImmutableList.copyOf(collection));
}
}
Original file line number Diff line number Diff line change
@@ -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<Pair<String, String>> collection);

@Override
default void notifyMapping(@NotNull Collection<? extends Pair<String, String>> collection) {
notifyMappingCompat(ImmutableList.copyOf(collection));
}
}
Original file line number Diff line number Diff line change
@@ -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<Pair<String, String>> collection);

@Override
default void notifyMapping(@NotNull Collection<? extends Pair<String, String>> collection) {
notifyMappingCompat(ImmutableList.copyOf(collection));
}
}

0 comments on commit 8100a67

Please sign in to comment.