mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-25 14:53:15 +01:00
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
This commit is contained in:
parent
3f44b97b5f
commit
ebe6ebe3f3
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue