Rework chunk loading timing stats - simpler, more useful

This commit is contained in:
Mike Primm 2014-02-04 07:05:24 -06:00
parent d4f161ca99
commit d6eb822b26

View File

@ -27,7 +27,7 @@ import org.getspout.spoutapi.block.SpoutChunk;
/** /**
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/ */
public class NewMapChunkCache implements MapChunkCache { public class NewMapChunkCache extends MapChunkCache {
private static boolean init = false; private static boolean init = false;
private static boolean use_spout = false; private static boolean use_spout = false;
@ -51,12 +51,6 @@ public class NewMapChunkCache implements MapChunkCache {
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */ private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
private long[] inhabitedTicks; /* Index = (x-x_min) + ((z-z_min)*x_dim) */ private long[] inhabitedTicks; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
private int chunks_read; /* Number of chunks actually loaded */
private int chunks_attempted; /* Number of chunks attempted to load */
private long total_loadtime; /* Total time loading chunks, in nanoseconds */
private long exceptions;
private static BukkitVersionHelper helper = BukkitVersionHelper.getHelper(); private static BukkitVersionHelper helper = BukkitVersionHelper.getHelper();
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS, private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
@ -211,7 +205,6 @@ public class NewMapChunkCache implements MapChunkCache {
try { try {
return biomemap[x - x_base][z - z_base]; return biomemap[x - x_base][z - z_base];
} catch (Exception ex) { } catch (Exception ex) {
exceptions++;
return BiomeMap.NULL; return BiomeMap.NULL;
} }
} }
@ -241,7 +234,6 @@ public class NewMapChunkCache implements MapChunkCache {
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9); mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
} catch (Exception x) { } catch (Exception x) {
exceptions++;
mult = 0xFFFFFF; mult = 0xFFFFFF;
} }
return mult; return mult;
@ -272,7 +264,6 @@ public class NewMapChunkCache implements MapChunkCache {
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9); mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
} catch (Exception x) { } catch (Exception x) {
exceptions++;
mult = 0xFFFFFF; mult = 0xFFFFFF;
} }
return mult; return mult;
@ -314,7 +305,6 @@ public class NewMapChunkCache implements MapChunkCache {
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9); mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
} catch (Exception x) { } catch (Exception x) {
exceptions++;
mult = 0xFFFFFF; mult = 0xFFFFFF;
} }
return mult; return mult;
@ -342,7 +332,6 @@ public class NewMapChunkCache implements MapChunkCache {
} }
return ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9); return ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} catch (Exception x) { } catch (Exception x) {
exceptions++;
return 0xFFFFFF; return 0xFFFFFF;
} }
} }
@ -372,7 +361,6 @@ public class NewMapChunkCache implements MapChunkCache {
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9); mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
} catch (Exception x) { } catch (Exception x) {
exceptions++;
mult = 0xFFFFFF; mult = 0xFFFFFF;
} }
return mult; return mult;
@ -807,7 +795,6 @@ public class NewMapChunkCache implements MapChunkCache {
public int loadChunks(int max_to_load) { public int loadChunks(int max_to_load) {
if(dw.isLoaded() == false) if(dw.isLoaded() == false)
return 0; return 0;
long t0 = System.nanoTime();
Object queue = helper.getUnloadQueue(helper.getNMSWorld(w)); Object queue = helper.getUnloadQueue(helper.getNMSWorld(w));
int cnt = 0; int cnt = 0;
@ -818,6 +805,7 @@ public class NewMapChunkCache implements MapChunkCache {
//boolean isnormral = w.getEnvironment() == Environment.NORMAL; //boolean isnormral = w.getEnvironment() == Environment.NORMAL;
// Load the required chunks. // Load the required chunks.
while((cnt < max_to_load) && iterator.hasNext()) { while((cnt < max_to_load) && iterator.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iterator.next(); DynmapChunk chunk = iterator.next();
boolean vis = true; boolean vis = true;
if(visible_limits != null) { if(visible_limits != null) {
@ -858,9 +846,9 @@ public class NewMapChunkCache implements MapChunkCache {
snaptile[idx] = ssr.tileData; snaptile[idx] = ssr.tileData;
inhabitedTicks[idx] = inhabited_ticks; inhabitedTicks[idx] = inhabited_ticks;
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
continue; continue;
} }
chunks_attempted++;
boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z); boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
boolean didload = false; boolean didload = false;
boolean isunloadpending = false; boolean isunloadpending = false;
@ -946,7 +934,6 @@ public class NewMapChunkCache implements MapChunkCache {
/* If wasn't loaded before, we need to do unload */ /* If wasn't loaded before, we need to do unload */
if (!wasLoaded) { if (!wasLoaded) {
chunks_read++;
/* Since we only remember ones we loaded, and we're synchronous, no player has /* Since we only remember ones we loaded, and we're synchronous, no player has
* moved, so it must be safe (also prevent chunk leak, which appears to happen * moved, so it must be safe (also prevent chunk leak, which appears to happen
* because isChunkInUse defined "in use" as being within 256 blocks of a player, * because isChunkInUse defined "in use" as being within 256 blocks of a player,
@ -954,10 +941,18 @@ public class NewMapChunkCache implements MapChunkCache {
* by the MC base server is 21x21 (or about a 160 block radius). * by the MC base server is 21x21 (or about a 160 block radius).
* Also, if we did generate it, need to save it */ * Also, if we did generate it, need to save it */
helper.unloadChunkNoSave(w, c, chunk.x, chunk.z); helper.unloadChunkNoSave(w, c, chunk.x, chunk.z);
endChunkLoad(startTime, ChunkStats.UNLOADED_CHUNKS);
} }
else if (isunloadpending) { /* Else, if loaded and unload is pending */ else if (isunloadpending) { /* Else, if loaded and unload is pending */
w.unloadChunkRequest(chunk.x, chunk.z); /* Request new unload */ w.unloadChunkRequest(chunk.x, chunk.z); /* Request new unload */
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
} }
else {
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
}
}
else {
endChunkLoad(startTime, ChunkStats.UNGENERATED_CHUNKS);
} }
cnt++; cnt++;
} }
@ -973,7 +968,6 @@ public class NewMapChunkCache implements MapChunkCache {
isempty = false; isempty = false;
} }
} }
total_loadtime += System.nanoTime() - t0;
return cnt; return cnt;
} }
@ -1072,22 +1066,6 @@ public class NewMapChunkCache implements MapChunkCache {
public DynmapWorld getWorld() { public DynmapWorld getWorld() {
return dw; return dw;
} }
@Override
public int getChunksLoaded() {
return chunks_read;
}
@Override
public int getChunkLoadsAttempted() {
return chunks_attempted;
}
@Override
public long getTotalRuntimeNanos() {
return total_loadtime;
}
@Override
public long getExceptionCount() {
return exceptions;
}
static { static {
Biome[] b = Biome.values(); Biome[] b = Biome.values();