]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Print average download rate
authorMatt Joiner <anacrolix@gmail.com>
Thu, 14 Oct 2021 12:14:10 +0000 (23:14 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 03:08:56 +0000 (14:08 +1100)
cmd/torrent/main.go

index 260f51d28931130598f9c84e7703d3d6baf2b5a3..c2e65801c92a5189c3425d857179c5557de835da 100644 (file)
@@ -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")