From 4d74b51b252dc23d4cb9a886823f356c8d4d78d9 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 21 Jan 2015 17:01:10 +0100 Subject: [PATCH 1/3] cmd: sum up & display storage pieces memory usage --- bin/cmd.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/cmd.js b/bin/cmd.js index 05c0d896..4bbfe129 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -438,11 +438,14 @@ function drawTorrent (torrent) { '{green:blocked:} {bold:' + torrent.numBlockedPeers + '}' ) clivas.line('{80:}') - linesremaining -= 8 + linesremaining -= 9 var pieces = torrent.storage.pieces + var storageMem = 0 for (var i = 0; i < pieces.length; i++) { var piece = pieces[i] + if (piece.buffer) + storageMem += piece.buffer.length if (piece.verified || piece.blocksWritten === 0) { continue; } @@ -453,6 +456,9 @@ function drawTorrent (torrent) { clivas.line('{4+cyan:' + i + '} ' + bar); linesremaining -= 1 } + clivas.line( + '{red:storage mem:} {bold:' + Math.ceil(storageMem / 1024) + ' KB} ' + ) clivas.line('{80:}') linesremaining -= 1 From 111109a7c8f909942d204b2cb63d4e5bd994be35 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 21 Jan 2015 17:45:54 +0100 Subject: [PATCH 2/3] cmd: paint reserved blocks in blue --- bin/cmd.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/cmd.js b/bin/cmd.js index 4bbfe129..f1e695c8 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -451,7 +451,19 @@ function drawTorrent (torrent) { } var bar = '' for (var j = 0; j < piece.blocks.length; j++) { - bar += piece.blocks[j] ? '{green:█}' : '{red:█}'; + switch(piece.blocks[j]) { + case 0: + bar += '{red:█}'; + break; + case 1: + bar += '{blue:█}'; + break; + case 2: + bar += '{green:█}'; + break; + default: + throw 'Invalid block state: ' + piece.blocks[j] + } } clivas.line('{4+cyan:' + i + '} ' + bar); linesremaining -= 1 From b9e9603043212c9e0519369542d5cd45caa47756 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 22 Jan 2015 00:08:57 +0100 Subject: [PATCH 3/3] FSStorage: free written piece buffers --- lib/fs-storage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fs-storage.js b/lib/fs-storage.js index cd32d4e5..6942e40e 100644 --- a/lib/fs-storage.js +++ b/lib/fs-storage.js @@ -160,6 +160,7 @@ FSStorage.prototype._onPieceDone = function (piece) { var writeToNextFile = function (err) { if (err) return self.emit('error', err) if (i >= end) { + delete piece.buffer return cb() }