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

[informant]: MillisecondDuration -> as_millis() #11211

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use ethcore::{
};
use ethcore_service::ClientService;
use cache::CacheConfig;
use informant::{Informant, FullNodeInformantData, MillisecondDuration};
use informant::{Informant, FullNodeInformantData};
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};
use helpers::{to_client_config, execute_upgrades};
use dir::Directories;
Expand Down Expand Up @@ -294,13 +294,13 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
}
client.flush_queue();

let ms = timer.elapsed().as_milliseconds();
let elapsed = timer.elapsed();
let report = client.report();

info!("Import completed in {} seconds, {} headers, {} hdr/s",
ms / 1000,
elapsed.as_secs(),
report.blocks_imported,
(report.blocks_imported * 1000) as u64 / ms,
(report.blocks_imported as u128 * 1000) / elapsed.as_millis(),
);

Ok(())
Expand Down Expand Up @@ -415,16 +415,16 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
user_defaults.save(&user_defaults_path)?;

let report = client.report();

let ms = timer.elapsed().as_milliseconds();
let elapsed = timer.elapsed();
let ms = timer.elapsed().as_millis();
info!("Import completed in {} seconds, {} blocks, {} blk/s, {} transactions, {} tx/s, {} Mgas, {} Mgas/s",
ms / 1000,
elapsed.as_secs(),
report.blocks_imported,
(report.blocks_imported * 1000) as u64 / ms,
(report.blocks_imported as u128 * 1000) / ms,
report.transactions_applied,
(report.transactions_applied * 1000) as u64 / ms,
(report.transactions_applied as u128 * 1000) / ms,
report.gas_processed / 1_000_000,
(report.gas_processed / (ms * 1000)).low_u64(),
report.gas_processed / (ms * 1000),
);
Ok(())
}
Expand Down
30 changes: 8 additions & 22 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

extern crate ansi_term;
use self::ansi_term::Colour::{White, Yellow, Green, Cyan, Blue};
use self::ansi_term::{Colour, Style};

use std::sync::{Arc};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::time::{Instant, Duration};

use ansi_term::Colour::{White, Yellow, Green, Cyan, Blue};
use ansi_term::{Colour, Style};
use atty;
use ethcore::client::Client;
use client_traits::{BlockInfo, ChainInfo, BlockChainClient, ChainNotify};
Expand Down Expand Up @@ -55,18 +53,6 @@ pub fn format_bytes(b: usize) -> String {
}
}

/// Something that can be converted to milliseconds.
pub trait MillisecondDuration {
/// Get the value in milliseconds.
fn as_milliseconds(&self) -> u64;
}

impl MillisecondDuration for Duration {
fn as_milliseconds(&self) -> u64 {
self.as_secs() * 1000 + self.subsec_nanos() as u64 / 1_000_000
}
}

#[derive(Default)]
struct CacheSizes {
sizes: ::std::collections::BTreeMap<&'static str, usize>,
Expand Down Expand Up @@ -308,13 +294,13 @@ impl<T: InformantData> Informant<T> {
paint(White.bold(), format!("{}", chain_info.best_block_hash)),
if self.target.executes_transactions() {
format!("{} blk/s {} tx/s {} Mgas/s",
paint(Yellow.bold(), format!("{:7.2}", (client_report.blocks_imported * 1000) as f64 / elapsed.as_milliseconds() as f64)),
paint(Yellow.bold(), format!("{:6.1}", (client_report.transactions_applied * 1000) as f64 / elapsed.as_milliseconds() as f64)),
paint(Yellow.bold(), format!("{:6.1}", (client_report.gas_processed / 1000).low_u64() as f64 / elapsed.as_milliseconds() as f64))
paint(Yellow.bold(), format!("{:7.2}", (client_report.blocks_imported * 1000) as f64 / elapsed.as_millis() as f64)),
paint(Yellow.bold(), format!("{:6.1}", (client_report.transactions_applied * 1000) as f64 / elapsed.as_millis() as f64)),
paint(Yellow.bold(), format!("{:6.1}", (client_report.gas_processed / 1000).low_u64() as f64 / elapsed.as_millis() as f64))
)
} else {
format!("{} hdr/s",
paint(Yellow.bold(), format!("{:6.1}", (client_report.blocks_imported * 1000) as f64 / elapsed.as_milliseconds() as f64))
paint(Yellow.bold(), format!("{:6.1}", (client_report.blocks_imported * 1000) as f64 / elapsed.as_millis() as f64))
)
},
paint(Green.bold(), format!("{:5}", queue_info.unverified_queue_size)),
Expand Down Expand Up @@ -401,7 +387,7 @@ impl ChainNotify for Informant<FullNodeInformantData> {
Colour::White.bold().paint(format!("{}", header_view.hash())),
Colour::Yellow.bold().paint(format!("{}", block.transactions_count())),
Colour::Yellow.bold().paint(format!("{:.2}", header_view.gas_used().low_u64() as f32 / 1000000f32)),
Colour::Purple.bold().paint(format!("{}", new_blocks.duration.as_milliseconds())),
Colour::Purple.bold().paint(format!("{}", new_blocks.duration.as_millis())),
Colour::Blue.bold().paint(format!("{:.2}", size as f32 / 1024f32)),
if skipped > 0 {
format!(" + another {} block(s) containing {} tx(s)",
Expand Down