Fix profiler

This commit is contained in:
dfsek
2020-12-08 21:26:42 -07:00
parent 1457a10b0b
commit df3d3c6398
12 changed files with 26 additions and 41 deletions

View File

@@ -1,17 +1,11 @@
package com.dfsek.terra;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;
import org.polydev.gaea.profiler.DataType;
import org.polydev.gaea.profiler.Measurement;
import org.polydev.gaea.profiler.WorldProfiler;
import java.util.HashMap;
import java.util.Map;
public class TerraProfiler extends WorldProfiler {
private static final Map<World, TerraProfiler> profilerMap = new HashMap<>();
public TerraProfiler(World w) {
super(w);
this
@@ -22,13 +16,4 @@ public class TerraProfiler extends WorldProfiler {
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime")
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime");
}
public static TerraProfiler fromWorld(World w) {
if(w.getGenerator() instanceof TerraChunkGenerator) {
if(profilerMap.containsKey(w)) return profilerMap.get(w);
TerraProfiler p = new TerraProfiler(w);
profilerMap.put(w, p);
return p;
} else throw new IllegalArgumentException("Attempted to instantiate/fetch Profiler for non-Terra world!");
}
}

View File

@@ -18,11 +18,13 @@ public class TerraWorld {
private final BiomeZone zone;
private final ConfigPack config;
private boolean safe;
private final TerraProfiler profiler;
public TerraWorld(World w, ConfigPack c) {
safe = true;
config = c;
profiler = new TerraProfiler(w);
ConfigPackTemplate template = config.getTemplate();
@@ -71,4 +73,8 @@ public class TerraWorld {
public boolean isSafe() {
return safe;
}
public TerraProfiler getProfiler() {
return profiler;
}
}

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.Terra;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -18,8 +18,8 @@ public class QueryCommand extends WorldCommand {
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
WorldProfiler profile = TerraProfiler.fromWorld(w);
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
sender.sendMessage(profile.getResultsFormatted());
return true;
}

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -20,7 +20,7 @@ public class ResetCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
profile.reset();
LangUtil.send("command.profile.reset", sender);
return true;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -20,7 +20,7 @@ public class StartCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
profile.setProfiling(true);
LangUtil.send("command.profile.start", sender);
return true;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -20,7 +20,7 @@ public class StopCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
profile.setProfiling(false);
LangUtil.send("command.profile.stop", sender);
return true;

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.generation;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.ConfigPack;
@@ -98,7 +97,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
ElevationInterpolator elevationInterpolator;
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("ElevationTime")) {
try(ProfileFuture ignore = tw.getProfiler().measure("ElevationTime")) {
elevationInterpolator = new ElevationInterpolator(chunkX, chunkZ, tw.getGrid());
}

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack;
@@ -36,9 +35,9 @@ public class CavePopulator extends BlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("CaveTime")) {
Random random = PopulationUtil.getRandom(chunk);
TerraWorld tw = main.getWorld(world);
if(!tw.isSafe()) return;
ConfigPack config = tw.getConfig();

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
@@ -32,8 +31,8 @@ public class FloraPopulator extends GaeaBlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
TerraWorld tw = main.getWorld(world);
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("FloraTime")) {
if(!tw.isSafe()) return;
TerraBiomeGrid grid = tw.getGrid();
Map<Vector2, List<FloraLayer>> layers = new HashMap<>();

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.templates.BiomeTemplate;
@@ -28,8 +27,8 @@ public class OrePopulator extends GaeaBlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
TerraWorld tw = main.getWorld(world);
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("OreTime")) {
if(!tw.isSafe()) return;
for(int cx = -1; cx <= 1; cx++) {
for(int cz = -1; cz <= 1; cz++) {

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
@@ -38,11 +37,11 @@ public class StructurePopulator extends BlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("StructureTime")) {
Random random = PopulationUtil.getRandom(chunk);
int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4);
TerraWorld tw = main.getWorld(world);
if(!tw.isSafe()) return;
TerraBiomeGrid grid = tw.getGrid();
ConfigPack config = tw.getConfig();

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
@@ -32,8 +31,8 @@ public class TreePopulator extends GaeaBlockPopulator {
@Override
@SuppressWarnings("try")
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeTime")) {
TerraWorld tw = main.getWorld(world);
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("TreeTime")) {
if(!tw.isSafe()) return;
TerraBiomeGrid grid = tw.getGrid();
for(int x = 0; x < 16; x += 2) {