Skip to content

Commit

Permalink
feat: improve visibility for runtime performance
Browse files Browse the repository at this point in the history
tracing::span records how long it took to run a block of code and prints
this into into log.

See

https://github.com/near/nearcore/blob/ff01c544ce2675fadbf0284af52b356a383b27a8/docs/architecture.md#runtimenear-vm-runner

for the info on the tracing infra
  • Loading branch information
matklad committed Jul 8, 2021
1 parent ff01c54 commit c81db20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ byteorder = "1.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
log = "0.4"
tracing = "0.1.13"
rand = "0.7"
lazy_static = "1.4"
num-rational = "0.3"
Expand Down
8 changes: 8 additions & 0 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ impl Runtime {
signed_transaction: &SignedTransaction,
stats: &mut ApplyStats,
) -> Result<(Receipt, ExecutionOutcomeWithId), RuntimeError> {
let _span =
tracing::debug_span!(target: "runtime", "Runtime::process_transaction").entered();
near_metrics::inc_counter(&metrics::TRANSACTION_PROCESSED_TOTAL);

match verify_and_charge_transaction(
&apply_state.config,
state_update,
Expand Down Expand Up @@ -817,6 +820,8 @@ impl Runtime {
stats: &mut ApplyStats,
epoch_info_provider: &dyn EpochInfoProvider,
) -> Result<Option<ExecutionOutcomeWithId>, RuntimeError> {
let _span = tracing::debug_span!(target: "runtime", "Runtime::process_receipt").entered();

let account_id = &receipt.receiver_id;
match receipt.receipt {
ReceiptEnum::Data(ref data_receipt) => {
Expand Down Expand Up @@ -1156,9 +1161,12 @@ impl Runtime {
epoch_info_provider: &dyn EpochInfoProvider,
states_to_patch: Option<Vec<StateRecord>>,
) -> Result<ApplyResult, RuntimeError> {
let _span = tracing::debug_span!(target: "runtime", "Runtime::apply").entered();

if states_to_patch.is_some() && !cfg!(feature = "sandbox") {
panic!("Can only patch state in sandbox mode");
}

let trie = Rc::new(trie);
let initial_state = TrieUpdate::new(trie.clone(), root);
let mut state_update = TrieUpdate::new(trie.clone(), root);
Expand Down

0 comments on commit c81db20

Please sign in to comment.