Add printing of number of goroutines to assist with performance improvements
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package background
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
||||
@@ -9,11 +11,16 @@ import (
|
||||
"git.fjla.uk/owlboard/timetable-mgr/log"
|
||||
)
|
||||
|
||||
const frequency = 600 * time.Hour // Figure out a sensible frequency!
|
||||
const frequency = 2 * time.Hour // Figure out a sensible frequency!
|
||||
|
||||
// Starts a background ticker to run background tasks. Uses the frequency configured in the background/ticker.go file
|
||||
func InitTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
||||
go runTicker(cfg, stop)
|
||||
|
||||
// Run goroutine logging ticker if runtime set to debug
|
||||
if helpers.Runtime == "debug" {
|
||||
go goroutineTicker(stop)
|
||||
}
|
||||
}
|
||||
|
||||
// Runs the ticker and handles tick events
|
||||
@@ -32,3 +39,18 @@ func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Starts a ticker that logs how many goroutines are running every two seconds
|
||||
func goroutineTicker(stop <-chan struct{}) {
|
||||
log.Msg.Warn("Starting goroutine Tracker ticker - DEBUG USE ONLY")
|
||||
ticker := time.NewTicker(1000 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
case <-ticker.C:
|
||||
fmt.Printf("Number of goroutines running: %d\n", runtime.NumGoroutine())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user