From cb5ca33b0cd2cf14676cda793262d65a49b49221 Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Sat, 16 Jan 2021 13:40:12 -0500 Subject: [PATCH] remove default case from mumble onAudioStream --- .gitignore | 4 +++- main.go | 15 +++++++++++++++ mumble.go | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 34f636d..d25081d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .env main -mumble-discord-bridge \ No newline at end of file +mumble-discord-bridge +bridge +.prof \ No newline at end of file diff --git a/main.go b/main.go index c8c5611..2de5be3 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "log" "os" "os/signal" + "runtime/pprof" "strconv" "sync" "syscall" @@ -17,6 +18,8 @@ import ( _ "layeh.com/gumble/opus" ) +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") + func main() { godotenv.Load() @@ -61,6 +64,18 @@ func main() { } } + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal("could not create CPU profile: ", err) + } + defer f.Close() // error handling omitted for example + if err := pprof.StartCPUProfile(f); err != nil { + log.Fatal("could not start CPU profile: ", err) + } + defer pprof.StopCPUProfile() + } + //Connect to discord discord, err := discordgo.New("Bot " + *discordToken) if err != nil { diff --git a/mumble.go b/mumble.go index 24d2d4e..c3d143b 100644 --- a/mumble.go +++ b/mumble.go @@ -33,7 +33,6 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) { log.Println("new mumble audio stream", e.User.Name) for { select { - default: case <-die: log.Println("Removing mumble audio stream") return