MCPcopy Create free account
hub / github.com/efficientgo/e2e / Start

Function Start

profiling/profiling.go:196–245  ·  view source on GitHub ↗

Start deploys monitoring service which deploys Parca that collects profiles from all ProfiledRunnable instances in environment created with AsProfiled.

(env e2e.Environment, opts ...Option)

Source from the content-addressed store, hash-verified

194// Start deploys monitoring service which deploys Parca that collects profiles from all
195// ProfiledRunnable instances in environment created with AsProfiled.
196func Start(env e2e.Environment, opts ...Option) (_ *Service, err error) {
197 opt := opt{scrapeInterval: 5 * time.Second}
198 for _, o := range opts {
199 o(&opt)
200 }
201
202 m := http.NewServeMux()
203 m.HandleFunc("/debug/pprof/", pprof.Index)
204
205 o := sync.Once{}
206 scraped := make(chan struct{})
207 m.Handle("/debug/pprof/profile", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
208 o.Do(func() { close(scraped) })
209 pprof.Profile(w, req)
210 }))
211
212 // Listen on all addresses, since we need to connect to it from docker container.
213 list, err := net.Listen("tcp", "0.0.0.0:0")
214 if err != nil {
215 return nil, err
216 }
217 s := http.Server{Handler: m}
218
219 go func() { _ = s.Serve(list) }()
220 env.AddCloser(func() { _ = s.Close() })
221
222 p := NewParca(env, "profiling", opt.customParcaImage, nil)
223
224 _, port, err := net.SplitHostPort(list.Addr().String())
225 if err != nil {
226 return nil, err
227 }
228 l := &listener{p: p, localAddr: net.JoinHostPort(env.HostAddr(), port), scrapeInterval: opt.scrapeInterval}
229 if err := l.updateConfig(map[string]Profiled{}); err != nil {
230 return nil, err
231 }
232 env.AddListener(l)
233
234 if err := e2e.StartAndWaitReady(p); err != nil {
235 return nil, errors.Wrap(err, "starting profiling and waiting until ready")
236 }
237
238 select {
239 case <-time.After(2 * time.Minute):
240 return nil, errors.New("Parca failed to collect profiles from local process after 2 minutes, check profiling Parca logs")
241 case <-scraped:
242 }
243
244 return &Service{p: p}, nil
245}
246
247func (s *Service) OpenUserInterfaceInBrowser(paths ...string) error {
248 return e2einteractive.OpenInBrowser("http://" + s.p.Endpoint("http") + strings.Join(paths, "/"))

Callers

nothing calls this directly

Calls 8

updateConfigMethod · 0.95
StartAndWaitReadyFunction · 0.92
NewParcaFunction · 0.70
AddCloserMethod · 0.65
CloseMethod · 0.65
HostAddrMethod · 0.65
AddListenerMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…