41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//! Formatting of the periodic simulation statistics report.
|
|
|
|
use std::fmt::Write as _;
|
|
|
|
use shared::protocol::authority::ServerStats;
|
|
|
|
/// Renders one measurement window's diagnostics as a multi-line panel.
|
|
#[must_use]
|
|
pub fn format_panel(stats: &ServerStats) -> String {
|
|
let mut out = String::with_capacity(256);
|
|
|
|
// `write!` into a String cannot fail, so the results are discarded rather than propagated.
|
|
let _ = writeln!(out, "── server statistics ──");
|
|
let _ = writeln!(
|
|
out,
|
|
"tick {:.1} tps mean {:.2} ms max {:.2} ms budget {:.0}% uptime {} s",
|
|
stats.measured_tps,
|
|
stats.mean_tick_ms,
|
|
stats.max_tick_ms,
|
|
stats.tick_budget_percent,
|
|
stats.uptime_secs
|
|
);
|
|
let _ = write!(
|
|
out,
|
|
"world chunks {} resident / {} in flight clients {} entities {} players {}",
|
|
stats.loaded_chunks,
|
|
stats.chunks_in_flight,
|
|
stats.connected_clients,
|
|
stats.entities,
|
|
stats.players
|
|
);
|
|
|
|
out
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "tests/stats.rs"]
|
|
mod tests;
|