Skip to content

Commit

Permalink
log stats on wgpu_room
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Dec 8, 2023
1 parent 8bb0ed6 commit 5ce2ef3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/wgpu_room/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand Down
27 changes: 27 additions & 0 deletions examples/wgpu_room/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum AsyncCmd {
publication: RemoteTrackPublication,
},
E2eeKeyRatchet,
LogStats,
}

#[derive(Debug)]
Expand Down Expand Up @@ -199,6 +200,32 @@ async fn service_task(inner: Arc<ServiceInner>, 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,
);
}
}
}
}
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions livekit/src/room/track/local_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ impl LocalTrack {
Self::Video(track) => track.rtc_track().into(),
}
}

pub async fn get_stats(&self) -> RoomResult<Vec<RtcStats>> {
match self {
Self::Audio(track) => track.get_stats().await,
Self::Video(track) => track.get_stats().await,
}
}
}

impl From<LocalTrack> for Track {
Expand Down
7 changes: 7 additions & 0 deletions livekit/src/room/track/remote_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ impl RemoteTrack {
Self::Video(track) => track.rtc_track().into(),
}
}

pub async fn get_stats(&self) -> RoomResult<Vec<RtcStats>> {
match self {
Self::Audio(track) => track.get_stats().await,
Self::Video(track) => track.get_stats().await,
}
}
}

pub(super) async fn get_stats(inner: &Arc<TrackInner>) -> RoomResult<Vec<RtcStats>> {
Expand Down

0 comments on commit 5ce2ef3

Please sign in to comment.