util: Add a pprof helper package

As it turns out, there are other helper packages out there. I wrote this
before I realized that, and it didn't take me that long anyways.
This commit is contained in:
James Shubin
2025-01-24 03:06:31 -05:00
parent ca6e7ad432
commit 1d3f2dbe3c
2 changed files with 107 additions and 1 deletions

13
main.go
View File

@@ -43,7 +43,8 @@ import (
_ "github.com/purpleidea/mgmt/lang/gapi" // import so the gapi registers
_ "github.com/purpleidea/mgmt/puppet" // import so the gapi registers
_ "github.com/purpleidea/mgmt/puppet/langpuppet" // import so the gapi registers
_ "github.com/purpleidea/mgmt/yamlgraph" // import so the gapi registers
"github.com/purpleidea/mgmt/util/pprof"
_ "github.com/purpleidea/mgmt/yamlgraph" // import so the gapi registers
"go.etcd.io/etcd/server/v3/etcdmain"
)
@@ -76,6 +77,16 @@ func main() {
return // for safety
}
// Run profiling if it's activated.
// TODO: Should we pass a logger into this?
ctx, cancel := context.WithCancel(context.Background())
if err := pprof.Run(ctx); err != nil {
fmt.Println(err)
os.Exit(1)
//return // redundant
}
defer cancel()
cliUtil.LogSetup(debug)
data := &cliUtil.Data{
Program: program,