Skip to content

Commit

Permalink
pprof support
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Dec 21, 2023
1 parent b234336 commit ae89a72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Config struct {
// with it's own SQL database instance, this parameter should not
// be needed.
ArchiveHeightMax uint64 `koanf:"archive_height_max"`

PprofAddr string `koanf:"pprof_addr"`
}

// Validate performs config validation.
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"net/http"
_ "net/http/pprof" // Import for side effects

Check failure on line 7 in main.go

View workflow job for this annotation

GitHub Actions / lint-go

G108: Profiling endpoint is automatically exposed on /debug/pprof (gosec)
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -172,6 +174,15 @@ func runRoot() error {
return err
}

// Enable pprof if configured.
if cfg.PprofAddr != "" {
go func() {
if err := http.ListenAndServe(cfg.PprofAddr, nil); err != nil {

Check failure on line 180 in main.go

View workflow job for this annotation

GitHub Actions / lint-go

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
logging.GetLogger("pprof").Error("server stopped", "err", err)
}
}()
}

logger := logging.GetLogger("main")

// Decode hex runtime ID into something we can use.
Expand Down

0 comments on commit ae89a72

Please sign in to comment.