From ab292886a85ddc67d06d15c87a5373ac3717c56b Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 25 May 2025 22:26:12 +0200 Subject: [PATCH] main.go: add option to changes stats interval. --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 8a4980b..ead1aff 100644 --- a/main.go +++ b/main.go @@ -22,8 +22,7 @@ func printStats(pinger *probing.Pinger) { stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt) } -func eventLoop(pinger *probing.Pinger) { - ticker := time.NewTicker(time.Second * 4) +func eventLoop(pinger *probing.Pinger, ticker *time.Ticker) { defer ticker.Stop() defer pinger.Stop() @@ -52,6 +51,7 @@ func main() { count := getopt.IntLong("count", 'c', 0, "Stop after this many packages has been sent (and received). If this option is not specified, pinger will operate until interrupted.") timeout := getopt.DurationLong("timeout", 't', 0, "Exit the program after this time is reached, regardless of how many packets have been received.") interval := getopt.DurationLong("interval", 'i', time.Second*2, "Wait time between each packet send") + statsInterval := getopt.DurationLong("stats-interval", 0, time.Second*4, "How often stats should be printed to the console.") proto_udp := getopt.BoolLong("udp", 0, "Send UDP ping instead of a raw IMCP ping, IMCP required super-user privileges") record_rtt := getopt.BoolLong("rtt", 0, "Keep a record of rtts of all received packets.") @@ -85,7 +85,7 @@ func main() { } // Enter event loop in another goroutine. - go eventLoop(pinger) + go eventLoop(pinger, time.NewTicker(*statsInterval)) // Run pinger in main thread. fmt.Println("PING", pinger.Addr())