package NET.worlds.core; import NET.worlds.console.Main; import NET.worlds.console.MainCallback; import NET.worlds.console.MainTerminalCallback; import java.io.PrintStream; public class SystemInfo implements MainCallback, MainTerminalCallback { private static SystemInfo instance = new SystemInfo(); private long _lastFrame = 0L; private long _lastReport = 0L; private long _min; private long _max; private long _avg; private long _avgCount = 0L; private SystemInfo() { Main.register(this); } @Override public void mainCallback() { long curTime = Std.getFastTime(); long frameTime = curTime - this._lastFrame; if (frameTime < this._min) { this._min = frameTime; } if (frameTime > this._max) { this._max = frameTime; } this._avg += frameTime; this._avgCount++; if (curTime - this._lastReport > 300000L) { if (this._lastFrame != 0L) { System.out.println(logTime() + "Frame rate report:" + this._min + "/" + this._avg / this._avgCount + "/" + this._max); } this._min = 10000L; this._max = 0L; this._avg = 0L; this._avgCount = 0L; this._lastReport = curTime; } this._lastFrame = curTime; } @Override public void terminalCallback() { Main.unregister(this); if (this._avgCount != 0L) { System.out.println(logTime() + "Frame rate report:" + this._min + "/" + this._avg / this._avgCount + "/" + this._max); } } public static void Record(PrintStream out) { out.println("DISK REPORT:"); recordPath(out, "Windows SYSTEM path", GetSystemDirectory()); recordPath(out, "Current Working Directory", GetCurrentDirectory()); out.println(""); out.println("JAVA MEMORY:"); out.println(logTime() + "\t Free memory: " + Runtime.getRuntime().freeMemory()); out.println(logTime() + "\tTotal memory: " + Runtime.getRuntime().totalMemory()); out.println(""); out.println("WINDOWS MEMORY:"); out.println(logTime() + "\tTotal Physical Memory: " + GetTotalPhysicalMemory()); out.println(logTime() + "\tAvail Physical Memory: " + GetAvailPhysicalMemory()); out.println(logTime() + "\t Total Paged Memory: " + GetTotalPagedMemory()); out.println(logTime() + "\t Avail Paged Memory: " + GetAvailPagedMemory()); out.println(""); out.println(logTime() + "Java Properties: " + System.getProperties()); out.println(logTime() + "Number of CPUs: " + GetNumberOfProcessors()); out.println(logTime() + "Processor Type: " + GetProcessorType()); out.println(logTime() + "Platform Type: " + GetPlatformID()); } private static void recordPath(PrintStream out, String comment, String path) { out.println(logTime() + comment + ": " + path); if (path != null) { String drive = path.substring(0, 2); out.println(logTime() + "\tFree disk space (" + drive + "): " + GetDiskFreeSpace(drive + "\\") + " KB"); } } public static String logTime() { return "[" + Std.getRealTime() + "] "; } public static native int GetDiskFreeSpace(String var0); public static int GetDiskFreeSpace() { return GetDiskFreeSpace(null); } public static native String GetSystemDirectory(); public static native String GetCurrentDirectory(); public static native int GetTotalPhysicalMemory(); public static native int GetAvailPhysicalMemory(); public static native int GetTotalPagedMemory(); public static native int GetAvailPagedMemory(); public static native String GetPlatformID(); public static native int GetNumberOfProcessors(); public static native String GetProcessorType(); }