diff --git a/src/main/ProjectSWG.java b/src/main/ProjectSWG.java index 20fbfa64e..db5496dee 100644 --- a/src/main/ProjectSWG.java +++ b/src/main/ProjectSWG.java @@ -137,16 +137,12 @@ public class ProjectSWG { List intentTimes = IntentManager.getInstance().getSpeedRecorder().getAllTimes(); Collections.sort(intentTimes); Log.i(" Intent Times: [%d]", intentTimes.size()); - Log.i(" %-30s%-40s%-10s%-20s%-10s", "Intent", "Receiver", "Count", "Time", "Priority"); + Log.i(" %-30s%-40s%-10s%s", "Intent", "Receiver", "Count", "Time"); for (IntentSpeedRecord record : intentTimes) { String receiverName = record.getConsumer().getClass().getName(); if (receiverName.indexOf('$') != -1) receiverName = receiverName.substring(0, receiverName.indexOf('$')); - String intentName = record.getIntent().getSimpleName(); - String recordCount = Long.toString(record.getCount()); - String recordTime = String.format("%.6fms", record.getTime() / 1E6); - String priority = Integer.toString(record.getPriority()); - Log.i(" %-30s%-40s%-10s%-20s%-10s", intentName, receiverName, recordCount, recordTime, priority); + Log.i(" %-30s%-40s%-10s%.6fms", record.getIntent().getSimpleName(), receiverName, Long.toString(record.getCount()), record.getTime() / 1E6); } } @@ -190,6 +186,37 @@ public class ProjectSWG { this.adminServerPort = safeParseInt(params.get("-adminServerPort"), -1); } + private int safeParseInt(String str, int def) { + if (str == null) + return def; + try { + return Integer.parseInt(str); + } catch (NumberFormatException e) { + return def; + } + } + + private Map getParameters(String [] args) { + Map params = new HashMap<>(); + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + String nextArg = (i+1 < args.length) ? args[i+1] : null; + if (arg.indexOf('=') != -1) { + String [] parts = arg.split("=", 2); + if (parts.length < 2) + params.put(parts[0], null); + else + params.put(parts[0], parts[1]); + } else if (arg.equalsIgnoreCase("-adminServerPort") && nextArg != null) { + params.put(arg, nextArg); + i++; + } else { + params.put(arg, null); + } + } + return params; + } + private void setStatus(ServerStatus status) { this.status = status; new ServerStatusIntent(status).broadcast(); @@ -210,10 +237,11 @@ public class ProjectSWG { } Log.e("Passed %d of %d unit tests in %.3fms - aborting start", passCount, runCount, testResult.getRunTime() / 1000.0); return false; + } else { + int runCount = testResult.getRunCount(); + Log.i("Passed %d of %d unit tests in %.3fms", runCount, runCount, testResult.getRunTime() / 1000.0); + return true; } - int runCount = testResult.getRunCount(); - Log.i("Passed %d of %d unit tests in %.3fms", runCount, runCount, testResult.getRunTime() / 1000.0); - return true; } private void create() { @@ -230,7 +258,6 @@ public class ProjectSWG { throw new CoreException("Failed to initialize."); Log.i("Initialized. Time: %.3fms", manager.getCoreTime()); initStatus = ServerInitStatus.INITIALIZED; - cleanupMemory(); } private void start() { @@ -243,22 +270,9 @@ public class ProjectSWG { private void loop() { setStatus((manager.getGalaxyStatus() == GalaxyStatus.UP) ? ServerStatus.OPEN : ServerStatus.LOCKED); - - boolean initialIntentsCompleted = false; - long loop = 0; while (!shutdownRequested && !manager.isShutdownRequested() && manager.isOperational()) { - if (!initialIntentsCompleted && IntentManager.getInstance().getIntentCount() == 0) { - Log.i("Intent queue empty."); - initialIntentsCompleted = true; -// throw new CoreException("Intent queue empty"); - } - - if (loop % 12000 == 0) {// Approx every 10 mins, do a memory clean-up - cleanupMemory(); - } if (Delay.sleepMilli(50)) throw new CoreException("Main Thread Interrupted"); - loop++; } } @@ -296,46 +310,6 @@ public class ProjectSWG { TERMINATED } - private static void cleanupMemory() { - Runtime rt = Runtime.getRuntime(); - long total = rt.totalMemory(); - long usedBefore = total - rt.freeMemory(); - System.gc(); - long usedAfter = total - rt.freeMemory(); - Log.d("Memory cleanup. Total: %.1fGB Before: %.2f%% After: %.2f%%", total/1073741824.0, usedBefore/1073741824.0*100, usedAfter/1073741824.0*100); - } - - private static Map getParameters(String [] args) { - Map params = new HashMap<>(); - for (int i = 0; i < args.length; i++) { - String arg = args[i]; - String nextArg = (i+1 < args.length) ? args[i+1] : null; - if (arg.indexOf('=') != -1) { - String [] parts = arg.split("=", 2); - if (parts.length < 2) - params.put(parts[0], null); - else - params.put(parts[0], parts[1]); - } else if (arg.equalsIgnoreCase("-adminServerPort") && nextArg != null) { - params.put(arg, nextArg); - i++; - } else { - params.put(arg, null); - } - } - return params; - } - - private static int safeParseInt(String str, int def) { - if (str == null) - return def; - try { - return Integer.parseInt(str); - } catch (NumberFormatException e) { - return def; - } - } - public static class CoreException extends RuntimeException { private static final long serialVersionUID = 455306876887818064L;