Skip to content

Commit

Permalink
refactor: use external crate for displaying tracing spans
Browse files Browse the repository at this point in the history
When debugging #4771, I had to copy-paste tracing_timings module to get
a useful profiling output, which isn't ideal. So I improved and
published that code to crates.io as `tracing-span-tree`.

In particular, this new implementation prints the trace in the correct
order, and it also has an `.aggregate(true)` mode for cases where you
run the profiled code in a loop and want a summary.
  • Loading branch information
matklad authored and mina86 committed Sep 7, 2021
1 parent ab4ae83 commit 46f41b9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 92 deletions.
17 changes: 13 additions & 4 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions runtime/near-vm-runner-standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ clap = "=3.0.0-beta.2"
base64 = "0.13"
strum = "0.20"
num-rational = "0.3"
tracing = "0.1"
tracing-subscriber = "0.2"
tracing-span-tree = "0.1"

near-vm-logic = { path = "../near-vm-logic", version = "3.0.0", features = ["costs_counting"]}
near-vm-runner = { path = "../near-vm-runner", version = "3.0.0", features = ["wasmtime_vm", "wasmer1_vm"] }
Expand Down
3 changes: 1 addition & 2 deletions runtime/near-vm-runner-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! Optional `--context-file=/tmp/context.json --config-file=/tmp/config.json` could be added
//! to provide custom context and VM config.
mod script;
mod tracing_timings;

use crate::script::Script;
use clap::Clap;
Expand Down Expand Up @@ -121,7 +120,7 @@ fn main() {
let cli_args = CliArgs::parse();

if cli_args.timings {
tracing_timings::enable();
tracing_span_tree::span_tree().enable();
}

let mut script = Script::default();
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner-standalone/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn default_vm_context() -> VMContext {
fn vm_script_smoke_test() {
use near_vm_logic::ReturnData;

crate::tracing_timings::enable();
tracing_span_tree::span_tree().enable();

let mut script = Script::default();
script.contract_cache(true);
Expand Down Expand Up @@ -242,7 +242,7 @@ fn profile_data_is_per_outcome() {
fn test_evm_slow_deserialize_repro() {
fn evm_slow_deserialize_repro(vm_kind: VMKind) {
println!("evm_slow_deserialize_repro of {:?}", &vm_kind);
crate::tracing_timings::enable();
tracing_span_tree::span_tree().enable();

let mut script = Script::default();
script.vm_kind(vm_kind);
Expand Down
78 changes: 0 additions & 78 deletions runtime/near-vm-runner-standalone/src/tracing_timings.rs

This file was deleted.

4 changes: 2 additions & 2 deletions runtime/near-vm-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ tracing_subscriber::fmt::Subscriber::builder()
code_to_profile_here();
```

Alternatively, in the `standalone` crate we have a more compact hierarchical subscriber
Alternatively, there's an alternative hierarchical profiler

```rust
crate::tracing_timings::enable();
tracing_span_tree::span_tree().enable();;

code_to_profile_here();
```
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime-params-estimator/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn slow() {
metrics_to_measure: Some(vec!["ActionDeployContractBase".to_string()]),
};

tracing_span_tree::enable_aggregated();
tracing_span_tree::span_tree().enable();
let mut ctx = Ctx::new(&config);
action_deploy_contract_base(&mut ctx);
}
Expand Down Expand Up @@ -469,6 +469,6 @@ fn fast() {
s.blocks.push(block)
}

tracing_span_tree::enable_aggregated();
tracing_span_tree::span_tree().enable();
s.run().unwrap();
}

0 comments on commit 46f41b9

Please sign in to comment.