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 static final com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) java.lang.management.ManagementFactory.getOperatingSystemMXBean(); 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 int GetDiskFreeSpace(String var0) { try { java.io.File file = (var0 != null) ? new java.io.File(var0) : new java.io.File("."); return (int)(file.getFreeSpace() / 1024L); } catch (Exception e) { return 0; } } public static int GetDiskFreeSpace() { return GetDiskFreeSpace(null); } public static String GetSystemDirectory() { return System.getProperty("java.home", ""); } public static String GetCurrentDirectory() { return System.getProperty("user.dir", ""); } public static int GetTotalPhysicalMemory() { return (int)(operatingSystemMXBean.getTotalPhysicalMemorySize() / 1024L); } public static int GetAvailPhysicalMemory() { return (int)(operatingSystemMXBean.getFreePhysicalMemorySize() / 1024L); } public static int GetTotalPagedMemory() { return (int)(operatingSystemMXBean.getTotalSwapSpaceSize() / 1024L); } public static int GetAvailPagedMemory() { return (int)(operatingSystemMXBean.getFreeSwapSpaceSize() / 1024L); } public static String GetPlatformID() { return System.getProperty("os.name", "Unknown") + " " + System.getProperty("os.version", ""); } public static int GetNumberOfProcessors() { return Runtime.getRuntime().availableProcessors(); } public static String GetProcessorType() { return System.getProperty("os.arch", "Unknown"); } }