-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
217 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
core/src/block_strider/subscriber/metrics_subscriber.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
use anyhow::Result; | ||
use everscale_types::models::{AccountStatus, ComputePhase, InMsg, MsgInfo, OutMsg, TxInfo}; | ||
use tycho_block_util::block::BlockStuff; | ||
|
||
use crate::block_strider::{ | ||
BlockSubscriber, BlockSubscriberContext, StateSubscriber, StateSubscriberContext, | ||
}; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct MetricsSubscriber; | ||
|
||
impl BlockSubscriber for MetricsSubscriber { | ||
type HandleBlockFut<'a> = futures_util::future::Ready<Result<()>>; | ||
|
||
fn handle_block(&self, cx: &BlockSubscriberContext) -> Self::HandleBlockFut<'_> { | ||
if let Err(e) = handle_block(&cx.block) { | ||
tracing::error!("failed to handle block: {e:?}"); | ||
} | ||
futures_util::future::ready(Ok(())) | ||
} | ||
} | ||
|
||
impl StateSubscriber for MetricsSubscriber { | ||
type HandleStateFut<'a> = futures_util::future::Ready<Result<()>>; | ||
|
||
fn handle_state(&self, cx: &StateSubscriberContext) -> Self::HandleStateFut<'_> { | ||
if let Err(e) = handle_block(&cx.block) { | ||
tracing::error!("failed to handle block: {e:?}"); | ||
} | ||
futures_util::future::ready(Ok(())) | ||
} | ||
} | ||
|
||
fn handle_block(block: &BlockStuff) -> Result<()> { | ||
let block_id = block.id(); | ||
let info = block.as_ref().load_info()?; | ||
let extra = block.as_ref().load_extra()?; | ||
|
||
let mut in_msg_count: u32 = 0; | ||
for descr in extra.in_msg_description.load()?.iter() { | ||
let (_, _, in_msg) = descr?; | ||
in_msg_count += matches!( | ||
in_msg, | ||
InMsg::External(_) | InMsg::Immediate(_) | InMsg::Final(_) | ||
) as u32; | ||
} | ||
|
||
let mut out_msgs_count: u32 = 0; | ||
for descr in extra.out_msg_description.load()?.iter() { | ||
let (_, _, out_msg) = descr?; | ||
out_msgs_count += matches!(out_msg, OutMsg::New(_) | OutMsg::Immediate(_)) as u32; | ||
} | ||
|
||
let mut transaction_count = 0u32; | ||
let mut message_count = 0u32; | ||
let mut ext_message_count = 0u32; | ||
let mut account_blocks_count = 0u32; | ||
let mut contract_deployments = 0u32; | ||
let mut contract_destructions = 0u32; | ||
let mut total_gas_used = 0; | ||
|
||
let account_blocks = extra.account_blocks.load()?; | ||
for entry in account_blocks.iter() { | ||
let (_, _, account_block) = entry?; | ||
account_blocks_count += 1; | ||
|
||
for entry in account_block.transactions.iter() { | ||
let (_, _, tx) = entry?; | ||
let tx = tx.load()?; | ||
|
||
transaction_count += 1; | ||
message_count += tx.in_msg.is_some() as u32 + tx.out_msg_count.into_inner() as u32; | ||
|
||
if let Some(in_msg) = tx.load_in_msg()? { | ||
ext_message_count += matches!(&in_msg.info, MsgInfo::ExtIn(_)) as u32; | ||
} | ||
|
||
let was_active = tx.orig_status == AccountStatus::Active; | ||
let is_active = tx.end_status == AccountStatus::Active; | ||
|
||
contract_deployments += (!was_active && is_active) as u32; | ||
contract_destructions += (was_active && !is_active) as u32; | ||
|
||
total_gas_used += 'gas: { | ||
match tx.load_info()? { | ||
TxInfo::Ordinary(info) => { | ||
if let ComputePhase::Executed(phase) = &info.compute_phase { | ||
break 'gas phase.gas_used.into_inner(); | ||
} | ||
} | ||
TxInfo::TickTock(info) => { | ||
if let ComputePhase::Executed(phase) = &info.compute_phase { | ||
break 'gas phase.gas_used.into_inner(); | ||
} | ||
} | ||
}; | ||
|
||
0 | ||
}; | ||
} | ||
} | ||
|
||
let out_in_message_ratio = if in_msg_count > 0 { | ||
out_msgs_count as f64 / in_msg_count as f64 | ||
} else { | ||
0.0 | ||
}; | ||
let out_message_account_ratio = if account_blocks_count > 0 { | ||
out_msgs_count as f64 / account_blocks_count as f64 | ||
} else { | ||
0.0 | ||
}; | ||
|
||
let labels = &[("workchain", block_id.shard.workchain().to_string())]; | ||
metrics::histogram!("tycho_bc_software_version", labels).record(info.gen_software.version); | ||
metrics::histogram!("tycho_bc_in_msg_count", labels).record(in_msg_count); | ||
metrics::histogram!("tycho_bc_out_msg_count", labels).record(out_msgs_count); | ||
|
||
metrics::counter!("tycho_bc_txs_total", labels).increment(transaction_count as _); | ||
metrics::counter!("tycho_bc_msgs_total", labels).increment(message_count as _); | ||
metrics::counter!("tycho_bc_ext_msgs_total", labels).increment(ext_message_count as _); | ||
|
||
metrics::counter!("tycho_bc_contract_deploy_total", labels) | ||
.increment(contract_deployments as _); | ||
metrics::counter!("tycho_bc_contract_delete_total", labels) | ||
.increment(contract_destructions as _); | ||
|
||
metrics::histogram!("tycho_bc_total_gas_used", labels).record(total_gas_used as f64); | ||
metrics::histogram!("tycho_bc_out_in_msg_ratio", labels).record(out_in_message_ratio); | ||
metrics::histogram!("tycho_bc_out_msg_acc_ratio", labels).record(out_message_account_ratio); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.