Skip to content

Commit

Permalink
feat(pruner): log stats as an ordered list of segments (#9370)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jul 8, 2024
1 parent 1b41bc8 commit aaa27d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/node/events/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ impl<DB> NodeState<DB> {
hash=?block.hash(),
peers=self.num_connected_peers(),
txs=block.body.len(),
gas=format_gas(block.header.gas_used),
gas_throughput=format_gas_throughput(block.header.gas_used, elapsed),
gas=%format_gas(block.header.gas_used),
gas_throughput=%format_gas_throughput(block.header.gas_used, elapsed),
full=%format!("{:.1}%", block.header.gas_used as f64 * 100.0 / block.header.gas_limit as f64),
base_fee=%format!("{:.2}gwei", block.header.base_fee_per_gas.unwrap_or(0) as f64 / constants::GWEI_TO_WEI as f64),
blobs=block.header.blob_gas_used.unwrap_or(0) / constants::eip4844::DATA_GAS_PER_BLOB,
Expand Down
4 changes: 2 additions & 2 deletions crates/prune/prune/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_primitives::BlockNumber;
use reth_prune_types::{PruneProgress, PruneSegment};
use std::{collections::BTreeMap, time::Duration};
use std::time::Duration;

/// An event emitted by a [Pruner][crate::Pruner].
#[derive(Debug, PartialEq, Eq, Clone)]
Expand All @@ -11,6 +11,6 @@ pub enum PrunerEvent {
Finished {
tip_block_number: BlockNumber,
elapsed: Duration,
stats: BTreeMap<PruneSegment, (PruneProgress, usize)>,
stats: Vec<(PruneSegment, usize, PruneProgress)>,
},
}
9 changes: 3 additions & 6 deletions crates/prune/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use reth_provider::{
use reth_prune_types::{PruneLimiter, PruneMode, PruneProgress, PrunePurpose, PruneSegment};
use reth_static_file_types::StaticFileSegment;
use reth_tokio_util::{EventSender, EventStream};
use std::{
collections::BTreeMap,
time::{Duration, Instant},
};
use std::time::{Duration, Instant};
use tokio::sync::watch;
use tracing::debug;

Expand All @@ -27,7 +24,7 @@ pub type PrunerResult = Result<PruneProgress, PrunerError>;
/// The pruner type itself with the result of [`Pruner::run`]
pub type PrunerWithResult<DB> = (Pruner<DB>, PrunerResult);

type PrunerStats = BTreeMap<PruneSegment, (PruneProgress, usize)>;
type PrunerStats = Vec<(PruneSegment, usize, PruneProgress)>;

/// Pruning routine. Main pruning logic happens in [`Pruner::run`].
#[derive(Debug)]
Expand Down Expand Up @@ -241,7 +238,7 @@ impl<DB: Database> Pruner<DB> {
if output.pruned > 0 {
limiter.increment_deleted_entries_count_by(output.pruned);
pruned += output.pruned;
stats.insert(segment.segment(), (output.progress, output.pruned));
stats.push((segment.segment(), output.pruned, output.progress));
}
} else {
debug!(target: "pruner", segment = ?segment.segment(), ?purpose, "Nothing to prune for the segment");
Expand Down

0 comments on commit aaa27d6

Please sign in to comment.