Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
//go:build memprofiler
|
|
// +build memprofiler
|
|
|
|
package base
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"runtime/pprof"
|
|
"time"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/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, event.WithInfoMsg("could not create profile directory"))
|
|
return
|
|
}
|
|
|
|
go func() {
|
|
for {
|
|
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.WithInfoMsg("could not create memory profile"))
|
|
}
|
|
runtime.GC()
|
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
|
event.WriteError(ctx, op, err, event.WithInfoMsg("could not write memory profile"))
|
|
}
|
|
f.Close()
|
|
event.WriteSysEvent(ctx, op, "wrote memory profile", "filename", filename)
|
|
time.Sleep(5 * time.Minute)
|
|
}
|
|
}()
|
|
}
|