Adding some profiling code
This commit is contained in:
parent
648d6a192d
commit
63df3adab1
24
server.go
24
server.go
@ -30,9 +30,13 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GaryBoone/GoStats/stats"
|
"github.com/GaryBoone/GoStats/stats"
|
||||||
@ -309,6 +313,7 @@ func main() {
|
|||||||
staticDir := flag.String("static", "static", "path to static files")
|
staticDir := flag.String("static", "static", "path to static files")
|
||||||
portNum := flag.Int("port", 8080, "port to serve content on")
|
portNum := flag.Int("port", 8080, "port to serve content on")
|
||||||
dataSrc := flag.String("data", "hscd@/hscd", "data source for database")
|
dataSrc := flag.String("data", "hscd@/hscd", "data source for database")
|
||||||
|
profile := flag.String("profile", "", "write cpu profile to file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
@ -317,6 +322,25 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
if *profile != "" {
|
||||||
|
f, err := os.Create(*profile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pprof.StartCPUProfile(f)
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
log.Print("interrupted")
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
os.Exit(1)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/query", executeQuery)
|
http.HandleFunc("/query", executeQuery)
|
||||||
http.HandleFunc("/categories", getCategories)
|
http.HandleFunc("/categories", getCategories)
|
||||||
http.HandleFunc("/learn", addCategory)
|
http.HandleFunc("/learn", addCategory)
|
||||||
|
Loading…
Reference in New Issue
Block a user