Merge branch 'aweinstock/networktracy' into 'master'

Add some tracy plots about network usage to the client.

See merge request veloren/veloren!2510
This commit is contained in:
Imbris 2021-07-03 05:44:30 +00:00
commit a9767c40d1
5 changed files with 56 additions and 3 deletions

View File

@ -8,6 +8,7 @@ edition = "2018"
simd = ["vek/platform_intrinsics"] simd = ["vek/platform_intrinsics"]
plugins = ["common-state/plugins"] plugins = ["common-state/plugins"]
bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "common-frontend", "async-channel"] bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "common-frontend", "async-channel"]
tracy = ["common-base/tracy"]
default = ["simd"] default = ["simd"]

View File

@ -74,6 +74,16 @@ use tokio::runtime::Runtime;
use tracing::{debug, error, trace, warn}; use tracing::{debug, error, trace, warn};
use vek::*; use vek::*;
#[cfg(feature = "tracy")]
mod tracy_plots {
use common_base::tracy_client::{create_plot, Plot};
pub static TERRAIN_SENDS: Plot = create_plot!("terrain_sends");
pub static TERRAIN_RECVS: Plot = create_plot!("terrain_recvs");
pub static INGAME_SENDS: Plot = create_plot!("ingame_sends");
pub static INGAME_RECVS: Plot = create_plot!("ingame_recvs");
}
#[cfg(feature = "tracy")] use tracy_plots::*;
const PING_ROLLING_AVERAGE_SECS: usize = 10; const PING_ROLLING_AVERAGE_SECS: usize = 10;
#[derive(Debug)] #[derive(Debug)]
@ -782,6 +792,8 @@ impl Client {
ClientMsg::Type(msg) => self.register_stream.send(msg), ClientMsg::Type(msg) => self.register_stream.send(msg),
ClientMsg::Register(msg) => self.register_stream.send(msg), ClientMsg::Register(msg) => self.register_stream.send(msg),
ClientMsg::General(msg) => { ClientMsg::General(msg) => {
#[cfg(feature = "tracy")]
let (mut ingame, mut terrain) = (0.0, 0.0);
let stream = match msg { let stream = match msg {
ClientGeneral::RequestCharacterList ClientGeneral::RequestCharacterList
| ClientGeneral::CreateCharacter { .. } | ClientGeneral::CreateCharacter { .. }
@ -803,15 +815,30 @@ impl Client {
| ClientGeneral::UnlockSkillGroup(_) | ClientGeneral::UnlockSkillGroup(_)
| ClientGeneral::RequestPlayerPhysics { .. } | ClientGeneral::RequestPlayerPhysics { .. }
| ClientGeneral::RequestLossyTerrainCompression { .. } => { | ClientGeneral::RequestLossyTerrainCompression { .. } => {
#[cfg(feature = "tracy")]
{
ingame = 1.0;
}
&mut self.in_game_stream &mut self.in_game_stream
}, },
//Only in game, terrain //Only in game, terrain
ClientGeneral::TerrainChunkRequest { .. } => &mut self.terrain_stream, ClientGeneral::TerrainChunkRequest { .. } => {
#[cfg(feature = "tracy")]
{
terrain = 1.0;
}
&mut self.terrain_stream
},
//Always possible //Always possible
ClientGeneral::ChatMsg(_) ClientGeneral::ChatMsg(_)
| ClientGeneral::Command(_, _) | ClientGeneral::Command(_, _)
| ClientGeneral::Terminate => &mut self.general_stream, | ClientGeneral::Terminate => &mut self.general_stream,
}; };
#[cfg(feature = "tracy")]
{
INGAME_SENDS.point(ingame);
TERRAIN_SENDS.point(terrain);
}
stream.send(msg) stream.send(msg)
}, },
ClientMsg::Ping(msg) => self.ping_stream.send(msg), ClientMsg::Ping(msg) => self.ping_stream.send(msg),
@ -2067,6 +2094,8 @@ impl Client {
fn handle_messages(&mut self, frontend_events: &mut Vec<Event>) -> Result<u64, Error> { fn handle_messages(&mut self, frontend_events: &mut Vec<Event>) -> Result<u64, Error> {
let mut cnt = 0; let mut cnt = 0;
#[cfg(feature = "tracy")]
let (mut terrain_cnt, mut ingame_cnt) = (0, 0);
loop { loop {
let cnt_start = cnt; let cnt_start = cnt;
@ -2084,14 +2113,29 @@ impl Client {
} }
while let Some(msg) = self.in_game_stream.try_recv()? { while let Some(msg) = self.in_game_stream.try_recv()? {
cnt += 1; cnt += 1;
#[cfg(feature = "tracy")]
{
ingame_cnt += 1;
}
self.handle_server_in_game_msg(frontend_events, msg)?; self.handle_server_in_game_msg(frontend_events, msg)?;
} }
while let Some(msg) = self.terrain_stream.try_recv()? { while let Some(msg) = self.terrain_stream.try_recv()? {
cnt += 1; cnt += 1;
#[cfg(feature = "tracy")]
{
if let ServerGeneral::TerrainChunkUpdate { chunk, .. } = &msg {
terrain_cnt += chunk.as_ref().map(|x| x.approx_len()).unwrap_or(0);
}
}
self.handle_server_terrain_msg(msg)?; self.handle_server_terrain_msg(msg)?;
} }
if cnt_start == cnt { if cnt_start == cnt {
#[cfg(feature = "tracy")]
{
TERRAIN_RECVS.point(terrain_cnt as f64);
INGAME_RECVS.point(ingame_cnt as f64);
}
return Ok(cnt); return Ok(cnt);
} }
} }

View File

@ -790,7 +790,7 @@ pub fn write_image_terrain<
pub struct WireChonk<VIE: VoxelImageEncoding, P: PackingFormula, M: Clone, S: RectVolSize> { pub struct WireChonk<VIE: VoxelImageEncoding, P: PackingFormula, M: Clone, S: RectVolSize> {
zmin: i32, zmin: i32,
zmax: i32, zmax: i32,
data: VIE::Output, pub(crate) data: VIE::Output,
below: Block, below: Block,
above: Block, above: Block,
meta: M, meta: M,

View File

@ -74,6 +74,14 @@ pub enum SerializedTerrainChunk {
} }
impl SerializedTerrainChunk { impl SerializedTerrainChunk {
pub fn approx_len(&self) -> usize {
match self {
SerializedTerrainChunk::DeflatedChonk(data) => data.data.len(),
SerializedTerrainChunk::QuadPng(data) => data.data.data.len(),
SerializedTerrainChunk::TriPng(data) => data.data.data.len(),
}
}
pub fn via_heuristic(chunk: &TerrainChunk, lossy_compression: bool) -> Self { pub fn via_heuristic(chunk: &TerrainChunk, lossy_compression: bool) -> Self {
if lossy_compression && (chunk.get_max_z() - chunk.get_min_z() <= 128) { if lossy_compression && (chunk.get_max_z() - chunk.get_min_z() <= 128) {
Self::quadpng(chunk) Self::quadpng(chunk)

View File

@ -25,7 +25,7 @@ buildInputs = ["xorg.libxcb"]
hot-anim = ["anim/use-dyn-lib"] hot-anim = ["anim/use-dyn-lib"]
singleplayer = ["server"] singleplayer = ["server"]
simd = ["vek/platform_intrinsics"] simd = ["vek/platform_intrinsics"]
tracy = ["profiling", "profiling/profile-with-tracy", "common-frontend/tracy"] tracy = ["profiling", "profiling/profile-with-tracy", "common-frontend/tracy", "client/tracy"]
plugins = ["client/plugins"] plugins = ["client/plugins"]
# We don't ship egui with published release builds so a separate feature is required that excludes it. # We don't ship egui with published release builds so a separate feature is required that excludes it.