From 78c107f17684a036b149609c4b71b02d417746f0 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Tue, 20 Dec 2022 18:53:33 +0100 Subject: [PATCH] Add JFR events --- .../plotsquared/core/command/HomeCommand.java | 14 +++++++++ .../java/com/plotsquared/core/plot/Plot.java | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index 2218ba44e..4c523db31 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -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 confirm, final RunnableVal2 whenDone ) { + final HomeQueryEvent event = new HomeQueryEvent(); + event.begin(); List plots = query.asList(); + event.size = plots.size(); + event.commit(); if (plots.isEmpty()) { player.sendMessage(TranslatableCaption.of("invalid.found_no_plots")); return; diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 098b95656..fba3c6179 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -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
* - This result is cached globally @@ -2295,13 +2317,19 @@ public class Plot { * @return a Set of Plots connected to this Plot */ public Set 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; }