Skip to content

Commit bf341d2

Browse files
authored
feat: allow using pprof on FDW when STEAMPIPE_FDW_PPROF environment variable is set (#368)
1 parent bb61b83 commit bf341d2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fdw.go

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
"fmt"
1414
"io/ioutil"
1515
"log"
16+
"net"
17+
"net/http"
18+
"os"
1619
"time"
1720
"unsafe"
1821

@@ -57,6 +60,18 @@ func init() {
5760
log.Printf("[INFO] Version: v%s\n", version.FdwVersion.String())
5861
log.Printf("[INFO] Log level: %s\n", level)
5962

63+
if _, found := os.LookupEnv("STEAMPIPE_FDW_PPROF"); found {
64+
log.Printf("[INFO] PROFILING!!!!")
65+
go func() {
66+
listener, err := net.Listen("tcp", "localhost:0")
67+
if err != nil {
68+
log.Println(err)
69+
return
70+
}
71+
log.Printf("[INFO] Check http://localhost:%d/debug/pprof/", listener.Addr().(*net.TCPAddr).Port)
72+
log.Println(http.Serve(listener, nil))
73+
}()
74+
}
6075
}
6176

6277
//export goFdwGetRelSize

0 commit comments

Comments
 (0)