From 6ba512efc8e23b5bb1c67963381e8669198bf145 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Sat, 26 Jun 2021 20:10:58 -0400 Subject: [PATCH 1/2] Add some tracy plots about network usage to the client. --- client/Cargo.toml | 1 + client/src/lib.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- voxygen/Cargo.toml | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 7e3877a9e8..c43090cecc 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" simd = ["vek/platform_intrinsics"] plugins = ["common-state/plugins"] bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "common-frontend", "async-channel"] +tracy = ["common-base/tracy"] default = ["simd"] diff --git a/client/src/lib.rs b/client/src/lib.rs index 66fb721872..32ef2f25bc 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -74,6 +74,16 @@ use tokio::runtime::Runtime; use tracing::{debug, error, trace, warn}; 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; #[derive(Debug)] @@ -782,6 +792,8 @@ impl Client { ClientMsg::Type(msg) => self.register_stream.send(msg), ClientMsg::Register(msg) => self.register_stream.send(msg), ClientMsg::General(msg) => { + #[cfg(feature = "tracy")] + let (mut ingame, mut terrain) = (0.0, 0.0); let stream = match msg { ClientGeneral::RequestCharacterList | ClientGeneral::CreateCharacter { .. } @@ -803,15 +815,30 @@ impl Client { | ClientGeneral::UnlockSkillGroup(_) | ClientGeneral::RequestPlayerPhysics { .. } | ClientGeneral::RequestLossyTerrainCompression { .. } => { + #[cfg(feature = "tracy")] + { + ingame = 1.0; + } &mut self.in_game_stream }, //Only in game, terrain - ClientGeneral::TerrainChunkRequest { .. } => &mut self.terrain_stream, + ClientGeneral::TerrainChunkRequest { .. } => { + #[cfg(feature = "tracy")] + { + terrain = 1.0; + } + &mut self.terrain_stream + }, //Always possible ClientGeneral::ChatMsg(_) | ClientGeneral::Command(_, _) | ClientGeneral::Terminate => &mut self.general_stream, }; + #[cfg(feature = "tracy")] + { + INGAME_SENDS.point(ingame); + TERRAIN_SENDS.point(terrain); + } 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) -> Result { let mut cnt = 0; + #[cfg(feature = "tracy")] + let (mut terrain_cnt, mut ingame_cnt) = (0, 0); loop { let cnt_start = cnt; @@ -2084,14 +2113,27 @@ impl Client { } while let Some(msg) = self.in_game_stream.try_recv()? { cnt += 1; + #[cfg(feature = "tracy")] + { + ingame_cnt += 1; + } self.handle_server_in_game_msg(frontend_events, msg)?; } while let Some(msg) = self.terrain_stream.try_recv()? { cnt += 1; + #[cfg(feature = "tracy")] + { + terrain_cnt += 1; + } self.handle_server_terrain_msg(msg)?; } if cnt_start == cnt { + #[cfg(feature = "tracy")] + { + TERRAIN_RECVS.point(terrain_cnt as f64); + INGAME_RECVS.point(ingame_cnt as f64); + } return Ok(cnt); } } diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 30e7e380bf..6de4bde135 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -25,7 +25,7 @@ buildInputs = ["xorg.libxcb"] hot-anim = ["anim/use-dyn-lib"] singleplayer = ["server"] 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"] # We don't ship egui with published release builds so a separate feature is required that excludes it. From c2106e158f4ac207dbb9e49989ac10230705ff6a Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Sat, 26 Jun 2021 22:38:52 -0400 Subject: [PATCH 2/2] Use approximate byte count for the terrain recv graph. --- client/src/lib.rs | 4 +++- common/net/src/msg/compression.rs | 2 +- common/net/src/msg/server.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 32ef2f25bc..28efbf8e1e 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -2123,7 +2123,9 @@ impl Client { cnt += 1; #[cfg(feature = "tracy")] { - terrain_cnt += 1; + 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)?; } diff --git a/common/net/src/msg/compression.rs b/common/net/src/msg/compression.rs index 0fd0f89276..40ef66c8ab 100644 --- a/common/net/src/msg/compression.rs +++ b/common/net/src/msg/compression.rs @@ -756,7 +756,7 @@ pub fn write_image_terrain< pub struct WireChonk { zmin: i32, zmax: i32, - data: VIE::Output, + pub(crate) data: VIE::Output, below: Block, above: Block, meta: M, diff --git a/common/net/src/msg/server.rs b/common/net/src/msg/server.rs index 05450e4db9..f63527ce60 100644 --- a/common/net/src/msg/server.rs +++ b/common/net/src/msg/server.rs @@ -74,6 +74,14 @@ pub enum 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 { if lossy_compression && (chunk.get_max_z() - chunk.get_min_z() <= 128) { Self::quadpng(chunk)