|
@@ -8,10 +8,14 @@ import (
|
|
|
"os/signal"
|
|
"os/signal"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
"runtime"
|
|
"runtime"
|
|
|
|
|
+ "runtime/trace"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"syscall"
|
|
"syscall"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
|
|
+ "net/http"
|
|
|
|
|
+ _ "net/http/pprof"
|
|
|
|
|
+
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
@@ -44,12 +48,33 @@ func init() {
|
|
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
|
v := flag.Bool("v", false, "prints current version and exits")
|
|
v := flag.Bool("v", false, "prints current version and exits")
|
|
|
|
|
+ profile := flag.Bool("profile", false, "Turn on pprof profiling")
|
|
|
|
|
+ profilePort := flag.Int("profile-port", 6060, "Define custom port for profiling")
|
|
|
flag.Parse()
|
|
flag.Parse()
|
|
|
if *v {
|
|
if *v {
|
|
|
fmt.Printf("Version %s (commit: %s)\n", version, commit)
|
|
fmt.Printf("Version %s (commit: %s)\n", version, commit)
|
|
|
os.Exit(0)
|
|
os.Exit(0)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if *profile {
|
|
|
|
|
+ runtime.SetBlockProfileRate(1)
|
|
|
|
|
+ go func() {
|
|
|
|
|
+ http.ListenAndServe(fmt.Sprintf("localhost:%d", *profilePort), nil)
|
|
|
|
|
+ }()
|
|
|
|
|
+
|
|
|
|
|
+ f, err := os.Create("trace.out")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer f.Close()
|
|
|
|
|
+
|
|
|
|
|
+ err = trace.Start(f)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer trace.Stop()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
buildstampInt64, _ := strconv.ParseInt(buildstamp, 10, 64)
|
|
buildstampInt64, _ := strconv.ParseInt(buildstamp, 10, 64)
|
|
|
if buildstampInt64 == 0 {
|
|
if buildstampInt64 == 0 {
|
|
|
buildstampInt64 = time.Now().Unix()
|
|
buildstampInt64 = time.Now().Unix()
|
|
@@ -113,6 +138,8 @@ func listenToSystemSignals(server models.GrafanaServer) {
|
|
|
|
|
|
|
|
select {
|
|
select {
|
|
|
case sig := <-signalChan:
|
|
case sig := <-signalChan:
|
|
|
|
|
+ // Stops trace if profiling has been enabled
|
|
|
|
|
+ trace.Stop()
|
|
|
server.Shutdown(0, fmt.Sprintf("system signal: %s", sig))
|
|
server.Shutdown(0, fmt.Sprintf("system signal: %s", sig))
|
|
|
case code = <-exitChan:
|
|
case code = <-exitChan:
|
|
|
server.Shutdown(code, "startup error")
|
|
server.Shutdown(code, "startup error")
|