/net/minecraft/server/CommandDebug.java
https://bitbucket.org/agaricusb/mc-dev · Java · 130 lines · 105 code · 25 blank · 0 comment · 12 complexity · c62b3852b1a67487941abcc39a3cf060 MD5 · raw file
- package net.minecraft.server;
- import java.io.File;
- import java.io.FileWriter;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class CommandDebug extends CommandAbstract {
- private long a = 0L;
- private int b = 0;
- public CommandDebug() {}
- public String c() {
- return "debug";
- }
- public int a() {
- return 3;
- }
- public void b(ICommandListener icommandlistener, String[] astring) {
- if (astring.length == 1) {
- if (astring[0].equals("start")) {
- a(icommandlistener, "commands.debug.start", new Object[0]);
- MinecraftServer.getServer().ai();
- this.a = System.currentTimeMillis();
- this.b = MinecraftServer.getServer().ah();
- return;
- }
- if (astring[0].equals("stop")) {
- if (!MinecraftServer.getServer().methodProfiler.a) {
- throw new CommandException("commands.debug.notStarted", new Object[0]);
- }
- long i = System.currentTimeMillis();
- int j = MinecraftServer.getServer().ah();
- long k = i - this.a;
- int l = j - this.b;
- this.a(k, l);
- MinecraftServer.getServer().methodProfiler.a = false;
- a(icommandlistener, "commands.debug.stop", new Object[] { Float.valueOf((float) k / 1000.0F), Integer.valueOf(l)});
- return;
- }
- }
- throw new ExceptionUsage("commands.debug.usage", new Object[0]);
- }
- private void a(long i, int j) {
- File file1 = new File(MinecraftServer.getServer().e("debug"), "profile-results-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + ".txt");
- file1.getParentFile().mkdirs();
- try {
- FileWriter filewriter = new FileWriter(file1);
- filewriter.write(this.b(i, j));
- filewriter.close();
- } catch (Throwable throwable) {
- Logger.getLogger("Minecraft").log(Level.SEVERE, "Could not save profiler results to " + file1, throwable);
- }
- }
- private String b(long i, int j) {
- StringBuilder stringbuilder = new StringBuilder();
- stringbuilder.append("---- Minecraft Profiler Results ----\n");
- stringbuilder.append("// ");
- stringbuilder.append(d());
- stringbuilder.append("\n\n");
- stringbuilder.append("Time span: ").append(i).append(" ms\n");
- stringbuilder.append("Tick span: ").append(j).append(" ticks\n");
- stringbuilder.append("// This is approximately ").append(String.format("%.2f", new Object[] { Float.valueOf((float) j / ((float) i / 1000.0F))})).append(" ticks per second. It should be ").append(20).append(" ticks per second\n\n");
- stringbuilder.append("--- BEGIN PROFILE DUMP ---\n\n");
- this.a(0, "root", stringbuilder);
- stringbuilder.append("--- END PROFILE DUMP ---\n\n");
- return stringbuilder.toString();
- }
- private void a(int i, String s, StringBuilder stringbuilder) {
- List list = MinecraftServer.getServer().methodProfiler.b(s);
- if (list != null && list.size() >= 3) {
- for (int j = 1; j < list.size(); ++j) {
- ProfilerInfo profilerinfo = (ProfilerInfo) list.get(j);
- stringbuilder.append(String.format("[%02d] ", new Object[] { Integer.valueOf(i)}));
- for (int k = 0; k < i; ++k) {
- stringbuilder.append(" ");
- }
- stringbuilder.append(profilerinfo.c);
- stringbuilder.append(" - ");
- stringbuilder.append(String.format("%.2f", new Object[] { Double.valueOf(profilerinfo.a)}));
- stringbuilder.append("%/");
- stringbuilder.append(String.format("%.2f", new Object[] { Double.valueOf(profilerinfo.b)}));
- stringbuilder.append("%\n");
- if (!profilerinfo.c.equals("unspecified")) {
- try {
- this.a(i + 1, s + "." + profilerinfo.c, stringbuilder);
- } catch (Exception exception) {
- stringbuilder.append("[[ EXCEPTION " + exception + " ]]");
- }
- }
- }
- }
- }
- private static String d() {
- String[] astring = new String[] { "Shiny numbers!", "Am I not running fast enough? :(", "I\'m working as hard as I can!", "Will I ever be good enough for you? :(", "Speedy. Zoooooom!", "Hello world", "40% better than a crash report.", "Now with extra numbers", "Now with less numbers", "Now with the same numbers", "You should add flames to things, it makes them go faster!", "Do you feel the need for... optimization?", "*cracks redstone whip*", "Maybe if you treated it better then it\'ll have more motivation to work faster! Poor server."};
- try {
- return astring[(int) (System.nanoTime() % (long) astring.length)];
- } catch (Throwable throwable) {
- return "Witty comment unavailable :(";
- }
- }
- public List a(ICommandListener icommandlistener, String[] astring) {
- return astring.length == 1 ? a(astring, new String[] { "start", "stop"}) : null;
- }
- }