Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Add some colours.
  • Loading branch information
tomusdrw committed Aug 9, 2018
commit a9a65adcce85e23234e83f930fe9f05c1afc62d3
40 changes: 31 additions & 9 deletions substrate/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! Console informant. Prints sync progress and block events. Runs on the calling thread.

use ansi_term::Colour;
use std::time::{Duration, Instant};
use futures::{Future, Stream};
use service::{Service, Components};
Expand Down Expand Up @@ -48,15 +49,30 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
let num_peers = sync_status.num_peers;
let best_number: u64 = best_block.number().as_();
let speed = move || speed(best_number, last_number);
let status = match (sync_status.sync.state, sync_status.sync.best_seen_block) {
(SyncState::Idle, _) => "Idle".into(),
(SyncState::Downloading, None) => format!("Syncing {:02.1} bps", speed()),
(SyncState::Downloading, Some(n)) => format!("Syncing {:02.1} bps, target=#{}", speed(), n),
let (status, target) = match (sync_status.sync.state, sync_status.sync.best_seen_block) {
(SyncState::Idle, _) => ("Idle".into(), "".into()),
(SyncState::Downloading, None) => (format!("Syncing{}", speed()), "".into()),
(SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed()), format!(", target=#{}", n)),
};
last_number = Some(best_number);
let txpool_status = txpool.light_status();
info!(target: "substrate", "{} ({} peers), best: #{} ({})", status, sync_status.num_peers, best_number, hash);
telemetry!("system.interval"; "status" => status, "peers" => num_peers, "height" => best_number, "best" => ?hash, "txcount" => txpool_status.transaction_count);
info!(
target: "substrate",
"{}{} ({} peers), best: #{} ({})",
Colour::White.bold().paint(&status),
target,
Colour::White.bold().paint(format!("{}", sync_status.num_peers)),
Colour::White.paint(format!("{}", best_number)),
hash
);
telemetry!(
"system.interval";
"status" => format!("{}{}", status, target),
"peers" => num_peers,
"height" => best_number,
"best" => ?hash,
"txcount" => txpool_status.transaction_count
);
} else {
warn!("Error getting best block information");
}
Expand All @@ -80,10 +96,16 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
handle.spawn(exit.until(informant_work).map(|_| ()));
}

fn speed(best_number: u64, last_number: Option<u64>) -> f64 {
match last_number {
Some(num) => (best_number.saturating_sub(num) * 10_000 / TIMER_INTERVAL_MS) as f64 / 10.0,
fn speed(best_number: u64, last_number: Option<u64>) -> String {
let speed = match last_number {
Some(num) => (best_number.saturating_sub(num) * 10_000 / TIMER_INTERVAL_MS) as f64,
None => 0.0
};

if speed < 1.0 {
"".into()
} else {
format!(" {:4.1} bps", speed / 10.0)
}
}