Started adding functionality to log results directly to files
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
7a8503ed3e
commit
56f1982837
14
cmd/ping.go
14
cmd/ping.go
@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/go-ping/ping"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.metaunix.net/bitgoblin/hardware-tests/lib"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -23,11 +25,17 @@ var pingCmd = &cobra.Command{
|
||||
}
|
||||
pinger.Count = count
|
||||
pinger.OnFinish = func(stats *ping.Statistics) {
|
||||
fmt.Printf("--- %s ping statistics ---\n", stats.Addr)
|
||||
fmt.Printf("%d packets transmitted, %d packets received, %v%% packet loss\n",
|
||||
result := fmt.Sprintf("--- %s ping statistics ---\n", stats.Addr)
|
||||
result += fmt.Sprintf("%d packets transmitted, %d packets received, %v%% packet loss\n",
|
||||
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
||||
fmt.Printf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
|
||||
result += fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
|
||||
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
|
||||
|
||||
if Log != nil {
|
||||
lib.WriteToFile(Log, result)
|
||||
} else {
|
||||
fmt.Printf("%s", result)
|
||||
}
|
||||
}
|
||||
fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())
|
||||
err = pinger.Run() // Blocks until finished.
|
||||
|
@ -7,6 +7,10 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
Log string
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "bgbench",
|
||||
Short: "Bit Goblin hardware benching tool.",
|
||||
@ -20,3 +24,7 @@ func Execute() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&Log, "log", "l", "false", "File location to write results to.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user