ADMIN API to dump Go heap profile
()
| 615 | |
| 616 | // ADMIN API to dump Go heap profile |
| 617 | func (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, ¶ms); 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 | |
| 644 | func (h *handler) handlePprofGoroutine() error { |
| 645 | httpprof.Handler("goroutine").ServeHTTP(h.response, h.rq) |