forked from bazelbuild/intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 e8332fe)
- Loading branch information
Showing
6 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
base/src/com/google/idea/blaze/base/actions/internal/AswbDumpVfs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sdkcompat/v223/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sdkcompat/v231/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sdkcompat/v232/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
sdkcompat/v233/com/google/idea/sdkcompat/platform/FileWatcherNotificationSinkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |