diff --git a/Makefile b/Makefile index 211924cf73..c4bd3d0cc0 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,12 @@ build: build-ui-ifne install: export BOUNDARY_INSTALL_BINARY=1 install: build +.PHONY: build-memprof +build-memprof: BUILD_TAGS+=memprofiler +build-memprof: + @echo "==> Building Boundary with memory profiling enabled" + @CGO_ENABLED=$(CGO_ENABLED) BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" + # Format Go files, ignoring files marked as generated through the header defined at # https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source .PHONY: fmt diff --git a/internal/cmd/base/profiling_on.go b/internal/cmd/base/profiling_on.go index 666c089d64..124291bf63 100644 --- a/internal/cmd/base/profiling_on.go +++ b/internal/cmd/base/profiling_on.go @@ -4,18 +4,21 @@ package base import ( + "context" "os" "path/filepath" "runtime" "runtime/pprof" "time" + + "github.com/hashicorp/boundary/internal/observability/event" ) func StartMemProfiler(ctx context.Context) { const op = "base.StartMemProfiler" profileDir := filepath.Join(os.TempDir(), "boundaryprof") if err := os.MkdirAll(profileDir, 0o700); err != nil { - event.WriteError(ctx, op, err, "could not create profile directory") + event.WriteError(ctx, op, err, event.WithInfoMsg("could not create profile directory")) return } @@ -24,11 +27,11 @@ func StartMemProfiler(ctx context.Context) { filename := filepath.Join(profileDir, time.Now().UTC().Format("20060102_150405")) + ".pprof" f, err := os.Create(filename) if err != nil { - event.WriteError(ctx, op, err, event.WithInfo("could not create memory profile")) + event.WriteError(ctx, op, err, event.WithInfoMsg("could not create memory profile")) } runtime.GC() if err := pprof.WriteHeapProfile(f); err != nil { - event.WriteError(ctx, op, err, "could not write memory profile") + event.WriteError(ctx, op, err, event.WithInfoMsg("could not write memory profile")) } f.Close() event.WriteSysEvent(ctx, op, "wrote memory profile", "filename", filename)