Command Profiler 是一个模组,允许你使用 /cmdprof 命令对命令(commands)和函数(functions)进行性能分析。
使用分析器
如果你拥有管理员权限(operator privileges),可以使用 /cmdprof enable 命令来启动分析器。要停止收集数据,请执行 /cmdprof disable;要重置当前已分析的数据,请执行 /cmdprof reset。
查看分析结果
有三种不同的格式用于获取数据:
- 在控制台中显示文本(以
print开头的子命令) - 保存为 JSON 格式(以
save开头的子命令) - 保存为字节流(与
save相同,但需要提供bytes作为参数)
这意味着你需要访问服务器控制台才能查看分析结果。
有 print 和 save 子命令可用于查看整个分析运行期间的总体结果。(print 按总耗时排序)
还有 print_trace 和 save_trace 子命令可用于查看最近一次捕获的 tick 内的分析结果。(按执行顺序排列)
注意:要使用这些命令查看追踪(trace)数据,你必须先启用 cmdprof:local/trace。而对于配置文件(profile)数据,你需要启用 cmdprof:local/profile,该选项默认处于启用状态。
配置分析器
你可以使用 /cmdprof config 子命令来配置分析器,目前有以下多个选项:
cmdprof:granularity- 设置为command时将对所有命令进行分析,设置为function时不会单独分析命令cmdprof:command/macro_templates- 设置为false时,带有宏的命令会将其参数内联到命令中cmdprof:function/line_numbers- 设置为true时,命令将包含其行号,而不是设为0cmdprof:local/profile,当设置为true时,/cmdprof print和/cmdprof save可用cmdprof:local/trace,当设置为true时,/cmdprof print_trace和/cmdprof save_trace可用cmdprof:memory_usage,当设置为true时,所有事件都会跟踪内存使用情况(这会显著降低性能,除非你正在尝试制作修复内存问题的模组,否则不建议使用)cmdprof:macro/instantiations,当设置为true时,分析结果会将实例化宏函数所花费的时间作为一个单独的步骤列出,而不是将其合并到执行实例化的命令中cmdprof:online/scoreboard- 当设置为true时,服务器将在启用时将记分板数据发送到在线数据页面。
在线查看数据
你可以使用 /cmdprof online view 打开在线分析器界面,并使用 /cmdprof online stop 停止它。注意,你需要先通过 /cmdprof enable 启用分析器,否则将无法提供数据。如果你想在线查看记分板数据,请执行 /cmdprof config cmdprof:online/scoreboard true。
当分析器运行时,数据会自动每秒刷新一次。记分板数据大约每个 tick 更新一次。
基准测试函数
使用 /cmdprof benchmark run <name>,你可以对一个函数或函数标签(function tag)进行基准测试。这可能需要一段时间,但在完成后,它会在聊天窗口中显示结果。你可以通过 /cmdprof benchmark cancel 取消当前正在运行的基准测试。成功的 /reload 操作会自动取消所有待处理的基准测试。被基准测试的函数是在服务器命令上下文中运行的,而不是由运行命令的玩家上下文运行。
此外,你还可以使用 /cmdprof benchmark command <command> 对单个命令进行基准测试。
注意:专门进行基准测试时,你不需要启用分析器,你可能应该执行 /cmdprof disable 以获得更准确的函数速度表现。但是,如果你希望转储(dump)结果等,可能仍希望保持分析器处于启用状态。
Command Profiler is a mod which lets you profile commands and functions using /cmdprof.
Using the profiler
You can start the profiler if you have operator privileges using the /cmdprof enable command. For the profiler to stop collecting data do /cmdprof disable, and to reset the current profiled data do /cmdprof reset.
Viewing profiler results
There are three different formats for taking the data
- display text in console (subcommands that start with
print) - save as JSON (subcommands that start with
save) - save as bytes (same as
saveexcept you need to providebytesas an argument)
This does mean that you need access to the server console to view the profiler results.
There are print and save subcommands for viewing the profiler results over the entire duration of the profiler running. (print is sorted by total time taken)
And there are print_trace and save_trace subcommands for viewing the profiler results over the last captured tick. (ordered by execution)
Note: To use these commands to view trace data, you have to enable cmdprof:local/trace first. Meanwhile for profile data, you have to enable cmdprof:local/profile which is enabled by default.
Configuring the profiler
You can configure the profiler using the /cmdprof config subcommand, there are currently several options:
cmdprof:granularity- when set tocommandall commands will be profiled, and when set tofunctioncommands will not be profiled individuallycmdprof:command/macro_templates- when set tofalse, commands which have macros will have their arguments inlined into the commandcmdprof:function/line_numbers- when set totrue, commands will include their line number, instead of being set to0cmdprof:local/profile, when set totrue,/cmdprof printand/cmdprof saveare usablecmdprof:local/trace, when set totrue,/cmdprof print_traceand/cmdprof save_traceare usablecmdprof:memory_usage, when set totrue, all events will track the memory usage (this reduces the performance by quite a bit, not worth using it unless you're trying to make a mod which fixes memory usage issues)cmdprof:macro/instantiations, when set totrue, profiler results will include how long it takes to instantiate a macro function as a separate step, instead of merging it with the command that executes the instantiationcmdprof:online/scoreboard- when set totrue, the server will send scoreboard data to the online data page when enabled.
Viewing data online
You can open the profiler online using /cmdprof online view, and stop it using /cmdprof online stop. Note that you need to enable the profiler using /cmdprof enable first, otherwise there will be no data provided. If you want to see scoreboard data online, do /cmdprof config cmdprof:online/scoreboard true.
The profiler automatically refreshes data every second when it is running. The scoreboard data gets updated approximately every tick.
Benchmarking functions
Using /cmdprof benchmark run <name>, you can benchmark a function or a function tag, it might take a while, but after it finishes, it will display the results in chat. You can cancel a currently running benchmark via /cmdprof benchmark cancel. A successful /reload automatically cancels all pending benchmarks. The benchmarked function(s) run in the server command context instead of whoever is running it.
Additionally, you benchmark a single command using /cmdprof benchmark command <command>.
Note: You don't need to have the profiler enabled for benchmarking specifically, you should probably do /cmdprof disable to have a more accurate representation of how fast a function could be. However you might still want to keep the profiler enabled, if you want to dump the results for example.
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Command Profiler
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
- 修复了在存在活跃 WebSocket 连接(但实际上)时退出游戏导致崩溃的问题
- 默认禁用
cmdprof:online/scoreboard选项 - 新增
cmdprof:local/trace和cmdprof:local/profile选项,以便更精细地控制分析器的内存使用
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
原版世界生成优化模组
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
缓冲的原始输入和线程化的事件轮询
评论 0
登录后参与评分
还没有评论,来抢沙发吧