Add tracing for unflushed EditSessions

This commit is contained in:
Kenzie Togami
2018-10-30 18:39:51 -07:00
parent 93de97dc19
commit e1fbaaff59
11 changed files with 81 additions and 3 deletions

View File

@ -234,6 +234,16 @@ public class EditSession implements Extent, AutoCloseable {
return event.getExtent();
}
// pkg private for TracedEditSession only
ChunkBatchingExtent getChunkBatchingExtent() {
return chunkBatchingExtent;
}
MultiStageReorder getReorderExtent() {
return reorderExtent;
}
/**
* Turns on specific features for a normal WorldEdit session, such as
* {@link #enableQueue() queuing} and {@link #setBatchingChunks(boolean)

View File

@ -152,21 +152,24 @@ public class EditSessionFactory {
@Override
public EditSession getEditSession(World world, int maxBlocks) {
return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, null, maxBlocks, null));
return getEditSession(world, maxBlocks, null, null);
}
@Override
public EditSession getEditSession(World world, int maxBlocks, Player player) {
return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, player, maxBlocks, null));
return getEditSession(world, maxBlocks, null, player);
}
@Override
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag) {
return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null));
return getEditSession(world, maxBlocks, blockBag, null);
}
@Override
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag, Player player) {
if (WorldEdit.getInstance().getConfiguration().traceUnflushedSessions) {
return new TracedEditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, player, maxBlocks, null));
}
return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, player, maxBlocks, null));
}

View File

@ -100,6 +100,7 @@ public abstract class LocalConfiguration {
};
public boolean profile = false;
public boolean traceUnflushedSessions = false;
public Set<String> disallowedBlocks = new HashSet<>();
public int defaultChangeLimit = -1;
public int maxChangeLimit = -1;

View File

@ -0,0 +1,49 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.world.World;
import java.util.logging.Level;
public class TracedEditSession extends EditSession {
TracedEditSession(EventBus eventBus, World world, int maxBlocks, BlockBag blockBag, EditSessionEvent event) {
super(eventBus, world, maxBlocks, blockBag, event);
}
private final Throwable stacktrace = new Throwable("Creation trace.");
@Override
protected void finalize() throws Throwable {
if (!isQueueEnabled() && !isBatchingChunks()) {
return;
}
if (getChunkBatchingExtent().commitRequired() || getReorderExtent().commitRequired()) {
WorldEdit.logger.warning("####### LEFTOVER BUFFER BLOCKS DETECTED #######");
WorldEdit.logger.warning("This means that some code did not flush their EditSession.");
WorldEdit.logger.log(Level.WARNING, "Here is a stacktrace from the creation of this EditSession:", stacktrace);
}
}
}

View File

@ -73,6 +73,10 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
this.enabled = enabled;
}
public boolean commitRequired() {
return batches.size() > 0;
}
@Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
if (!enabled) {

View File

@ -94,6 +94,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
this.enabled = enabled;
}
public boolean commitRequired() {
return stage1.size() > 0 || stage2.size() > 0 || stage3.size() > 0;
}
@Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
BlockState existing = getBlock(location);

View File

@ -75,6 +75,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
loadExtra();
profile = getBool("profile", profile);
traceUnflushedSessions = getBool("traceUnflushedSessions", traceUnflushedSessions);
disallowedBlocks = getStringSet("disallowed-blocks", defaultDisallowedBlocks);
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);

View File

@ -54,6 +54,7 @@ public class YAMLConfiguration extends LocalConfiguration {
}
profile = config.getBoolean("debug", profile);
traceUnflushedSessions = config.getBoolean("debugging.trace-unflushed-sessions", traceUnflushedSessions);
wandItem = convertLegacyItem(config.getString("wand-item", wandItem));
defaultChangeLimit = Math.max(-1, config.getInt(