Files
tasks/common/pprof/pprof.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

67 lines
1.6 KiB
Go

package pprof
import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" // DO NOT REMOVE THE LINE
"sync/atomic"
"github.com/hanzoai/tasks/common/config"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
)
const (
pprofNotInitialized int32 = 0
pprofInitialized int32 = 1
)
type (
// PProfInitializerImpl initialize the pprof based on config
PProfInitializerImpl struct {
PProf *config.PProf
Logger log.Logger
}
)
// the pprof should only be initialized once per process
// otherwise, the caller / worker will experience weird issue
var pprofStatus = pprofNotInitialized
// NewInitializer create a new instance of PProf Initializer
func NewInitializer(cfg *config.PProf, logger log.Logger) *PProfInitializerImpl {
return &PProfInitializerImpl{
PProf: cfg,
Logger: logger,
}
}
// Start the pprof based on config
func (initializer *PProfInitializerImpl) Start() error {
port := initializer.PProf.Port
if port == 0 {
initializer.Logger.Info("PProf not started due to port not set")
return nil
}
host := initializer.PProf.Host
if host == "" {
// default to localhost which will favor ipv4 on dual stack
// environments - configure host as `::1` to bind on ipv6 localhost
host = "localhost"
}
hostPort := net.JoinHostPort(host, fmt.Sprint(port))
if atomic.CompareAndSwapInt32(&pprofStatus, pprofNotInitialized, pprofInitialized) {
go func() {
initializer.Logger.Info("PProf listen on ", tag.Host(host), tag.Port(port))
err := http.ListenAndServe(hostPort, nil)
if err != nil {
initializer.Logger.Error("listen and serve err", tag.Error(err))
}
}()
}
return nil
}