Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit f9c7344

Browse files
committed
Add pprof server and protect it with an env var
This will allow us to enable pprof in any environment where we need to keep an eye on what is going on, especially since we need to track down some race conditions during long runs.
1 parent 1a145db commit f9c7344

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

main.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package browser
22

33
import (
4+
"log"
5+
"net/http"
6+
_ "net/http/pprof" // nolint:gosec
7+
"os"
8+
49
"github.com/grafana/xk6-browser/api"
510
"github.com/grafana/xk6-browser/chromium"
611
"github.com/grafana/xk6-browser/common"
@@ -37,6 +42,16 @@ var (
3742
_ k6modules.Instance = &ModuleInstance{}
3843
)
3944

45+
func init() {
46+
if _, ok := os.LookupEnv("XK6_BROWSER_PPROF"); ok {
47+
go func() {
48+
address := "localhost:6060"
49+
log.Println("Starting http debug server", address)
50+
log.Println(http.ListenAndServe(address, nil))
51+
}()
52+
}
53+
}
54+
4055
// New returns a pointer to a new RootModule instance.
4156
func New() *RootModule {
4257
return &RootModule{}
@@ -69,16 +84,6 @@ func (mi *ModuleInstance) Exports() k6modules.Exports {
6984

7085
// Launch Chromium with given options.
7186
func (m *JSModule) Launch(opts goja.Value) api.Browser {
72-
/*go func() {
73-
f, err := os.Create("./cpu.profile")
74-
if err != nil {
75-
log.Fatal(err)
76-
}
77-
pprof.StartCPUProfile(f)
78-
defer pprof.StopCPUProfile()
79-
<-ctx.Done()
80-
}()*/
81-
8287
ctx := k6ext.WithVU(m.vu.Context(), m.vu)
8388
ctx = k6ext.WithCustomMetrics(ctx, m.k6Metrics)
8489

0 commit comments

Comments
 (0)