Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Runtime interface to add support for tracing from wasm #6381

Merged
merged 93 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
62f4df9
Add span recording to tracing implementation
mattrutherford Apr 27, 2020
e5aa529
Add tracing proxy
mattrutherford Apr 28, 2020
e71eb09
switch to rustc_hash::FxHashMap
mattrutherford Apr 29, 2020
db69268
Replace lazy_static and hashmap with thread_local and vec.
mattrutherford Apr 29, 2020
b43015f
fix marking valid span as invalid while removing invalid spans
mattrutherford Apr 29, 2020
dba7d55
refactor, add wasm_tracing module in `support`
mattrutherford May 6, 2020
5e86ef6
update registered spans
mattrutherford May 6, 2020
35706ca
tidy up
mattrutherford May 6, 2020
1388002
typos
mattrutherford May 6, 2020
41964e7
refactor
mattrutherford May 6, 2020
ad81d3b
update flag name to signal lost trace - `is_valid_trace`
mattrutherford May 6, 2020
2cb66bf
update flag name to signal lost trace - `is_valid_trace`
mattrutherford May 6, 2020
03b7b6e
update docs
mattrutherford May 6, 2020
16b018c
update docs
mattrutherford May 6, 2020
d2af83d
Use tracing Field recording to store the actual `name` and `target`
mattrutherford May 7, 2020
9f8baf2
fix debug log in subscriber + small refactor
mattrutherford May 7, 2020
1199f36
add tests
mattrutherford May 11, 2020
0c61f79
handle misuse in case trying to exit span not held
mattrutherford May 11, 2020
8061da5
Implement filter for wasm traces, simplify field recording for primit…
mattrutherford May 11, 2020
2097aca
remove superfluous warning
mattrutherford May 11, 2020
1ef18e6
update docs
mattrutherford May 11, 2020
60e0b60
Merge branch 'master' into mr-sp-tracing
mattrutherford May 11, 2020
cd8bed8
Merge branch 'master' into mr-sp-tracing
mattrutherford May 12, 2020
460d24d
Update primitives/tracing/src/proxy.rs
mattrutherford May 13, 2020
85bdbe0
Apply suggestions from code review
mattrutherford May 13, 2020
b9d1fdf
update docs, apply suggestions
mattrutherford May 14, 2020
b66bb33
move Proxy from thread_local to `Extension`, rename macro
mattrutherford May 14, 2020
afa511d
fix test
mattrutherford May 15, 2020
93a03a8
unify native & wasm span macro calls
mattrutherford May 15, 2020
2126d8e
implement wasm tracing control facility in primitives and frame
mattrutherford May 15, 2020
0d48517
add cli flag `--wasm-tracing`
mattrutherford May 15, 2020
e01ae89
fix
mattrutherford May 15, 2020
2db5f89
switch to `Option<u4>` (possible performance degradation), switch
mattrutherford May 15, 2020
c9c7e9c
performance improvement using u64 vs Option<u64>
mattrutherford May 15, 2020
e3bdb79
performance improvement moving concat to client
mattrutherford May 15, 2020
10a07a6
update docs
mattrutherford May 18, 2020
2b73ed7
Update client/cli/src/params/import_params.rs
mattrutherford May 18, 2020
cff0aa2
performance improvement
mattrutherford May 18, 2020
27c8a8f
Merge remote-tracking branch 'origin/mr-sp-tracing' into mr-sp-tracing
mattrutherford May 18, 2020
70e6315
Revert "performance improvement"
mattrutherford May 18, 2020
dc335e9
small refactor
mattrutherford May 18, 2020
955fa15
formatting
mattrutherford May 18, 2020
cd563c3
bump impl_version
mattrutherford May 18, 2020
1bc601f
Update client/cli/src/config.rs
mattrutherford May 19, 2020
691129d
Merge branch 'master' into mr-sp-tracing
mattrutherford May 19, 2020
e78dd7e
Merge branch 'master' into mr-sp-tracing
mattrutherford May 20, 2020
22bb40f
Merge branch 'master' into mr-sp-tracing
mattrutherford May 21, 2020
a63e6d5
update docs
mattrutherford May 21, 2020
88d3da1
Merge branch 'master' into mr-sp-tracing
mattrutherford May 28, 2020
7228358
small fixes, remove pub static
mattrutherford May 28, 2020
d735529
nit
mattrutherford May 29, 2020
de94f07
add integration tests and refactor Subscriber
mattrutherford Jun 1, 2020
8901340
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 1, 2020
179a515
tests
mattrutherford Jun 1, 2020
a2fbef3
revert formatting
mattrutherford Jun 1, 2020
74ec338
try fix test that works locally but not in CI
mattrutherford Jun 1, 2020
749657b
try fix test that works locally but not in CI
mattrutherford Jun 1, 2020
248f767
debug test that works locally but not in CI
mattrutherford Jun 1, 2020
19cf0f9
fix test that works locally but not in CI
mattrutherford Jun 1, 2020
ffe508a
remove pub visibility from bool in runtime
mattrutherford Jun 3, 2020
d5ba777
make TracingSpanGuard #[cfg(not(feature = "std"))], update docs, comm…
mattrutherford Jun 4, 2020
25e24c4
make TracingProxy drop implementation conditional on !empty state
mattrutherford Jun 4, 2020
da72fbd
add docs for TraceHandler
mattrutherford Jun 4, 2020
f7adde5
remove blank line
mattrutherford Jun 4, 2020
bed5bcb
update expect message
mattrutherford Jun 4, 2020
6f3602e
update tests
mattrutherford Jun 4, 2020
31b4cc1
merge master
mattrutherford Jun 4, 2020
1f016b9
rename cli option to tracing_enable_wasm
mattrutherford Jun 4, 2020
2a48d0a
rename cli option to tracing_enable_wasm
mattrutherford Jun 4, 2020
01693e0
fix
mattrutherford Jun 4, 2020
19d832c
merge master
mattrutherford Jun 9, 2020
a17775c
ensure wasm-tracing features are wasm only
mattrutherford Jun 9, 2020
2aa7c72
bump impl_version
mattrutherford Jun 9, 2020
3b7044d
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 9, 2020
bc9ec21
bump impl_version
mattrutherford Jun 9, 2020
32b8e36
add `"pallet-scheduler/std"` to `[features]` `std` in node/runtime
mattrutherford Jun 9, 2020
9835a01
refactor service to remove sp_tracing dependency
mattrutherford Jun 10, 2020
50e4c9c
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 10, 2020
8b16881
refactor: line width, trait bounds
mattrutherford Jun 10, 2020
068fd94
improve LogTraceHandler output
mattrutherford Jun 10, 2020
14a90ae
fix test
mattrutherford Jun 10, 2020
95b8832
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 10, 2020
b822794
improve tracing log output
mattrutherford Jun 11, 2020
157a639
Apply suggestions from code review
bkchr Jun 11, 2020
88c3d71
Apply suggestions from code review
mattrutherford Jun 15, 2020
4150780
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 15, 2020
07a0c56
Merge branch 'mr-sp-tracing' of github.com:paritytech/substrate into …
mattrutherford Jun 15, 2020
c36fc2a
swap wasm indication from trace name to a separate value
mattrutherford Jun 15, 2020
ca77a6a
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 15, 2020
d9ebb3b
Update client/tracing/src/lib.rs
bkchr Jun 15, 2020
1811e05
add docs
mattrutherford Jun 16, 2020
d9b314b
remove runtime features
mattrutherford Jun 17, 2020
070abbb
Merge branch 'master' into tracing-host-functions
mattrutherford Jun 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 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 bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ std = [
"pallet-membership/std",
"pallet-multisig/std",
"pallet-identity/std",
"pallet-scheduler/std",
"node-primitives/std",
"sp-offchain/std",
"pallet-offences/std",
Expand Down
3 changes: 3 additions & 0 deletions client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ substrate-test-runtime = { version = "2.0.0-rc3", path = "../../test-utils/runti
sp-state-machine = { version = "0.8.0-rc3", path = "../../primitives/state-machine" }
test-case = "0.3.3"
sp-runtime = { version = "2.0.0-rc3", path = "../../primitives/runtime" }
sp-tracing = { version = "2.0.0-rc3", path = "../../primitives/tracing" }
sc-tracing = { version = "2.0.0-rc3", path = "../tracing" }
tracing = "0.1.14"

[features]
default = [ "std" ]
Expand Down
10 changes: 9 additions & 1 deletion client/executor/runtime-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sp_std::{vec::Vec, vec};
#[cfg(not(feature = "std"))]
use sp_io::{
storage, hashing::{blake2_128, blake2_256, sha2_256, twox_128, twox_256},
crypto::{ed25519_verify, sr25519_verify},
crypto::{ed25519_verify, sr25519_verify}, wasm_tracing,
};
#[cfg(not(feature = "std"))]
use sp_runtime::{print, traits::{BlakeTwo256, Hash}};
Expand Down Expand Up @@ -246,6 +246,14 @@ sp_core::wasm_export_functions! {
sp_allocator::FreeingBumpHeapAllocator::new(0);
}

fn test_enter_span() -> u64 {
wasm_tracing::enter_span("integration_test_span_target", "integration_test_span_name")
}

fn test_exit_span(span_id: u64) {
wasm_tracing::exit_span(span_id)
}

fn returns_mutable_static() -> u64 {
unsafe {
MUTABLE_STATIC += 1;
Expand Down
99 changes: 99 additions & 0 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,102 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) {
t.join().unwrap();
}
}

#[test_case(WasmExecutionMethod::Interpreted)]
fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {

use std::sync::{Arc, Mutex};

use sc_tracing::SpanDatum;

impl sc_tracing::TraceHandler for TestTraceHandler {
fn process_span(&self, sd: SpanDatum) {
self.0.lock().unwrap().push(sd);
}
}

struct TestTraceHandler(Arc<Mutex<Vec<SpanDatum>>>);

let traces = Arc::new(Mutex::new(Vec::new()));
let handler = TestTraceHandler(traces.clone());

// Create subscriber with wasm_tracing disabled
let test_subscriber = sc_tracing::ProfilingSubscriber::new_with_handler(
Box::new(handler), "integration_test_span_target");

let _guard = tracing::subscriber::set_default(test_subscriber);

let mut ext = TestExternalities::default();
let mut ext = ext.ext();

// Test tracing disabled
assert!(!sp_tracing::wasm_tracing_enabled());

let span_id = call_in_wasm(
"test_enter_span",
&[],
wasm_method,
&mut ext,
).unwrap();

assert_eq!(
0u64.encode(),
span_id
);
// Repeat to check span id always 0 when deactivated
let span_id = call_in_wasm(
"test_enter_span",
&[],
wasm_method,
&mut ext,
).unwrap();

assert_eq!(
0u64.encode(),
span_id
);

call_in_wasm(
"test_exit_span",
&span_id.encode(),
wasm_method,
&mut ext,
).unwrap();
// Check span has not been recorded
let len = traces.lock().unwrap().len();
assert_eq!(len, 0);

// Test tracing enabled
sp_tracing::set_wasm_tracing(true);

let span_id = call_in_wasm(
"test_enter_span",
&[],
wasm_method,
&mut ext,
).unwrap();

let span_id = u64::decode(&mut &span_id[..]).unwrap();

assert!(
span_id > 0
);

call_in_wasm(
"test_exit_span",
&span_id.encode(),
wasm_method,
&mut ext,
).unwrap();

// Check there is only the single trace
let len = traces.lock().unwrap().len();
assert_eq!(len, 1);

let span_datum = traces.lock().unwrap().pop().unwrap();
let values = span_datum.values.into_inner();
assert_eq!(span_datum.target, "integration_test_span_target");
assert_eq!(span_datum.name, "integration_test_span_name");
assert_eq!(values.get("wasm").unwrap(), "true");
assert_eq!(values.get("is_valid_trace").unwrap(), "true");
}
2 changes: 2 additions & 0 deletions client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ targets = ["x86_64-unknown-linux-gnu"]
erased-serde = "0.3.9"
log = { version = "0.4.8" }
parking_lot = "0.10.0"
rustc-hash = "1.1.0"
serde = "1.0.101"
serde_json = "1.0.41"
slog = { version = "2.5.2", features = ["nested-values"] }
tracing-core = "0.1.7"
sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" }

sc-telemetry = { version = "2.0.0-rc3", path = "../telemetry" }

Expand Down