1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-10 02:35:58 +01:00

Add profiling support.

This commit is contained in:
Juliusz Chroboczek 2020-05-20 23:04:31 +02:00
parent 5a2dbf36b9
commit 47d23658b5

49
sfu.go
View file

@ -18,6 +18,8 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"runtime"
"runtime/pprof"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@ -32,6 +34,8 @@ var groupsDir string
var iceFilename string var iceFilename string
func main() { func main() {
var cpuprofile, memprofile, mutexprofile string
flag.StringVar(&httpAddr, "http", ":8443", "web server `address`") flag.StringVar(&httpAddr, "http", ":8443", "web server `address`")
flag.StringVar(&staticRoot, "static", "./static/", flag.StringVar(&staticRoot, "static", "./static/",
"web server root `directory`") "web server root `directory`")
@ -39,7 +43,52 @@ func main() {
"data `directory`") "data `directory`")
flag.StringVar(&groupsDir, "groups", "./groups/", flag.StringVar(&groupsDir, "groups", "./groups/",
"group description `directory`") "group description `directory`")
flag.StringVar(&cpuprofile, "cpuprofile", "",
"store CPU profile in `file`")
flag.StringVar(&memprofile, "memprofile", "",
"store memory profile in `file`")
flag.StringVar(&mutexprofile, "mutexprofile", "",
"store mutex profile in `file`")
flag.Parse() flag.Parse()
if cpuprofile != "" {
f, err := os.Create(cpuprofile)
if err != nil {
log.Printf("Create(cpuprofile): %v", err)
return
}
pprof.StartCPUProfile(f)
defer func() {
pprof.StopCPUProfile()
f.Close()
}()
}
if memprofile != "" {
defer func() {
f, err := os.Create(memprofile)
if err != nil {
log.Printf("Create(memprofile): %v", err)
return
}
pprof.WriteHeapProfile(f)
f.Close()
}()
}
if mutexprofile != "" {
runtime.SetMutexProfileFraction(1)
defer func() {
f, err := os.Create(mutexprofile)
if err != nil {
log.Printf("Create(mutexprofile): %v", err)
return
}
pprof.Lookup("mutex").WriteTo(f, 0)
f.Close()
}()
}
iceFilename = filepath.Join(staticRoot, "ice-servers.json") iceFilename = filepath.Join(staticRoot, "ice-servers.json")
http.Handle("/", mungeHandler{http.FileServer(http.Dir(staticRoot))}) http.Handle("/", mungeHandler{http.FileServer(http.Dir(staticRoot))})