Quellcode durchsuchen

Add PGO

tags/v2.2.3^2^2
9seconds vor 1 Monat
Ursprung
Commit
4fbabfda2a
5 geänderte Dateien mit 54 neuen und 0 gelöschten Zeilen
  1. 3
    0
      .gitattributes
  2. BIN
      default.pgo
  3. 17
    0
      main.go
  4. 7
    0
      run_profile.go
  5. 27
    0
      run_profile_tag_prof.go

+ 3
- 0
.gitattributes Datei anzeigen

@@ -0,0 +1,3 @@
1
+# git config merge.theirs.name "Always accept theirs"
2
+# git config merge.theirs.driver "cp %B %A"
3
+default.pgo binary merge=theirs

BIN
default.pgo Datei anzeigen


+ 17
- 0
main.go Datei anzeigen

@@ -14,6 +14,23 @@ import (
14 14
 )
15 15
 
16 16
 func main() {
17
+	// this runs profiling server. To enable it, build with prof tag
18
+	//   $ go build -tags prof
19
+	//
20
+	// Then you can pass a port using MTG_PROF_PORT environment variable.
21
+	// Default is 6000
22
+	//   $ MTG_PROF_PORT=6000 mtg run config.toml
23
+	//
24
+	// It will run a webserver with profiling data on
25
+	// localhost:${MTG_PROF_PORT:-6000}.
26
+	//
27
+	// To collect PGO do following:
28
+	//   $ curl -o default.pgo 'http://localhost:6000/debug/pprof/profile?seconds=300'
29
+	//
30
+	// See also https://pkg.go.dev/net/http/pprof
31
+	//          https://go.dev/blog/pprof
32
+	runProfile()
33
+
17 34
 	cli := &cli.CLI{}
18 35
 	ctx := kong.Parse(cli, kong.Vars{
19 36
 		"version": getVersion(),

+ 7
- 0
run_profile.go Datei anzeigen

@@ -0,0 +1,7 @@
1
+//go:build !prof
2
+
3
+package main
4
+
5
+func runProfile() {
6
+
7
+}

+ 27
- 0
run_profile_tag_prof.go Datei anzeigen

@@ -0,0 +1,27 @@
1
+//go:build prof
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+	"net"
8
+	"net/http"
9
+	_ "net/http/pprof" //nolint: gosec
10
+	"os"
11
+)
12
+
13
+const DefaultProfPort = "6000"
14
+
15
+func runProfile() {
16
+	port := os.Getenv("MTG_PROF_PORT")
17
+	if port == "" {
18
+		port = DefaultProfPort
19
+	}
20
+
21
+	listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", port))
22
+	if err != nil {
23
+		panic(err)
24
+	}
25
+
26
+	go http.Serve(listener, nil)
27
+}

Laden…
Abbrechen
Speichern