From 5ce2ef3c8be15b7616f9224b66829837d06932e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Fri, 8 Dec 2023 13:27:44 +0100 Subject: [PATCH] log stats on wgpu_room --- examples/wgpu_room/src/app.rs | 4 ++-- examples/wgpu_room/src/service.rs | 27 ++++++++++++++++++++++++++ livekit/src/room/track/local_track.rs | 7 +++++++ livekit/src/room/track/remote_track.rs | 7 +++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/examples/wgpu_room/src/app.rs b/examples/wgpu_room/src/app.rs index 7191d4a86..159614861 100644 --- a/examples/wgpu_room/src/app.rs +++ b/examples/wgpu_room/src/app.rs @@ -162,8 +162,8 @@ impl LkApp { }); ui.menu_button("Debug", |ui| { - if ui.button("Refresh stats").clicked() { - // TODO + if ui.button("Log stats").clicked() { + let _ = self.service.send(AsyncCmd::LogStats); } }); }); diff --git a/examples/wgpu_room/src/service.rs b/examples/wgpu_room/src/service.rs index e7bd6dfef..1d1d3653c 100644 --- a/examples/wgpu_room/src/service.rs +++ b/examples/wgpu_room/src/service.rs @@ -33,6 +33,7 @@ pub enum AsyncCmd { publication: RemoteTrackPublication, }, E2eeKeyRatchet, + LogStats, } #[derive(Debug)] @@ -199,6 +200,32 @@ async fn service_task(inner: Arc, mut cmd_rx: mpsc::UnboundedRecei } } } + AsyncCmd::LogStats => { + if let Some(state) = running_state.as_ref() { + for (_, publication) in state.room.local_participant().tracks() { + if let Some(track) = publication.track() { + log::info!( + "track stats: LOCAL {:?} {:?}", + track.sid(), + track.get_stats().await, + ); + } + } + + for (_, participant) in state.room.participants() { + for (_, publication) in participant.tracks() { + if let Some(track) = publication.track() { + log::info!( + "track stats: {:?} {:?} {:?}", + participant.identity(), + track.sid(), + track.get_stats().await, + ); + } + } + } + } + } } } } diff --git a/livekit/src/room/track/local_track.rs b/livekit/src/room/track/local_track.rs index 1fed93559..79c85d301 100644 --- a/livekit/src/room/track/local_track.rs +++ b/livekit/src/room/track/local_track.rs @@ -42,6 +42,13 @@ impl LocalTrack { Self::Video(track) => track.rtc_track().into(), } } + + pub async fn get_stats(&self) -> RoomResult> { + match self { + Self::Audio(track) => track.get_stats().await, + Self::Video(track) => track.get_stats().await, + } + } } impl From for Track { diff --git a/livekit/src/room/track/remote_track.rs b/livekit/src/room/track/remote_track.rs index 62fb3955f..75fd877e6 100644 --- a/livekit/src/room/track/remote_track.rs +++ b/livekit/src/room/track/remote_track.rs @@ -37,6 +37,13 @@ impl RemoteTrack { Self::Video(track) => track.rtc_track().into(), } } + + pub async fn get_stats(&self) -> RoomResult> { + match self { + Self::Audio(track) => track.get_stats().await, + Self::Video(track) => track.get_stats().await, + } + } } pub(super) async fn get_stats(inner: &Arc) -> RoomResult> {