Add JFR events

This commit is contained in:
SirYwell 2022-12-20 18:53:33 +01:00
parent bbf1e4fe61
commit 78c107f176
No known key found for this signature in database
2 changed files with 45 additions and 0 deletions

View File

@ -35,6 +35,9 @@ import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import net.kyori.adventure.text.minimessage.Template;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -59,13 +62,24 @@ public class HomeCommand extends Command {
this.plotAreaManager = plotAreaManager;
}
@Label("Home Query")
@Category("PlotSquared")
static class HomeQueryEvent extends Event {
@Label("Result Size")
public int size;
}
private void home(
final @NonNull PlotPlayer<?> player,
final @NonNull PlotQuery query, final int page,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone
) {
final HomeQueryEvent event = new HomeQueryEvent();
event.begin();
List<Plot> plots = query.asList();
event.size = plots.size();
event.commit();
if (plots.isEmpty()) {
player.sendMessage(TranslatableCaption.of("invalid.found_no_plots"));
return;

View File

@ -68,6 +68,9 @@ import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -2288,6 +2291,25 @@ public class Plot {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
@Label("Connected Plots Search")
@Category("PlotSquared")
static class ConnectedPlotsEvent extends Event {
public ConnectedPlotsEvent(final int x, final int y) {
this.x = x;
this.y = y;
}
@Label("Plot Id X")
public int x;
@Label("Plot Id Y")
public int y;
@Label("Merged Plots Count")
public int mergedSize;
@Label("Connected Plots Cache Miss")
public boolean cacheMiss;
}
/**
* Gets a set of plots connected (and including) this plot<br>
* - This result is cached globally
@ -2295,13 +2317,19 @@ public class Plot {
* @return a Set of Plots connected to this Plot
*/
public Set<Plot> getConnectedPlots() {
ConnectedPlotsEvent event = new ConnectedPlotsEvent(this.id.getX(), this.id.getY());
event.begin();
if (this.settings == null) {
event.commit();
return Collections.singleton(this);
}
if (!this.isMerged()) {
event.commit();
return Collections.singleton(this);
}
if (connected_cache != null && connected_cache.contains(this)) {
event.mergedSize = connected_cache.size();
event.commit();
return connected_cache;
}
regions_cache = null;
@ -2410,6 +2438,9 @@ public class Plot {
}
}
connected_cache = tmpSet;
event.mergedSize = tmpSet.size();
event.cacheMiss = true;
event.commit();
return tmpSet;
}