Skip to content

Commit

Permalink
Add support for CPU profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
hg committed Feb 15, 2021
1 parent 537d522 commit eae9d73
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/hg/airmon/influx"
"github.com/hg/airmon/mqtt"
"log"
"os"
"runtime/pprof"
)

func main() {
Expand All @@ -21,10 +23,23 @@ func main() {
flag.StringVar(&infs.Bucket, "influx.bucket", "airmon", "InfluxDB server URI")
flag.StringVar(&infs.Token, "influx.token", "", "InfluxDB access token")

profile := flag.String("profile", "", "write cpu profile to this file")

flag.Parse()
mqts.SetFromEnvironment()
infs.SetFromEnvironment()

if *profile != "" {
f, err := os.Create(*profile)
if err != nil {
log.Fatal("could not create cpu profile file: ", err)
}
defer f.Close()

_ = pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}

sender, err := influx.NewWriter(infs)
if err != nil {
log.Fatal("could not prepare InfluxDB writer: ", err)
Expand Down

0 comments on commit eae9d73

Please sign in to comment.