diff options
author | Gusted <postmaster@gusted.xyz> | 2025-01-03 09:33:09 +0100 |
---|---|---|
committer | Gusted <postmaster@gusted.xyz> | 2025-01-05 04:07:49 +0100 |
commit | ebe6ebe3f3e3d1bc071ed52ede2279ea0d04c3ca (patch) | |
tree | 2ab8752203745cf2dcad01523f8eb1a464cf0d10 /routers | |
parent | feat: add limited execution tracing support (diff) | |
download | forgejo-ebe6ebe3f3e3d1bc071ed52ede2279ea0d04c3ca.tar.xz forgejo-ebe6ebe3f3e3d1bc071ed52ede2279ea0d04c3ca.zip |
feat: Run garbage collection before profiling heap
- This avoids returning that some memory is allocated for something
that's actually no longer in used. Go's standard library also does this
for testing and benchmarking when returning memory profiles. A canonical
link that this recommended is the example "To add equivalent profiling
support to a standalone program" in https://pkg.go.dev/runtime/pprof
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/admin/diagnosis.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/routers/web/admin/diagnosis.go b/routers/web/admin/diagnosis.go index 1c12259b06..959c9bc444 100644 --- a/routers/web/admin/diagnosis.go +++ b/routers/web/admin/diagnosis.go @@ -6,6 +6,7 @@ package admin import ( "archive/zip" "fmt" + "runtime" "runtime/pprof" "runtime/trace" "time" @@ -73,5 +74,8 @@ func MonitorDiagnosis(ctx *context.Context) { ctx.ServerError("Failed to create zip file", err) return } + // To avoid showing memory that actually can be cleaned, run the garbage + // collector. + runtime.GC() _ = pprof.Lookup("heap").WriteTo(f, 0) } |