]> Sergey Matveev's repositories - btrtrc.git/commitdiff
cmd/torrent: Track download rate
authorMatt Joiner <anacrolix@gmail.com>
Wed, 12 May 2021 04:26:23 +0000 (14:26 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 14 May 2021 05:42:20 +0000 (15:42 +1000)
cmd/torrent/main.go

index 0d32aa4bfb3d090da4d213e0e9d3353b7784d562..a04eb5eabb341125811d8bf91a7a0006630a4ee2 100644 (file)
@@ -40,6 +40,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
                        fmt.Printf("%v: getting torrent info for %q\n", time.Since(start), t.Name())
                        <-t.GotInfo()
                }
+               lastStats := t.Stats()
                var lastLine string
                for range time.Tick(time.Second) {
                        var completedPieces, partialPieces int
@@ -52,8 +53,9 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
                                        partialPieces += r.Length
                                }
                        }
+                       stats := t.Stats()
                        line := fmt.Sprintf(
-                               "%v: downloading %q: %s/%s, %d/%d pieces completed (%d partial)\n",
+                               "%v: downloading %q: %s/%s, %d/%d pieces completed (%d partial): %v/s\n",
                                time.Since(start),
                                t.Name(),
                                humanize.Bytes(uint64(t.BytesCompleted())),
@@ -61,6 +63,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
                                completedPieces,
                                t.NumPieces(),
                                partialPieces,
+                               humanize.Bytes(uint64(stats.BytesReadUsefulData.Int64()-lastStats.BytesReadUsefulData.Int64())),
                        )
                        if line != lastLine {
                                lastLine = line
@@ -69,6 +72,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) {
                        if pieceStates {
                                fmt.Println(psrs)
                        }
+                       lastStats = stats
                }
        }()
 }
@@ -155,7 +159,6 @@ func addTorrents(client *torrent.Client) error {
 
 var flags struct {
        Debug bool
-       Stats *bool
 
        *DownloadCmd      `arg:"subcommand:download"`
        *ListFilesCmd     `arg:"subcommand:list-files"`
@@ -176,8 +179,9 @@ type DownloadCmd struct {
        PublicIP        net.IP
        Progress        bool `default:"true"`
        PieceStates     bool
-       Quiet           bool `help:"discard client logging"`
-       Dht             bool `default:"true"`
+       Quiet           bool  `help:"discard client logging"`
+       Stats           *bool `help:"print stats at termination"`
+       Dht             bool  `default:"true"`
 
        TcpPeers        bool `default:"true"`
        UtpPeers        bool `default:"true"`