Added a generic log throttler option
This commit is contained in:
parent
97c8e21fc1
commit
4ca8d0fd45
8 changed files with 33 additions and 29 deletions
|
@ -71,6 +71,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
@ -791,6 +792,17 @@ public class Commons {
|
||||||
return EnumFacing.UP;
|
return EnumFacing.UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, Long> throttle_timePreviousForKey_ms = new ConcurrentHashMap<>(16);
|
||||||
|
public static boolean throttleMe(final String keyword) {
|
||||||
|
final Long timeLastLog_ms = throttle_timePreviousForKey_ms.getOrDefault(keyword, Long.MIN_VALUE);
|
||||||
|
final long timeCurrent_ms = System.currentTimeMillis();
|
||||||
|
if (timeCurrent_ms > timeLastLog_ms + WarpDriveConfig.LOGGING_THROTTLE_MS) {
|
||||||
|
throttle_timePreviousForKey_ms.put(keyword, timeCurrent_ms);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isSafeThread() {
|
public static boolean isSafeThread() {
|
||||||
final String name = Thread.currentThread().getName();
|
final String name = Thread.currentThread().getName();
|
||||||
return name.equals("Server thread") || name.equals("Client thread");
|
return name.equals("Server thread") || name.equals("Client thread");
|
||||||
|
|
|
@ -47,7 +47,6 @@ import java.util.Random;
|
||||||
})
|
})
|
||||||
public abstract class BlockAbstractContainer extends BlockContainer implements IBlockBase, defense.api.IEMPBlock {
|
public abstract class BlockAbstractContainer extends BlockContainer implements IBlockBase, defense.api.IEMPBlock {
|
||||||
|
|
||||||
private static boolean isInvalidEMPreported = false;
|
|
||||||
private static long timeUpdated = -1L;
|
private static long timeUpdated = -1L;
|
||||||
private static int dimensionIdUpdated = Integer.MAX_VALUE;
|
private static int dimensionIdUpdated = Integer.MAX_VALUE;
|
||||||
private static int xUpdated = Integer.MAX_VALUE;
|
private static int xUpdated = Integer.MAX_VALUE;
|
||||||
|
@ -299,8 +298,7 @@ public abstract class BlockAbstractContainer extends BlockContainer implements I
|
||||||
} else if (explosiveEMP.getRadius() == 50.0F) {
|
} else if (explosiveEMP.getRadius() == 50.0F) {
|
||||||
onEMP(world, new BlockPos(x, y, z), 0.70F);
|
onEMP(world, new BlockPos(x, y, z), 0.70F);
|
||||||
} else {
|
} else {
|
||||||
if (!isInvalidEMPreported) {
|
if (Commons.throttleMe("BlockAbstractContainer Invalid EMP radius")) {
|
||||||
isInvalidEMPreported = true;
|
|
||||||
WarpDrive.logger.warn(String.format("EMP received %s from %s with energy %d and unsupported radius %.1f",
|
WarpDrive.logger.warn(String.format("EMP received %s from %s with energy %d and unsupported radius %.1f",
|
||||||
Commons.format(world, x, y, z),
|
Commons.format(world, x, y, z),
|
||||||
explosiveEMP, explosiveEMP.getEnergy(), explosiveEMP.getRadius()));
|
explosiveEMP, explosiveEMP.getEnergy(), explosiveEMP.getRadius()));
|
||||||
|
|
|
@ -58,7 +58,6 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
protected String peripheralName = null;
|
protected String peripheralName = null;
|
||||||
private String[] methodsArray = {};
|
private String[] methodsArray = {};
|
||||||
private boolean isAlwaysInterfaced = true;
|
private boolean isAlwaysInterfaced = true;
|
||||||
private long lastLUAinternalException_ms = Long.MIN_VALUE;
|
|
||||||
|
|
||||||
// String returned to LUA script in case of error
|
// String returned to LUA script in case of error
|
||||||
public static final String COMPUTER_ERROR_TAG = "!ERROR!";
|
public static final String COMPUTER_ERROR_TAG = "!ERROR!";
|
||||||
|
@ -440,11 +439,8 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (final Exception exception) {
|
} catch (final Exception exception) {
|
||||||
// only dump once per second
|
|
||||||
final long currentTime_ms = System.currentTimeMillis();
|
|
||||||
if ( WarpDriveConfig.LOGGING_LUA
|
if ( WarpDriveConfig.LOGGING_LUA
|
||||||
|| lastLUAinternalException_ms + 1000L < currentTime_ms ) {
|
|| Commons.throttleMe("LUA exception") ) {
|
||||||
lastLUAinternalException_ms = currentTime_ms;
|
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -217,6 +217,7 @@ public class WarpDriveConfig {
|
||||||
public static EnumTooltipCondition TOOLTIP_ADD_REPAIR_WITH = EnumTooltipCondition.ON_SNEAK;
|
public static EnumTooltipCondition TOOLTIP_ADD_REPAIR_WITH = EnumTooltipCondition.ON_SNEAK;
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
public static long LOGGING_THROTTLE_MS = 5000L;
|
||||||
public static boolean LOGGING_JUMP = true;
|
public static boolean LOGGING_JUMP = true;
|
||||||
public static boolean LOGGING_JUMPBLOCKS = false;
|
public static boolean LOGGING_JUMPBLOCKS = false;
|
||||||
public static boolean LOGGING_ENERGY = false;
|
public static boolean LOGGING_ENERGY = false;
|
||||||
|
@ -861,6 +862,8 @@ public class WarpDriveConfig {
|
||||||
|
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
LOGGING_THROTTLE_MS = Commons.clamp(0L, 600000L,
|
||||||
|
config.get("logging", "throttle_ms", LOGGING_THROTTLE_MS, "How many milliseconds to we wait between before logging another occurrence in time sensitive section of the mod (rendering, events, etc.)").getLong(LOGGING_THROTTLE_MS));
|
||||||
LOGGING_JUMP = config.get("logging", "enable_jump_logs", LOGGING_JUMP, "Basic jump logs, should always be enabled").getBoolean(true);
|
LOGGING_JUMP = config.get("logging", "enable_jump_logs", LOGGING_JUMP, "Basic jump logs, should always be enabled").getBoolean(true);
|
||||||
LOGGING_JUMPBLOCKS = config.get("logging", "enable_jumpblocks_logs", LOGGING_JUMPBLOCKS, "Detailed jump logs to help debug the mod, will spam your logs...").getBoolean(false);
|
LOGGING_JUMPBLOCKS = config.get("logging", "enable_jumpblocks_logs", LOGGING_JUMPBLOCKS, "Detailed jump logs to help debug the mod, will spam your logs...").getBoolean(false);
|
||||||
LOGGING_ENERGY = config.get("logging", "enable_energy_logs", LOGGING_ENERGY, "Detailed energy logs to help debug the mod, enable it before reporting a bug").getBoolean(false);
|
LOGGING_ENERGY = config.get("logging", "enable_energy_logs", LOGGING_ENERGY, "Detailed energy logs to help debug the mod, enable it before reporting a bug").getBoolean(false);
|
||||||
|
|
|
@ -239,7 +239,7 @@ public class ChunkHandler {
|
||||||
if (chunkData != null) {
|
if (chunkData != null) {
|
||||||
chunkData.onBlockUpdated(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
chunkData.onBlockUpdated(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||||
} else {
|
} else {
|
||||||
if (WarpDriveConfig.LOGGING_WORLD_GENERATION) {
|
if (Commons.throttleMe("ChunkHandler block updating in non-loaded chunk")) {
|
||||||
WarpDrive.logger.error(String.format("%s block updating %s, while chunk isn't loaded!",
|
WarpDrive.logger.error(String.format("%s block updating %s, while chunk isn't loaded!",
|
||||||
world.isRemote ? "Client" : "Server",
|
world.isRemote ? "Client" : "Server",
|
||||||
Commons.format(world, blockPos)));
|
Commons.format(world, blockPos)));
|
||||||
|
@ -256,11 +256,13 @@ public class ChunkHandler {
|
||||||
public static ChunkData getChunkData(final World world, final int x, final int y, final int z) {
|
public static ChunkData getChunkData(final World world, final int x, final int y, final int z) {
|
||||||
final ChunkData chunkData = getChunkData(world.isRemote, world.provider.getDimension(), x, y, z);
|
final ChunkData chunkData = getChunkData(world.isRemote, world.provider.getDimension(), x, y, z);
|
||||||
if (chunkData == null) {
|
if (chunkData == null) {
|
||||||
WarpDrive.logger.error(String.format("Trying to get data from an non-loaded chunk in %s %s",
|
if (Commons.throttleMe("ChunkHandler get data from an non-loaded chunk")) {
|
||||||
world.isRemote ? "Client" : "Server",
|
WarpDrive.logger.error(String.format("Trying to get data from an non-loaded chunk in %s %s",
|
||||||
Commons.format(world, x, y, z)));
|
world.isRemote ? "Client" : "Server",
|
||||||
LocalProfiler.printCallStats();
|
Commons.format(world, x, y, z)));
|
||||||
Commons.dumpAllThreads();
|
LocalProfiler.printCallStats();
|
||||||
|
Commons.dumpAllThreads();
|
||||||
|
}
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
return chunkData;
|
return chunkData;
|
||||||
|
@ -310,7 +312,7 @@ public class ChunkHandler {
|
||||||
}
|
}
|
||||||
if (Commons.isSafeThread()) {
|
if (Commons.isSafeThread()) {
|
||||||
mapRegistryItems.put(index, chunkData);
|
mapRegistryItems.put(index, chunkData);
|
||||||
} else {
|
} else if (Commons.throttleMe("ChunkHandler added to the registry outside main thread")) {
|
||||||
WarpDrive.logger.error(String.format("%s world DIM%d chunk %s is being added to the registry outside main thread!",
|
WarpDrive.logger.error(String.format("%s world DIM%d chunk %s is being added to the registry outside main thread!",
|
||||||
isRemote ? "Client" : "Server",
|
isRemote ? "Client" : "Server",
|
||||||
dimensionId,
|
dimensionId,
|
||||||
|
|
|
@ -29,7 +29,6 @@ import icbm.classic.lib.emp.CapabilityEMP;
|
||||||
public class EMPReceiver implements IEMPReceiver, ICapabilityProvider {
|
public class EMPReceiver implements IEMPReceiver, ICapabilityProvider {
|
||||||
|
|
||||||
public static final ResourceLocation resourceLocation = new ResourceLocation(WarpDrive.MODID, "EMPReceiver");
|
public static final ResourceLocation resourceLocation = new ResourceLocation(WarpDrive.MODID, "EMPReceiver");
|
||||||
private static boolean isInvalidEMPReported = false;
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@Optional.Method(modid = "icbmclassic")
|
@Optional.Method(modid = "icbmclassic")
|
||||||
|
@ -67,8 +66,7 @@ public class EMPReceiver implements IEMPReceiver, ICapabilityProvider {
|
||||||
} else if (blastEMP.getBlastRadius() == 50.0F) {
|
} else if (blastEMP.getBlastRadius() == 50.0F) {
|
||||||
tileEntityAbstractBase.onEMP(0.70F);
|
tileEntityAbstractBase.onEMP(0.70F);
|
||||||
} else {
|
} else {
|
||||||
if (!isInvalidEMPReported) {
|
if (Commons.throttleMe("EMPReceiver Invalid radius")) {
|
||||||
isInvalidEMPReported = true;
|
|
||||||
WarpDrive.logger.warn(String.format("EMP received @ %s from %s with source %s and unsupported radius %.1f",
|
WarpDrive.logger.warn(String.format("EMP received @ %s from %s with source %s and unsupported radius %.1f",
|
||||||
Commons.format(world, x, y, z),
|
Commons.format(world, x, y, z),
|
||||||
blastEMP, blastEMP.getBlastSource(), blastEMP.getBlastRadius()));
|
blastEMP, blastEMP.getBlastSource(), blastEMP.getBlastRadius()));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package cr0s.warpdrive.render;
|
package cr0s.warpdrive.render;
|
||||||
|
|
||||||
|
import cr0s.warpdrive.Commons;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.block.energy.BlockCapacitor;
|
import cr0s.warpdrive.block.energy.BlockCapacitor;
|
||||||
import cr0s.warpdrive.data.EnumDisabledInputOutput;
|
import cr0s.warpdrive.data.EnumDisabledInputOutput;
|
||||||
|
@ -22,8 +23,6 @@ public class BakedModelCapacitor extends BakedModelAbstractBase {
|
||||||
|
|
||||||
private IExtendedBlockState extendedBlockStateDefault;
|
private IExtendedBlockState extendedBlockStateDefault;
|
||||||
|
|
||||||
private long timeLastError = -1L;
|
|
||||||
|
|
||||||
public BakedModelCapacitor() {
|
public BakedModelCapacitor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +57,7 @@ public class BakedModelCapacitor extends BakedModelAbstractBase {
|
||||||
if (extendedBlockState != null) {
|
if (extendedBlockState != null) {
|
||||||
final EnumDisabledInputOutput enumDisabledInputOutput = getEnumDisabledInputOutput(extendedBlockState, enumFacing);
|
final EnumDisabledInputOutput enumDisabledInputOutput = getEnumDisabledInputOutput(extendedBlockState, enumFacing);
|
||||||
if (enumDisabledInputOutput == null) {
|
if (enumDisabledInputOutput == null) {
|
||||||
final long time = System.currentTimeMillis();
|
if (Commons.throttleMe("BakedModelCapacitor invalid extended")) {
|
||||||
if (time - timeLastError > 5000L) {
|
|
||||||
timeLastError = time;
|
|
||||||
new RuntimeException("Invalid extended property").printStackTrace();
|
new RuntimeException("Invalid extended property").printStackTrace();
|
||||||
WarpDrive.logger.error(String.format("%s Invalid extended property for %s enumFacing %s\n%s",
|
WarpDrive.logger.error(String.format("%s Invalid extended property for %s enumFacing %s\n%s",
|
||||||
this, extendedBlockState, enumFacing, formatDetails()));
|
this, extendedBlockState, enumFacing, formatDetails()));
|
||||||
|
|
|
@ -2,6 +2,8 @@ package cr0s.warpdrive.render;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import cr0s.warpdrive.Commons;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.block.forcefield.BlockForceFieldProjector;
|
import cr0s.warpdrive.block.forcefield.BlockForceFieldProjector;
|
||||||
import cr0s.warpdrive.data.EnumForceFieldShape;
|
import cr0s.warpdrive.data.EnumForceFieldShape;
|
||||||
|
@ -102,9 +104,7 @@ public enum CustomModelLoaderProjector implements ICustomModelLoader {
|
||||||
class MyBakedModel implements IBakedModel {
|
class MyBakedModel implements IBakedModel {
|
||||||
|
|
||||||
private final IBakedModel bakedModel;
|
private final IBakedModel bakedModel;
|
||||||
|
|
||||||
private long timeLastError = -1L;
|
|
||||||
|
|
||||||
MyBakedModel(final IBakedModel bakedModel) {
|
MyBakedModel(final IBakedModel bakedModel) {
|
||||||
this.bakedModel = bakedModel;
|
this.bakedModel = bakedModel;
|
||||||
initSprites();
|
initSprites();
|
||||||
|
@ -117,9 +117,7 @@ public enum CustomModelLoaderProjector implements ICustomModelLoader {
|
||||||
final IExtendedBlockState exState = (IExtendedBlockState) blockState;
|
final IExtendedBlockState exState = (IExtendedBlockState) blockState;
|
||||||
EnumForceFieldShape enumForceFieldShape = exState != null ? exState.getValue(BlockForceFieldProjector.SHAPE) : EnumForceFieldShape.NONE;
|
EnumForceFieldShape enumForceFieldShape = exState != null ? exState.getValue(BlockForceFieldProjector.SHAPE) : EnumForceFieldShape.NONE;
|
||||||
if (enumForceFieldShape == null) {
|
if (enumForceFieldShape == null) {
|
||||||
final long time = System.currentTimeMillis();
|
if (Commons.throttleMe("CustomModelLoaderProjector Invalid shape")) {
|
||||||
if (time - timeLastError > 5000L) {
|
|
||||||
timeLastError = time;
|
|
||||||
new RuntimeException("Invalid shape").printStackTrace();
|
new RuntimeException("Invalid shape").printStackTrace();
|
||||||
WarpDrive.logger.error(String.format("Invalid shape for %s facing %s",
|
WarpDrive.logger.error(String.format("Invalid shape for %s facing %s",
|
||||||
blockState, enumFacing));
|
blockState, enumFacing));
|
||||||
|
|
Loading…
Reference in a new issue