MCPcopy
hub / github.com/yusing/godoxy / initProfiling

Function initProfiling

cmd/pprof_prof.go:16–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func initProfiling() {
17 go func() {
18 log.Info().Msgf("pprof server started at http://localhost:7777/debug/pprof/")
19 log.Error().Err(http.ListenAndServe(":7777", nil)).Msg("pprof server failed")
20 }()
21 go func() {
22 ticker := time.NewTicker(time.Second * 10)
23 defer ticker.Stop()
24
25 var m runtime.MemStats
26 var gcStats debug.GCStats
27
28 for range ticker.C {
29 runtime.ReadMemStats(&m)
30 debug.ReadGCStats(&gcStats)
31
32 log.Info().Msgf("-----------------------------------------------------")
33 log.Info().Msgf("Timestamp: %s", time.Now().Format(time.RFC3339))
34 log.Info().Msgf(" Go Heap - In Use (Alloc/HeapAlloc): %s", strutils.FormatByteSize(m.Alloc))
35 log.Info().Msgf(" Go Heap - Reserved from OS (HeapSys): %s", strutils.FormatByteSize(m.HeapSys))
36 log.Info().Msgf(" Go Stacks - In Use (StackInuse): %s", strutils.FormatByteSize(m.StackInuse))
37 log.Info().Msgf(" Go Runtime - Other Sys (MSpanInuse, MCacheInuse, BuckHashSys, GCSys, OtherSys): %s", strutils.FormatByteSize(m.MSpanInuse+m.MCacheInuse+m.BuckHashSys+m.GCSys+m.OtherSys))
38 log.Info().Msgf(" Go Runtime - Total from OS (Sys): %s", strutils.FormatByteSize(m.Sys))
39 log.Info().Msgf(" Go Runtime - Freed from OS (HeapReleased): %s", strutils.FormatByteSize(m.HeapReleased))
40 log.Info().Msgf(" Number of Goroutines: %d", runtime.NumGoroutine())
41 log.Info().Msgf(" Number of completed GC cycles: %d", m.NumGC)
42 log.Info().Msgf(" Number of GCs: %d", gcStats.NumGC)
43 log.Info().Msgf(" Total GC time: %s", gcStats.PauseTotal)
44 log.Info().Msgf(" Last GC time: %s", gcStats.LastGC.Format(time.DateTime))
45 log.Info().Msg("-----------------------------------------------------")
46 }
47 }()
48}

Callers 1

mainFunction · 0.70

Calls 4

ErrMethod · 0.80
ListenAndServeMethod · 0.65
FormatMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected