Timings
Time a series of steps, like everything a reload command does, and send the result at the end:
@Command("atlas reload")
suspend fun reload(sender: CommandSender) {
val timing = Timing("Atlas reload")
withAsyncCtx {
timing.step("config") { AtlasConfig.reload() }
timing.step("punishments") { PunishmentConfig.reload() }
timing.step("shop") { SaintCoinsShopService.reload() }
timing.stepSuspend("tebex") { TebexService.refresh() }
}
sender.sendMessage(timing.summary())
}
That sends "Atlas reload took 132ms", and hovering it shows every step with its time, the slowest one highlighted.
- A step that throws doesn't stop the rest: it's reported as an incident and shows up as ✗ in red, and the summary says how many failed.
stepreturns the block's result (or null if it failed).timing.total,timing.stepsandtiming.failedare there if you want to build your own message.summaryText()andbreakdownText()give you the MiniMessage strings.
For things that run over and over (a database load, a packet handler), Timings.timed("db.loadPlayer") { ... } keeps running stats. The slowest ones show up in /mycommand debug, and /mycommand debug timings lists them all with average, max and count.