From 2bca615e82f176cf902fe1bc9a0994d5cce76e09 Mon Sep 17 00:00:00 2001 From: Xander Bazzi Date: Wed, 5 Feb 2025 01:46:30 -0500 Subject: [PATCH] Add logging for performance analysis --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index e748c79..03277bd 100644 --- a/main.go +++ b/main.go @@ -140,10 +140,15 @@ func playOnVoiceChannel(voiceChannel *dg.VoiceConnection) { packets := [][]byte{} + startTime := time.Now() + + bytes_sent := 0 for { // I read in the RFC that frames will not be bigger than this size p := make([]byte, 960) n, err := ffmpegOut.Read(p) + bytes_sent = bytes_sent + n + if err != nil { log.Printf("Bytes: %d", n) if err == io.EOF { @@ -157,14 +162,29 @@ func playOnVoiceChannel(voiceChannel *dg.VoiceConnection) { packets = append(packets, p[:n]) } + elapsedTime := time.Since(startTime) + + log.Printf("bytes sent = %d", bytes_sent) + log.Printf("Took %s seconds to run", elapsedTime) + // log.Printf("Bytes/Sec = %s", elapsedTime) + voiceChannel.Speaking(true) time.Sleep(time.Second * 2) log.Println("Playing sound") + startTime = time.Now() + bytes_sent = 0 for _, p := range packets { log.Printf("Sending packet: %d bytes", len(p)) + bytes_sent += len(p) + // packets_sent := packets_sent + p voiceChannel.OpusSend <- p } + + elapsedTime = time.Since(startTime) + log.Printf("Packets = %d", len(packets)) + log.Printf("Network bytes sent = %d", bytes_sent) + log.Printf("Took %s seconds to run", elapsedTime) log.Println("Ended stream") } -- 2.47.1