Add threading debug

This commit is contained in:
crschnick 2023-12-05 19:05:33 +00:00
parent b1f5c0549c
commit ce32613dd4
3 changed files with 22 additions and 11 deletions

View file

@ -30,6 +30,7 @@ public class AppProperties {
boolean image;
boolean staging;
boolean useVirtualThreads;
boolean debugThreads;
Path dataDir;
boolean showcase;
@ -50,6 +51,9 @@ public class AppProperties {
useVirtualThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.useVirtualThreads"))
.map(Boolean::parseBoolean)
.orElse(true);
debugThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.debugThreads"))
.map(Boolean::parseBoolean)
.orElse(false);
dataDir = XPipeInstallation.getDataDir();
showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase"))
.map(Boolean::parseBoolean)

View file

@ -2,22 +2,29 @@ package io.xpipe.app.util;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.core.util.FailableRunnable;
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadHelper {
public static Thread unstarted(Runnable r) {
return AppProperties.get().isUseVirtualThreads() ? Thread.ofVirtual().unstarted(r) : Thread.ofPlatform().unstarted(r);
private static final AtomicInteger counter = new AtomicInteger();
private static Runnable wrap(Runnable r) {
return () -> {
if (AppProperties.get().isDebugThreads()) {
TrackEvent.trace("Started. Active threads: " + counter.incrementAndGet());
}
r.run();
if (AppProperties.get().isDebugThreads()) {
TrackEvent.trace("Finished. Active threads: " + counter.decrementAndGet());
}
};
}
public static Thread unstartedFailable(FailableRunnable<Exception> r) {
return unstarted(() -> {
try {
r.run();
} catch (Throwable e) {
ErrorEvent.fromThrowable(e).handle();
}
});
public static Thread unstarted(Runnable r) {
return AppProperties.get().isUseVirtualThreads() ? Thread.ofVirtual().unstarted(wrap(r)) : Thread.ofPlatform().unstarted(wrap(r));
}
public static Thread runAsync(Runnable r) {

View file

@ -53,6 +53,6 @@ public class ChmodAction implements BranchAction {
@Override
public List<LeafAction> getBranchingActions(OpenFileSystemModel model, List<BrowserEntry> entries) {
return List.of(new Chmod("600"), new Chmod("644"), new Chmod("700"), new Chmod("777"), new Chmod("u+x"), new Chmod("a+x"));
return List.of(new Chmod("400"), new Chmod("600"), new Chmod("644"), new Chmod("700"), new Chmod("777"), new Chmod("u+x"), new Chmod("a+x"));
}
}