Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

correct sync memory usage calculation #2385

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions sync/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ use rlp::*;
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 {
header: Bytes,
body: Option<Bytes>,
}

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 {
Expand Down Expand Up @@ -219,10 +225,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.
Expand Down