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
1717use livekit:: webrtc:: prelude:: * ;
18+ use metrics_logger:: metrics:: histogram;
1819
1920use super :: FfiHandle ;
2021use 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}
0 commit comments