mirror of
https://github.com/romanz/electrs.git
synced 2025-02-24 15:02:21 +01:00
Remove progress bar (to be replaced by Prometheus monitoring)
This commit is contained in:
parent
4d783a3898
commit
1f2fb6e4a0
4 changed files with 1 additions and 66 deletions
|
@ -14,7 +14,6 @@ chan-signal = "0.3"
|
|||
error-chain = "0.11"
|
||||
hex = "0.3"
|
||||
log = "0.4"
|
||||
pbr = "1.0"
|
||||
prometheus = "0.4"
|
||||
rocksdb = "0.10"
|
||||
rust-crypto = "0.2"
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::str::FromStr;
|
|||
use std::sync::Mutex;
|
||||
|
||||
use metrics::{HistogramOpts, HistogramVec, Metrics};
|
||||
use util::{self, HeaderList};
|
||||
use util::HeaderList;
|
||||
|
||||
use errors::*;
|
||||
|
||||
|
@ -329,16 +329,12 @@ impl Daemon {
|
|||
let all_heights: Vec<usize> = (0..tip_height + 1).collect();
|
||||
let chunk_size = 100_000;
|
||||
let mut result = vec![];
|
||||
let mut bar = util::new_progress_bar(all_heights.len());
|
||||
bar.message("Headers: ");
|
||||
let null_hash = Sha256dHash::default();
|
||||
for heights in all_heights.chunks(chunk_size) {
|
||||
let mut headers = self.getblockheaders(&heights)?;
|
||||
assert!(headers.len() == heights.len());
|
||||
bar.add(headers.len() as u64);
|
||||
result.append(&mut headers);
|
||||
}
|
||||
bar.finish();
|
||||
|
||||
let mut blockhash = null_hash;
|
||||
for header in &result {
|
||||
|
|
|
@ -7,7 +7,6 @@ extern crate bitcoin;
|
|||
extern crate chan_signal;
|
||||
extern crate crypto;
|
||||
extern crate hex;
|
||||
extern crate pbr;
|
||||
extern crate prometheus;
|
||||
extern crate rocksdb;
|
||||
extern crate serde;
|
||||
|
|
59
src/util.rs
59
src/util.rs
|
@ -1,12 +1,9 @@
|
|||
use bitcoin::blockdata::block::BlockHeader;
|
||||
use bitcoin::network::serialize::BitcoinHash;
|
||||
use bitcoin::util::hash::Sha256dHash;
|
||||
use pbr;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::io::{stderr, Stderr};
|
||||
use std::iter::FromIterator;
|
||||
use std::time::{Duration, Instant};
|
||||
use time;
|
||||
|
||||
pub type Bytes = Vec<u8>;
|
||||
|
@ -190,59 +187,3 @@ impl HeaderList {
|
|||
self.headers.len()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Timer {
|
||||
start: Instant,
|
||||
metrics: HashMap<&'static str, Duration>,
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
pub fn new() -> Timer {
|
||||
Timer {
|
||||
start: Instant::now(),
|
||||
metrics: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, tag: &'static str) {
|
||||
let new = Instant::now();
|
||||
let elapsed = new.duration_since(self.start);
|
||||
let duration = self.metrics.entry(tag).or_insert(Duration::from_secs(0));
|
||||
*duration += elapsed;
|
||||
self.start = new;
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Timer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut items: Vec<String> = self.metrics
|
||||
.iter()
|
||||
.map(|(k, v)| format!("{}: {}", k, humanize(v)))
|
||||
.collect();
|
||||
items.sort();
|
||||
let total = self.metrics
|
||||
.values()
|
||||
.fold(Duration::from_secs(0), |acc, d| acc + *d);
|
||||
write!(f, "took {} ({})", humanize(&total), items.join(", "))
|
||||
}
|
||||
}
|
||||
|
||||
const HOUR: f32 = 3600.0;
|
||||
const MINUTE: f32 = 60.0;
|
||||
|
||||
fn humanize(d: &Duration) -> String {
|
||||
let seconds = d.as_secs() as f32 + (d.subsec_nanos() as f32 * 1e-9);
|
||||
if seconds >= HOUR {
|
||||
format!("{:.2}h", seconds / HOUR)
|
||||
} else if seconds >= MINUTE {
|
||||
format!("{:.2}m", seconds / MINUTE)
|
||||
} else if seconds >= 1.0 {
|
||||
format!("{:.2}s", seconds)
|
||||
} else {
|
||||
format!("{:.2}ms", seconds * 1e3)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_progress_bar(count: usize) -> pbr::ProgressBar<Stderr> {
|
||||
pbr::ProgressBar::on(stderr(), count as u64)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue