Added a debug configuration setting for timing and query information

This commit is contained in:
Ammar Askar
2015-03-20 22:46:01 +05:00
parent c3b9784efb
commit 51fdff20a7
3 changed files with 30 additions and 5 deletions

View File

@ -426,7 +426,7 @@ public class CommandsHandler implements CommandExecutor
return;
}
state = conn.createStatement();
rs = state.executeQuery(params.getQuery());
rs = executeQuery(state, params.getQuery());
sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":");
if (rs.next()) {
rs.beforeFirst();
@ -488,7 +488,7 @@ public class CommandsHandler implements CommandExecutor
state = conn.createStatement();
file = new File("plugins/LogBlock/log/" + params.getTitle().replace(":", ".") + ".log");
sender.sendMessage(ChatColor.GREEN + "Creating " + file.getName());
rs = state.executeQuery(params.getQuery());
rs = executeQuery(state, params.getQuery());
file.getParentFile().mkdirs();
file.createNewFile();
final FileWriter writer = new FileWriter(file);
@ -559,7 +559,7 @@ public class CommandsHandler implements CommandExecutor
return;
}
state = conn.createStatement();
rs = state.executeQuery(params.getQuery());
rs = executeQuery(state, params.getQuery());
if (rs.next()) {
final Player player = (Player)sender;
final int y = rs.getInt("y");
@ -614,7 +614,7 @@ public class CommandsHandler implements CommandExecutor
new CommandSaveQueue(sender, null, false);
if (!params.silent)
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
rs = state.executeQuery(params.getQuery());
rs = executeQuery(state, params.getQuery());
final WorldEditor editor = new WorldEditor(logblock, params.world);
while (rs.next())
@ -678,7 +678,7 @@ public class CommandsHandler implements CommandExecutor
state = conn.createStatement();
if (!checkRestrictions(sender, params))
return;
rs = state.executeQuery(params.getQuery());
rs = executeQuery(state, params.getQuery());
if (!params.silent)
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
final WorldEditor editor = new WorldEditor(logblock, params.world);
@ -778,6 +778,17 @@ public class CommandsHandler implements CommandExecutor
}
}
private static ResultSet executeQuery(Statement state, String query) throws SQLException {
if (Config.debug) {
long startTime = System.currentTimeMillis();
ResultSet rs = state.executeQuery(query);
getLogger().log(Level.INFO, "[LogBlock Debug] Time Taken: " + (System.currentTimeMillis() - startTime) + " milliseconds. Query: " + query );
return rs;
} else {
return state.executeQuery(query);
}
}
private static List<String> argsToList(String[] arr, int offset) {
final List<String> list = new ArrayList<String>(Arrays.asList(arr));
for (int i = 0; i < offset; i++)

View File

@ -284,6 +284,9 @@ public class Consumer extends TimerTask
public synchronized void run() {
if (queue.isEmpty() || !lock.tryLock())
return;
long startTime = System.currentTimeMillis();
int startSize = queue.size();
final Connection conn = logblock.getConnection();
Statement state = null;
if (Config.queueWarningSize > 0 && queue.size() >= Config.queueWarningSize) {
@ -365,6 +368,14 @@ public class Consumer extends TimerTask
getLogger().log(Level.SEVERE, "[Consumer] SQL exception on close", ex);
}
lock.unlock();
if (debug) {
long timeElapsed = System.currentTimeMillis() - startTime;
int rowsProcessed = startSize - queue.size();
float rowPerTime = rowsProcessed / timeElapsed;
getLogger().log(Level.INFO, "[Consumer] Finished consumer cycle in " + timeElapsed + " milliseconds.");
getLogger().log(Level.INFO, "[Consumer] Total rows processed: " + rowsProcessed + ". row/time: " + String.format("%.4f", rowPerTime));
}
}
}

View File

@ -46,6 +46,7 @@ public class Config
public static Set<String> ignoredChat;
public static SimpleDateFormat formatter;
public static boolean safetyIdCheck;
public static boolean debug;
public static boolean logEnvironmentalKills;
// Not loaded from config - checked at runtime
public static boolean mb4 = false;
@ -129,6 +130,7 @@ public class Config
def.put("tools.toolblock.mode", "LOOKUP");
def.put("tools.toolblock.permissionDefault", "OP");
def.put("safety.id.check", true);
def.put("debug", false);
for (final Entry<String, Object> e : def.entrySet())
if (!config.contains(e.getKey()))
config.set(e.getKey(), e.getValue());
@ -183,6 +185,7 @@ public class Config
askClearLogAfterRollback = config.getBoolean("questioner.askClearLogAfterRollback", true);
askRollbackAfterBan = config.getBoolean("questioner.askRollbackAfterBan", false);
safetyIdCheck = config.getBoolean("safety.id.check", true);
debug = config.getBoolean("debug", false);
banPermission = config.getString("questioner.banPermission");
final List<Tool> tools = new ArrayList<Tool>();
final ConfigurationSection toolsSec = config.getConfigurationSection("tools");