Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# git config merge.theirs.name "Always accept theirs"
# git config merge.theirs.driver "cp %B %A"
default.pgo binary merge=theirs
Binary file added default.pgo
Binary file not shown.
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ import (
)

func main() {
// this runs profiling server. To enable it, build with prof tag
// $ go build -tags prof
//
// Then you can pass a port using MTG_PROF_PORT environment variable.
// Default is 6000
// $ MTG_PROF_PORT=6000 mtg run config.toml
//
// It will run a webserver with profiling data on
// localhost:${MTG_PROF_PORT:-6000}.
//
// To collect PGO do following:
// $ curl -o default.pgo 'http://localhost:6000/debug/pprof/profile?seconds=300'
//
// See also https://pkg.go.dev/net/http/pprof
// https://go.dev/blog/pprof
runProfile()

cli := &cli.CLI{}
ctx := kong.Parse(cli, kong.Vars{
"version": getVersion(),
Expand Down
7 changes: 7 additions & 0 deletions run_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !prof

package main

func runProfile() {

}
27 changes: 27 additions & 0 deletions run_profile_tag_prof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build prof

package main

import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" //nolint: gosec
"os"
)

const DefaultProfPort = "6000"

func runProfile() {
port := os.Getenv("MTG_PROF_PORT")
if port == "" {
port = DefaultProfPort
}

listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", port))
if err != nil {
panic(err)
}

go http.Serve(listener, nil)
}
Loading