From 3ca3c9622696d5cce1b7d5c23f2056e97baae8fa Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 6 Apr 2017 11:59:01 +0200 Subject: [PATCH 1/2] profiling: adds profiling and tracing If grafana-server binary is started with the -profile flag then tracing will create a trace.out file and pprof data can be accessed on the 6060 port. A custom port for pprof profiling can be set with the -profile-port flag. --- pkg/cmd/grafana-server/main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/cmd/grafana-server/main.go b/pkg/cmd/grafana-server/main.go index 7e8a6061a3f..cd3dd0dbd36 100644 --- a/pkg/cmd/grafana-server/main.go +++ b/pkg/cmd/grafana-server/main.go @@ -8,10 +8,14 @@ import ( "os/signal" "path/filepath" "runtime" + "runtime/trace" "strconv" "syscall" "time" + "net/http" + _ "net/http/pprof" + "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/sqlstore" @@ -44,12 +48,33 @@ func init() { func main() { 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() if *v { fmt.Printf("Version %s (commit: %s)\n", version, commit) 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) if buildstampInt64 == 0 { buildstampInt64 = time.Now().Unix() @@ -113,6 +138,8 @@ func listenToSystemSignals(server models.GrafanaServer) { select { case sig := <-signalChan: + // Stops trace if profiling has been enabled + trace.Stop() server.Shutdown(0, fmt.Sprintf("system signal: %s", sig)) case code = <-exitChan: server.Shutdown(code, "startup error") From e0640487dfa5527b22d689b472a2a17ca23516a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 11 Apr 2017 13:38:13 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 024bc39d2dd..5c32dcdba40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ * **InfluxDB**: Small fix for the "glow" when focus the field for LIMIT and SLIMIT [#7799](https://github.com/grafana/grafana/pull/7799) thx [@thuck](https://github.com/thuck) * **Panels**: Delay loading & Lazy load panels as they become visible (scrolled into view) [#5216](https://github.com/grafana/grafana/issues/5216) thx [@jifwin](https://github.com/jifwin) * **Graph**: Support auto grid min/max when using log scale [#3090](https://github.com/grafana/grafana/issues/3090), thx [@bigbenhur](https://github.com/bigbenhur) +* **Graph**: Support for histograms [#600](https://github.com/grafana/grafana/issues/600) * **Elasticsearch**: Support histogram aggregations [#3164](https://github.com/grafana/grafana/issues/3164) + ## Minor Enchancements * **Prometheus**: Make Prometheus query field a textarea [#7663](https://github.com/grafana/grafana/issues/7663), thx [@hagen1778](https://github.com/hagen1778)