From 89e7e00c319651dddb7ef209da9e0ee5bab129d8 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 14 Oct 2021 23:14:10 +1100 Subject: [PATCH] Print average download rate --- cmd/torrent/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 260f51d2..c2e65801 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -347,6 +347,7 @@ func downloadErr(flags downloadFlags) error { client.WriteStatus(w) }) err = addTorrents(client, flags) + started := time.Now() if err != nil { return fmt.Errorf("adding torrents: %w", err) } @@ -356,6 +357,13 @@ func downloadErr(flags downloadFlags) error { } else { err = errors.New("y u no complete torrents?!") } + clientConnStats := client.ConnStats() + log.Printf("average download rate: %v", + humanize.Bytes(uint64( + time.Duration( + clientConnStats.BytesReadUsefulData.Int64(), + )*time.Second/time.Since(started), + ))) if flags.Seed { if len(client.Torrents()) == 0 { log.Print("no torrents to seed") -- 2.44.0