Skip to content

Commit

Permalink
print hash rate
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Jul 18, 2024
1 parent 6b5c3aa commit 7c10138
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions t.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package torrent

import (
"context"
"fmt"
"runtime"
"strconv"
"strings"
"sync/atomic"
"time"

"github.com/anacrolix/chansync/events"
Expand Down Expand Up @@ -215,6 +217,8 @@ func (t *Torrent) DownloadPieces(begin, end pieceIndex) {

t.disallowDataDownload(true)

name := t.Name()

mu := sync.RWMutex{}
changes := map[pieceIndex]struct{}{}
haveTrigger := false
Expand All @@ -230,6 +234,12 @@ func (t *Torrent) DownloadPieces(begin, end pieceIndex) {
g.SetLimit(maxInt(runtime.NumCPU()*4-3, t.cl.config.PieceHashersPerTorrent/2))
defer cancel()

fmt.Println("DL", name, "hashers", maxInt(runtime.NumCPU()*4-3, t.cl.config.PieceHashersPerTorrent/2))

var hashed atomic.Int64
start := time.Now()
defer fmt.Println("DL", name, "DONE", "H:", hashed, "R:", float64(hashed.Load())/time.Since(start).Seconds())

for i := begin; i < end; i++ {
i := i

Expand All @@ -252,6 +262,7 @@ func (t *Torrent) DownloadPieces(begin, end pieceIndex) {
mu.RUnlock()

if checkCompletion && !storage.IsNew() {
hashed.Add(int64(piece.length(true)))
if sum, _, err := t.hashPiece(piece); err == nil && sum == *piece.hash {
storage.MarkComplete(false)
t.updatePieceCompletion(i, true)
Expand Down

0 comments on commit 7c10138

Please sign in to comment.