From 00a730042145491e05d6224b806d2ac447f3dfd2 Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Mon, 20 Sep 2021 14:17:58 +1000
Subject: [PATCH] cmd/torrent: Dump download statistics

---
 cmd/torrent/main.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go
index 624c2a4e..757ecdc7 100644
--- a/cmd/torrent/main.go
+++ b/cmd/torrent/main.go
@@ -369,6 +369,15 @@ func downloadErr(flags downloadFlags) error {
 			<-stop.C()
 		}
 	}
+	spew.Dump(expvar.Get("torrent").(*expvar.Map).Get("chunks received"))
+	spew.Dump(client.ConnStats())
+	clStats := client.ConnStats()
+	sentOverhead := clStats.BytesWritten.Int64() - clStats.BytesWrittenData.Int64()
+	log.Printf(
+		"client read %v, %v was useful data. sent %v non-data bytes",
+		humanize.Bytes(uint64(clStats.BytesRead.Int64())),
+		100*float64(clStats.BytesReadUsefulData.Int64())/float64(clStats.BytesRead.Int64()),
+		humanize.Bytes(uint64(sentOverhead)))
 	return nil
 }
 
-- 
2.51.0