From 1d1a3b9d027d98e84625d78e93e9eb4dbe089ca1 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 28 Sep 2016 23:00:27 +0200 Subject: [PATCH] correct sync memory usage calculation (#2386) --- sync/src/blocks.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sync/src/blocks.rs b/sync/src/blocks.rs index 2e0aa5d4e..342b59459 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -18,7 +18,7 @@ use util::*; use network::NetworkError; use ethcore::header::{ Header as BlockHeader}; -known_heap_size!(0, HeaderId, SyncBlock); +known_heap_size!(0, HeaderId); /// Block data with optional body. struct SyncBlock { @@ -26,6 +26,12 @@ struct SyncBlock { body: Option, } +impl HeapSizeOf for SyncBlock { + fn heap_size_of_children(&self) -> usize { + self.header.heap_size_of_children() + self.body.heap_size_of_children() + } +} + /// Used to identify header by transactions and uncles hashes #[derive(Eq, PartialEq, Hash)] struct HeaderId { @@ -218,10 +224,14 @@ impl BlockCollection { self.blocks.contains_key(hash) } - /// Return heap size. + /// Return used heap size. pub fn heap_size(&self) -> usize { - //TODO: other collections - self.blocks.heap_size_of_children() + self.heads.heap_size_of_children() + + self.blocks.heap_size_of_children() + + self.parents.heap_size_of_children() + + self.header_ids.heap_size_of_children() + + self.downloading_headers.heap_size_of_children() + + self.downloading_bodies.heap_size_of_children() } /// Check if given block hash is marked as being downloaded.