Skip to content

Commit dbe3a58

Browse files
authored
Implement recipe map lookup time benchmarking command (#2880)
1 parent ff44d7f commit dbe3a58

File tree

6 files changed

+424
-0
lines changed

6 files changed

+424
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package gregtech.common.command.benchmark;
2+
3+
import gregtech.api.util.function.Task;
4+
5+
public interface BenchmarkTask extends Task {
6+
7+
void abort();
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package gregtech.common.command.benchmark;
2+
3+
import net.minecraft.command.ICommandSender;
4+
import net.minecraftforge.server.command.CommandTreeBase;
5+
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
public class CommandBenchmark extends CommandTreeBase {
10+
11+
static @Nullable BenchmarkTask ACTIVE_BENCHMARK = null;
12+
13+
public CommandBenchmark() {
14+
addSubcommand(new CommandBenchmarkLookup());
15+
addSubcommand(new CommandBenchmarkAbort());
16+
}
17+
18+
@Override
19+
public int getRequiredPermissionLevel() {
20+
return 3;
21+
}
22+
23+
@Override
24+
public @NotNull String getName() {
25+
return "benchmark";
26+
}
27+
28+
@Override
29+
public @NotNull String getUsage(@NotNull ICommandSender sender) {
30+
return "gregtech.command.benchmark.usage";
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package gregtech.common.command.benchmark;
2+
3+
import net.minecraft.command.CommandBase;
4+
import net.minecraft.command.CommandException;
5+
import net.minecraft.command.ICommandSender;
6+
import net.minecraft.server.MinecraftServer;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class CommandBenchmarkAbort extends CommandBase {
11+
12+
@Override
13+
public @NotNull String getName() {
14+
return "abort";
15+
}
16+
17+
@Override
18+
public @NotNull String getUsage(@NotNull ICommandSender sender) {
19+
return "gregtech.command.benchmark.abort.usage";
20+
}
21+
22+
@Override
23+
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender,
24+
String @NotNull [] args) throws CommandException {
25+
if (CommandBenchmark.ACTIVE_BENCHMARK != null) {
26+
CommandBenchmark.ACTIVE_BENCHMARK.abort();
27+
CommandBenchmark.ACTIVE_BENCHMARK = null;
28+
throw new CommandException("Currently running benchmark successfully aborted.");
29+
} else {
30+
throw new CommandException("No benchmark is currently running!");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)