Skip to content

Commit cb198f3

Browse files
committed
Additional metrics
1 parent 7ceae59 commit cb198f3

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

livekit-ffi/src/server/audio_source.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{borrow::Cow, slice};
15+
use std::{borrow::Cow, slice, time::Instant};
1616

1717
use livekit::webrtc::prelude::*;
18+
use metrics_logger::metrics::histogram;
1819

1920
use super::FfiHandle;
2021
use crate::{proto, server, FfiError, FfiHandleId, FfiResult};
@@ -72,6 +73,9 @@ impl FfiAudioSource {
7273
server: &'static server::FfiServer,
7374
capture: proto::CaptureAudioFrameRequest,
7475
) -> FfiResult<proto::CaptureAudioFrameResponse> {
76+
77+
let t0 = Instant::now();
78+
7579
let buffer = capture.buffer;
7680

7781
let source = self.source.clone();
@@ -84,6 +88,7 @@ impl FfiAudioSource {
8488
.to_vec();
8589

8690
let handle = server.async_runtime.spawn(async move {
91+
let t0 = Instant::now();
8792
// The data must be available as long as the client receive the callback.
8893
match source {
8994
#[cfg(not(target_arch = "wasm32"))]
@@ -106,9 +111,14 @@ impl FfiAudioSource {
106111
}
107112
_ => {}
108113
}
114+
let delta = t0.elapsed();
115+
histogram!("capture_audio_frame_task").record(delta.as_millis() as f64);
109116
});
110117
server.watch_panic(handle);
111118

119+
let delta = t0.elapsed();
120+
histogram!("capture_audio_frame").record(delta.as_millis() as f64);
121+
112122
Ok(proto::CaptureAudioFrameResponse { async_id })
113123
}
114124
}

livekit-ffi/src/server/video_source.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::time::Instant;
16+
1517
use super::{colorcvt, FfiHandle};
1618
use crate::{proto, server, FfiError, FfiHandleId, FfiResult};
1719
use livekit::webrtc::{prelude::*, video_frame::VideoFrame};
20+
use metrics_logger::metrics::histogram;
1821

1922
pub struct FfiVideoSource {
2023
pub handle_id: FfiHandleId,
@@ -58,6 +61,7 @@ impl FfiVideoSource {
5861
_server: &'static server::FfiServer,
5962
capture: proto::CaptureVideoFrameRequest,
6063
) -> FfiResult<()> {
64+
let t0 = Instant::now();
6165
match self.source {
6266
#[cfg(not(target_arch = "wasm32"))]
6367
RtcVideoSource::Native(ref source) => {
@@ -72,6 +76,9 @@ impl FfiVideoSource {
7276
}
7377
_ => {}
7478
}
79+
80+
let delta = t0.elapsed();
81+
histogram!("capture_video_frame").record(delta.as_millis() as f64);
7582
Ok(())
7683
}
7784
}

livekit-ffi/src/server/video_stream.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::time::Instant;
16+
1517
use futures_util::StreamExt;
1618
use livekit::{
1719
prelude::Track,
1820
webrtc::{prelude::*, video_stream::native::NativeVideoStream},
1921
};
22+
use metrics_logger::metrics::histogram;
2023
use tokio::sync::{broadcast, mpsc, oneshot};
2124

2225
use super::{colorcvt, room::FfiTrack, FfiHandle};
@@ -132,6 +135,8 @@ impl FfiVideoStream {
132135
break;
133136
}
134137
frame = native_stream.next() => {
138+
let t0 = Instant::now();
139+
135140
let Some(frame) = frame else {
136141
break;
137142
};
@@ -165,6 +170,9 @@ impl FfiVideoStream {
165170
server.drop_handle(handle_id);
166171
log::warn!("failed to send video frame: {}", err);
167172
}
173+
174+
let delta = t0.elapsed();
175+
histogram!("forward_video_frame").record(delta.as_millis() as f64);
168176
}
169177
}
170178
}

0 commit comments

Comments
 (0)