Adjust how performance logging is managed

This commit is contained in:
Fred Boniface 2024-04-13 21:45:05 +01:00
parent dc958ac717
commit 16fa1c5354
1 changed files with 5 additions and 3 deletions

View File

@ -1,7 +1,7 @@
package background package background
import ( import (
"fmt" "math"
"runtime" "runtime"
"time" "time"
@ -9,6 +9,7 @@ import (
"git.fjla.uk/owlboard/timetable-mgr/corpus" "git.fjla.uk/owlboard/timetable-mgr/corpus"
"git.fjla.uk/owlboard/timetable-mgr/helpers" "git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log" "git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
) )
const frequency = 2 * time.Hour // Figure out a sensible frequency! const frequency = 2 * time.Hour // Figure out a sensible frequency!
@ -60,7 +61,8 @@ func debugLog() {
runtime.ReadMemStats(&memStats) runtime.ReadMemStats(&memStats)
goroutines := runtime.NumGoroutine() goroutines := runtime.NumGoroutine()
heapMem := float64(memStats.HeapAlloc) / (1024 * 1024)
heapMemRound := math.Round(heapMem*100) / 100
fmt.Printf("\nNumber of goroutines: %d\n", goroutines) log.Msg.Debug("Performance", zap.Int("goroutine-count", goroutines), zap.Float64("heap-mem (MB)", heapMemRound))
fmt.Printf("Heap Allocated memory: %2f MB\n\n", float64(memStats.HeapAlloc)/(1024*1024))
} }