Compatibility
Minecraft: Java Edition
Platforms
Supported environments
Links
Tags
Creators
Details
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.


