Merge pull request 'Add logging for performance analysis' (#1) from logg into main

Reviewed-on: https://git.thegrind.dev/thegrind/papibot/pulls/1
This commit is contained in:
javif89 2025-02-04 23:49:43 -07:00
commit dd65e50731

20
main.go
View File

@ -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")
}