Skip to content

Commit

Permalink
feat(collator): add handle_state histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jun 11, 2024
1 parent 52f4410 commit a3cf4fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions collator/src/state_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
use std::time::Instant;

use anyhow::{Context, Result};
use async_trait::async_trait;
Expand All @@ -8,6 +9,7 @@ use tokio::sync::{broadcast, Mutex};
use tycho_block_util::block::{BlockStuff, BlockStuffAug};
use tycho_block_util::state::ShardStateStuff;
use tycho_storage::{BlockHandle, Storage};
use tycho_util::metrics::HistogramGuard;

use crate::tracing_targets;
use crate::types::BlockStuffForSync;
Expand Down Expand Up @@ -147,6 +149,8 @@ impl StateNodeAdapter for StateNodeAdapterStdImpl {
}

async fn handle_state(&self, state: &ShardStateStuff) -> Result<()> {
let _histogram = HistogramGuard::begin("tycho_collator_adapter_handle_state_time");

tracing::debug!(target: tracing_targets::STATE_NODE_ADAPTER, "Handle block: {}", state.block_id().as_short_id());
let block_id = *state.block_id();

Expand Down Expand Up @@ -176,15 +180,25 @@ impl StateNodeAdapter for StateNodeAdapterStdImpl {

match block {
None => {
let _histogram = HistogramGuard::begin(
"tycho_collator_adapter_on_block_accepted_ext_time",
);

tracing::info!(target: tracing_targets::STATE_NODE_ADAPTER, "Block handled external: {:?}", block_id);
self.listener.on_block_accepted_external(state).await?;
}
Some(block) => {
let _histogram =
HistogramGuard::begin("tycho_collator_adapter_on_block_accepted_time");

tracing::info!(target: tracing_targets::STATE_NODE_ADAPTER, "Block handled: {:?}", block_id);
self.listener.on_block_accepted(&block.block_id).await?;
}
}
} else {
let _histogram =
HistogramGuard::begin("tycho_collator_adapter_on_block_accepted_alt_ext_time");

tracing::info!(target: tracing_targets::STATE_NODE_ADAPTER, "Block handled external. Shard ID not found in blocks buffer: {:?}", block_id);
self.listener.on_block_accepted_external(state).await?;
}
Expand Down
14 changes: 14 additions & 0 deletions scripts/gen-dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ def collator_do_collate() -> RowPanel:
create_heatmap_panel("tycho_do_collate_execute_time", "Execution time"),
create_heatmap_panel("tycho_do_collate_build_block_time", "Build block time"),
create_heatmap_panel("tycho_do_collate_update_state_time", "Update state time"),
create_heatmap_panel(
"tycho_collator_adapter_handle_state_time", "Handle state by collator"
),
create_heatmap_panel(
"tycho_collator_adapter_on_block_accepted_ext_time",
"on_block_accepted_external with blocks guard",
),
create_heatmap_panel(
"tycho_collator_adapter_on_block_accepted_alt_ext_time",
"on_block_accepted_external without blocks guard",
),
create_heatmap_panel(
"tycho_collator_adapter_on_block_accepted_time", "on_block_accepted"
),
]
return create_row("Collator Do Collate", metrics)

Expand Down

0 comments on commit a3cf4fb

Please sign in to comment.