MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleHeapProfiling

Method handleHeapProfiling

rest/api.go:617–642  ·  view source on GitHub ↗

ADMIN API to dump Go heap profile

()

Source from the content-addressed store, hash-verified

615
616// ADMIN API to dump Go heap profile
617func (h *handler) handleHeapProfiling() error {
618 var params struct {
619 File string `json:"file"`
620 }
621 body, err := h.readBody()
622 if err != nil {
623 return err
624 }
625 if err = base.JSONUnmarshal(body, &params); err != nil {
626 return err
627 }
628
629 base.InfofCtx(h.ctx(), base.KeyAll, "Dumping heap profile to %s ...", base.UD(params.File))
630 base.Audit(h.ctx(), base.AuditIDSyncGatewayProfiling, base.AuditFields{base.AuditFieldPprofProfileType: "heap", base.AuditFieldFileName: params.File})
631 f, err := os.Create(params.File)
632 if err != nil {
633 return err
634 }
635 err = pprof.WriteHeapProfile(f)
636
637 if fileCloseError := f.Close(); fileCloseError != nil {
638 base.WarnfCtx(h.ctx(), "Error closing profile file: %v", fileCloseError)
639 }
640
641 return err
642}
643
644func (h *handler) handlePprofGoroutine() error {
645 httpprof.Handler("goroutine").ServeHTTP(h.response, h.rq)

Callers

nothing calls this directly

Calls 8

readBodyMethod · 0.95
ctxMethod · 0.95
JSONUnmarshalFunction · 0.92
InfofCtxFunction · 0.92
UDFunction · 0.92
AuditFunction · 0.92
WarnfCtxFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected