JfrCommand.java
net.minecraft.server.commands.JfrCommand
信息
- 全限定名:net.minecraft.server.commands.JfrCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/JfrCommand.java
- 起始行号:L19
- 职责:
TODO
字段/常量
-
START_FAILED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
DUMP_FAILED- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private JfrCommand() @ L25
- 构造器名:JfrCommand
- 源码定位:L25
- 修饰符:private
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L28
- 方法名:register
- 源码定位:L28
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int startJfr(CommandSourceStack source) @ L37
- 方法名:startJfr
- 源码定位:L37
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
private static int stopJfr(CommandSourceStack source) @ L47
- 方法名:stopJfr
- 源码定位:L47
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
代码
public class JfrCommand {
private static final SimpleCommandExceptionType START_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.jfr.start.failed"));
private static final DynamicCommandExceptionType DUMP_FAILED = new DynamicCommandExceptionType(
message -> Component.translatableEscape("commands.jfr.dump.failed", message)
);
private JfrCommand() {
}
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("jfr")
.requires(Commands.hasPermission(Commands.LEVEL_OWNERS))
.then(Commands.literal("start").executes(c -> startJfr(c.getSource())))
.then(Commands.literal("stop").executes(c -> stopJfr(c.getSource())))
);
}
private static int startJfr(CommandSourceStack source) throws CommandSyntaxException {
Environment env = Environment.from(source.getServer());
if (!JvmProfiler.INSTANCE.start(env)) {
throw START_FAILED.create();
} else {
source.sendSuccess(() -> Component.translatable("commands.jfr.started"), false);
return 1;
}
}
private static int stopJfr(CommandSourceStack source) throws CommandSyntaxException {
try {
Path savedRecording = Paths.get(".").relativize(JvmProfiler.INSTANCE.stop().normalize());
Path clipboardPath = source.getServer().isPublished() && !SharedConstants.IS_RUNNING_IN_IDE ? savedRecording : savedRecording.toAbsolutePath();
Component fileText = Component.literal(savedRecording.toString())
.withStyle(ChatFormatting.UNDERLINE)
.withStyle(
style -> style.withClickEvent(new ClickEvent.CopyToClipboard(clipboardPath.toString()))
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.copy.click")))
);
source.sendSuccess(() -> Component.translatable("commands.jfr.stopped", fileText), false);
return 1;
} catch (Throwable var4) {
throw DUMP_FAILED.create(var4.getMessage());
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
ClickEvent.CopyToClipboard(), CopyToClipboard()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.literal(), Component.translatable(), Component.translatableEscape()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
HoverEvent.ShowText(), ShowText()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Environment.from()
- 引用位置: