Place ideal peers in the log output. (#1563)

This commit is contained in:
Gav Wood 2016-07-07 15:25:58 +02:00 committed by GitHub
parent 43d931de12
commit 57c14eedfa
4 changed files with 16 additions and 7 deletions

View File

@ -22,7 +22,7 @@ use std::time::{Instant, Duration};
use std::sync::RwLock; use std::sync::RwLock;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use ethsync::{EthSync, SyncProvider}; use ethsync::{EthSync, SyncProvider};
use util::Uint; use util::{Uint, NetworkService};
use ethcore::client::*; use ethcore::client::*;
use number_prefix::{binary_prefix, Standalone, Prefixed}; use number_prefix::{binary_prefix, Standalone, Prefixed};
@ -76,7 +76,7 @@ impl Informant {
} }
#[cfg_attr(feature="dev", allow(match_bool))] #[cfg_attr(feature="dev", allow(match_bool))]
pub fn tick(&self, client: &Client, maybe_sync: Option<&EthSync>) { pub fn tick<Message>(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService<Message>)>) where Message: Send + Sync + Clone + 'static {
let elapsed = self.last_tick.read().unwrap().elapsed(); let elapsed = self.last_tick.read().unwrap().elapsed();
if elapsed < Duration::from_secs(5) { if elapsed < Duration::from_secs(5) {
return; return;
@ -110,11 +110,13 @@ impl Informant {
paint(Yellow.bold(), format!("{:3}", ((report.gas_processed - last_report.gas_processed) / From::from(elapsed.as_milliseconds() * 1000)).low_u64())), paint(Yellow.bold(), format!("{:3}", ((report.gas_processed - last_report.gas_processed) / From::from(elapsed.as_milliseconds() * 1000)).low_u64())),
match maybe_sync { match maybe_sync {
Some(sync) => { Some((sync, net)) => {
let sync_info = sync.status(); let sync_info = sync.status();
format!("{}/{} peers {} ", let net_config = net.config();
format!("{}/{}/{} peers {} ",
paint(Green.bold(), format!("{:2}", sync_info.num_active_peers)), paint(Green.bold(), format!("{:2}", sync_info.num_active_peers)),
paint(Green.bold(), format!("{:2}", sync_info.num_peers)), paint(Green.bold(), format!("{:2}", sync_info.num_peers)),
paint(Green.bold(), format!("{:2}", net_config.ideal_peers)),
paint(Cyan.bold(), format!("{:>8}", format!("#{}", sync_info.last_imported_block_number.unwrap_or(chain_info.best_block_number)))), paint(Cyan.bold(), format!("{:>8}", format!("#{}", sync_info.last_imported_block_number.unwrap_or(chain_info.best_block_number)))),
) )
} }
@ -128,7 +130,7 @@ impl Informant {
paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(cache_info.total()))), paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(cache_info.total()))),
paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(queue_info.mem_used))), paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(queue_info.mem_used))),
match maybe_sync { match maybe_sync {
Some(sync) => { Some((sync, _)) => {
let sync_info = sync.status(); let sync_info = sync.status();
format!(" {} sync", paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(sync_info.mem_used)))) format!(" {} sync", paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(sync_info.mem_used))))
} }

View File

@ -40,7 +40,9 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
fn timeout(&self, _io: &IoContext<NetSyncMessage>, timer: TimerToken) { fn timeout(&self, _io: &IoContext<NetSyncMessage>, timer: TimerToken) {
if let INFO_TIMER = timer { if let INFO_TIMER = timer {
self.info.tick(&self.client, Some(&self.sync)); if let Some(net) = self.network.upgrade() {
self.info.tick(&self.client, Some((&self.sync, &net)));
}
} }
} }

View File

@ -485,7 +485,7 @@ fn execute_import(conf: Configuration) {
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => { trace!("Skipping block already in chain."); } Err(BlockImportError::Import(ImportError::AlreadyInChain)) => { trace!("Skipping block already in chain."); }
Err(e) => die!("Cannot import block: {:?}", e) Err(e) => die!("Cannot import block: {:?}", e)
} }
informant.tick(client.deref(), None); informant.tick::<&'static ()>(client.deref(), None);
}; };
match format { match format {

View File

@ -78,6 +78,11 @@ impl<Message> NetworkService<Message> where Message: Send + Sync + Clone + 'stat
&self.stats &self.stats
} }
/// Returns network configuration.
pub fn config(&self) -> &NetworkConfiguration {
&self.config
}
/// Returns external url if available. /// Returns external url if available.
pub fn external_url(&self) -> Option<String> { pub fn external_url(&self) -> Option<String> {
let host = self.host.read().unwrap(); let host = self.host.read().unwrap();