1- package main
1+ package cmd
22
33import (
44 "fmt"
@@ -18,13 +18,12 @@ const memoryCheckPeriod = 10 * time.Second
1818// profileDumpPeriod limits how frequently we will dump profiles to disk.
1919const profileDumpPeriod = 1 * time .Hour
2020
21- // memoryMonitor runs in a loop, checking every 10 seconds if memory use is greater
21+ // MemoryMonitor runs a loop, checking every 10 seconds if memory use is greater
2222// than GOMEMLIMIT. If so, it dumps memory and goroutine profiles to temporary files
2323// created by os.CreateTemp, at most once per hour.
2424//
2525// If GOMEMLIMIT is unset, returns immediately.
26- func memoryMonitor () {
27- logger := blog .Get ()
26+ func MemoryMonitor () {
2827 memLimit := debug .SetMemoryLimit (- 1 )
2928 if memLimit == math .MaxInt64 {
3029 return
@@ -46,6 +45,7 @@ func memoryMonitor() {
4645 if memStats .Sys - memStats .HeapReleased > memLimitU64 {
4746 lastDump = time .Now ()
4847
48+ logger := blog .Get ()
4949 err := writeProfile (logger , "heap" )
5050 if err != nil {
5151 logger .Errf ("writing heap profile: %s" , err )
@@ -60,7 +60,7 @@ func memoryMonitor() {
6060
6161func writeProfile (logger blog.Logger , typ string ) error {
6262 datestamp := time .Now ().Format ("20060102T150405" )
63- profileFile , err := os .CreateTemp ("" , fmt .Sprintf ("boulder-profile-%s-%s" , typ , datestamp ))
63+ profileFile , err := os .CreateTemp ("" , fmt .Sprintf ("boulder-profile-%s-%s.pprof " , typ , datestamp ))
6464 if err != nil {
6565 return fmt .Errorf ("creating profile file: %s" , err )
6666 }
0 commit comments