From 7c10138c2977f28017828a378679ed8c9529ba40 Mon Sep 17 00:00:00 2001 From: Mark Holt Date: Thu, 18 Jul 2024 16:37:13 +0100 Subject: [PATCH] print hash rate --- t.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t.go b/t.go index ece4a7764d..ddc280038d 100644 --- a/t.go +++ b/t.go @@ -2,9 +2,11 @@ package torrent import ( "context" + "fmt" "runtime" "strconv" "strings" + "sync/atomic" "time" "github.com/anacrolix/chansync/events" @@ -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 @@ -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 @@ -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)