From f18e7b566e2a98e252755f517610713e1fd8df45 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sun, 20 Mar 2016 12:57:48 -0400 Subject: [PATCH] add ability to profile application --- cmd/realm/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/realm/main.go b/cmd/realm/main.go index a21db3e..8343b20 100644 --- a/cmd/realm/main.go +++ b/cmd/realm/main.go @@ -7,6 +7,7 @@ import ( "github.com/alexflint/go-arg" "github.com/brettlangdon/realm" + "github.com/pkg/profile" ) var args struct { @@ -14,12 +15,23 @@ var args struct { Bind string `arg:"help:[]: to bind too"` StatsD string `arg:"--statsd,help:: to send StatsD metrics to"` Workers int `arg:"--workers,help:number of workers to start [default: $GOMAXPROCS]` + Profile string `arg:"--profile,help:enable profiling for one of [cpu, mem, block]` } func main() { args.Bind = ":53" argParser := arg.MustParse(&args) + // Enable profiling + switch args.Profile { + case "cpu": + defer profile.Start(profile.CPUProfile).Stop() + case "mem": + defer profile.Start(profile.MemProfile).Stop() + case "block": + defer profile.Start(profile.BlockProfile).Stop() + } + // Control number of workers via GOMAXPROCS if args.Workers > 0 { runtime.GOMAXPROCS(args.Workers)