Improved thread safety logs to help diagnosis

This commit is contained in:
Unknown 2018-07-12 11:40:54 +02:00 committed by unknown
parent 561d0b3d6e
commit 4721d92db6
3 changed files with 17 additions and 3 deletions

View file

@ -47,7 +47,15 @@ public class LocalProfiler {
}
public static void printCallStats() {
if (!WarpDriveConfig.LOGGING_PROFILING_THREAD_SAFETY) {
WarpDrive.logger.info("Consider enabling thread safety profiling to get more details next time");
return;
}
WarpDrive.logger.info("Dumping chunk stats:");
if (stats.isEmpty()) {
WarpDrive.logger.info("-none-");
return;
}
for (final Entry<String, Integer> entryStat : stats.entrySet()) {
WarpDrive.logger.info(String.format("%10d x %s",
entryStat.getValue(),

View file

@ -359,14 +359,17 @@ public class ChunkHandler {
return;
}
int countLoaded = 0;
int countRemoved = 0;
final long timeForRemoval = System.currentTimeMillis() - CHUNK_HANDLER_UNLOADED_CHUNK_MAX_AGE_MS;
final long timeForThrottle = System.currentTimeMillis() + 200;
final long sizeBefore = mapRegistryItems.size();
long indexCurrent = 0L;
try {
for (final Iterator<Entry<Long, ChunkData>> entryIterator = mapRegistryItems.entrySet().iterator(); entryIterator.hasNext(); ) {
final Map.Entry<Long, ChunkData> entryChunkData = entryIterator.next();
indexCurrent = entryChunkData.getKey();
final ChunkData chunkData = entryChunkData.getValue();
// update loaded chunks, remove old unloaded chunks
if (chunkData.isLoaded()) {
@ -383,14 +386,16 @@ public class ChunkHandler {
mapRegistryItems.size()));
}
entryIterator.remove();
countRemoved++;
}
}
} catch (final ConcurrentModificationException exception) {
WarpDrive.logger.error(String.format("%s world %s had some chunks changed outside main thread? (size %d -> %d)",
world.isRemote ? "Client" : "Server",
WarpDrive.logger.error(String.format("%s world %s had some chunks changed outside main thread? (size %d -> %d, loaded %d, removed %d, index 0x%X x %d z %d)",
world.isRemote ? "Client" : "Server",
Commons.format(world),
sizeBefore, mapRegistryItems.size()));
sizeBefore, mapRegistryItems.size(), countLoaded, countRemoved,
indexCurrent, indexCurrent & 0xFFFFFFFFL, (indexCurrent >> 32) & 0xFFFFFFFFL));
exception.printStackTrace();
LocalProfiler.printCallStats();
}

View file

@ -93,6 +93,7 @@ public class EMPReceiver implements IEMPReceiver, ICapabilityProvider {
@Nullable
@Override
@Optional.Method(modid = "icbmclassic")
@SuppressWarnings("unchecked")
public <T> T getCapability(@Nonnull final Capability<T> capability, @Nullable final EnumFacing facing) {
return capability == CapabilityEMP.EMP ? (T) this : null;
}