moved PerfTimer to a separate crate - "trace-time" (#7985)
This commit is contained in:
committed by
Robert Habermeier
parent
893979b5da
commit
f9d5d618dc
@@ -24,7 +24,6 @@ use itertools::Itertools;
|
||||
|
||||
// util
|
||||
use hash::keccak;
|
||||
use timer::PerfTimer;
|
||||
use bytes::Bytes;
|
||||
use journaldb;
|
||||
use util_error::UtilError;
|
||||
@@ -517,7 +516,7 @@ impl Client {
|
||||
if blocks.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
let _timer = PerfTimer::new("import_verified_blocks");
|
||||
trace_time!("import_verified_blocks");
|
||||
let start = precise_time_ns();
|
||||
|
||||
for block in blocks {
|
||||
@@ -592,7 +591,7 @@ impl Client {
|
||||
let _import_lock = self.import_lock.lock();
|
||||
|
||||
{
|
||||
let _timer = PerfTimer::new("import_old_block");
|
||||
trace_time!("import_old_block");
|
||||
let chain = self.chain.read();
|
||||
let mut ancient_verifier = self.ancient_verifier.lock();
|
||||
|
||||
@@ -888,7 +887,7 @@ impl Client {
|
||||
/// Import transactions from the IO queue
|
||||
pub fn import_queued_transactions(&self, transactions: &[Bytes], peer_id: usize) -> usize {
|
||||
trace!(target: "external_tx", "Importing queued");
|
||||
let _timer = PerfTimer::new("import_queued_transactions");
|
||||
trace_time!("import_queued_transactions");
|
||||
self.queue_transactions.fetch_sub(transactions.len(), AtomicOrdering::SeqCst);
|
||||
let txs: Vec<UnverifiedTransaction> = transactions.iter().filter_map(|bytes| UntrustedRlp::new(bytes).as_val().ok()).collect();
|
||||
let hashes: Vec<_> = txs.iter().map(|tx| tx.hash()).collect();
|
||||
@@ -1927,7 +1926,7 @@ impl MiningBlockChainClient for Client {
|
||||
let route = {
|
||||
// scope for self.import_lock
|
||||
let _import_lock = self.import_lock.lock();
|
||||
let _timer = PerfTimer::new("import_sealed_block");
|
||||
trace_time!("import_sealed_block");
|
||||
|
||||
let number = block.header().number();
|
||||
let block_data = block.rlp_bytes();
|
||||
|
||||
@@ -122,6 +122,8 @@ extern crate macros;
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate trace_time;
|
||||
#[cfg_attr(test, macro_use)]
|
||||
extern crate evm;
|
||||
|
||||
@@ -150,7 +152,6 @@ pub mod snapshot;
|
||||
pub mod spec;
|
||||
pub mod state;
|
||||
pub mod state_db;
|
||||
pub mod timer;
|
||||
pub mod trace;
|
||||
pub mod verification;
|
||||
pub mod views;
|
||||
|
||||
@@ -40,7 +40,6 @@ use ethcore_miner::service_transaction_checker::ServiceTransactionChecker;
|
||||
use miner::{MinerService, MinerStatus};
|
||||
use price_info::fetch::Client as FetchClient;
|
||||
use price_info::{Client as PriceInfoClient, PriceInfo};
|
||||
use timer::PerfTimer;
|
||||
use transaction::{
|
||||
Action,
|
||||
UnverifiedTransaction,
|
||||
@@ -388,7 +387,7 @@ impl Miner {
|
||||
|
||||
/// Prepares new block for sealing including top transactions from queue.
|
||||
fn prepare_block(&self, chain: &MiningBlockChainClient) -> (ClosedBlock, Option<H256>) {
|
||||
let _timer = PerfTimer::new("prepare_block");
|
||||
trace_time!("prepare_block");
|
||||
let chain_info = chain.chain_info();
|
||||
let (transactions, mut open_block, original_work_hash) = {
|
||||
let nonce_cap = if chain_info.best_block_number + 1 >= self.engine.params().dust_protection_transition {
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Performance timer with logging
|
||||
use time::precise_time_ns;
|
||||
|
||||
/// Performance timer with logging. Starts measuring time in the constructor, prints
|
||||
/// elapsed time in the destructor or when `stop` is called.
|
||||
pub struct PerfTimer {
|
||||
name: &'static str,
|
||||
start: u64,
|
||||
stopped: bool,
|
||||
}
|
||||
|
||||
impl PerfTimer {
|
||||
/// Create an instance with given name.
|
||||
pub fn new(name: &'static str) -> PerfTimer {
|
||||
PerfTimer {
|
||||
name: name,
|
||||
start: precise_time_ns(),
|
||||
stopped: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop the timer and print elapsed time on trace level with `perf` target.
|
||||
pub fn stop(&mut self) {
|
||||
if !self.stopped {
|
||||
trace!(target: "perf", "{}: {:.2}ms", self.name, (precise_time_ns() - self.start) as f32 / 1000_000.0);
|
||||
self.stopped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PerfTimer {
|
||||
fn drop(&mut self) {
|
||||
self.stop()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user