go.temporal.io/server/common/pprof/pprof.go

66 LOC · 23 covered · 43 uncovered · 5 ranges · 64 concepts · 2 introducers · 12 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package pprof
2
3 import (
4 "fmt"
5 "net"
6 "net/http"
7 _ "net/http/pprof" // DO NOT REMOVE THE LINE
8 "sync/atomic"
9
10 "go.temporal.io/server/common/config"
11 "go.temporal.io/server/common/log"
12 "go.temporal.io/server/common/log/tag"
13 )
14
15 const (
16 pprofNotInitialized int32 = 0
17 pprofInitialized int32 = 1
18 )
19
20 type (
21 // PProfInitializerImpl initialize the pprof based on config
22 PProfInitializerImpl struct {
23 PProf *config.PProf
24 Logger log.Logger
25 }
26 )
27
28 // the pprof should only be initialized once per process
29 // otherwise, the caller / worker will experience weird issue
30 var pprofStatus = pprofNotInitialized
31
32 // NewInitializer create a new instance of PProf Initializer
33 > func NewInitializer(cfg *config.PProf, logger log.Logger) *PProfInitializerImpl { fx.go ×44
34 > return &PProfInitializerImpl{
35 > PProf: cfg,
36 > Logger: logger,
37 > }
38 > }
39
40 // Start the pprof based on config
41 > func (initializer *PProfInitializerImpl) Start() error { fx.go ×44
42 > port := initializer.PProf.Port
43 > if port == 0 {
44 initializer.Logger.Info("PProf not started due to port not set")
45 return nil
46 }
47 > host := initializer.PProf.Host fx.go ×44
48 > if host == "" {
49 > // default to localhost which will favor ipv4 on dual stack
50 > // environments - configure host as `::1` to bind on ipv6 localhost
51 > host = "localhost"
52 > }
53
54 > hostPort := net.JoinHostPort(host, fmt.Sprint(port)) fx.go ×44
55 >
56 > if atomic.CompareAndSwapInt32(&pprofStatus, pprofNotInitialized, pprofInitialized) {
57 > go func() {
58 > initializer.Logger.Info("PProf listen on ", tag.Host(host), tag.Port(port))
59 > err := http.ListenAndServe(hostPort, nil)
60 > if err != nil {
61 initializer.Logger.Error("listen and serve err", tag.Error(err))
62 }
63 }()
64 }
65 > return nil fx.go ×44
66 }