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

Tracing for wasm with bridging to native #6916

Merged
134 commits merged into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
e43faeb
implement events handling, implement parent_id for spans & events
mattrutherford Jul 16, 2020
5d0d25a
add events to sp_io::storage
mattrutherford Jul 16, 2020
0b7f4f8
update test
mattrutherford Jul 16, 2020
f7981fc
add tests
mattrutherford Jul 16, 2020
f892b57
adjust limit
mattrutherford Jul 16, 2020
159ac53
Merge remote-tracking branch 'origin/master' into tracing-events
gnunicorn Jul 22, 2020
ffb8713
let tracing crate handle parent_ids
gnunicorn Jul 22, 2020
cc3e5e3
re-enable current-id tracking
gnunicorn Jul 22, 2020
89a9b73
Merge branch 'master' into tracing-events
mattrutherford Jul 22, 2020
38b412c
Merge branch 'tracing-events' of github.com:paritytech/substrate into…
mattrutherford Jul 22, 2020
1855a9a
add test for threads with CurrentSpan
mattrutherford Jul 22, 2020
2081e5d
fix log level
mattrutherford Jul 22, 2020
8da1d7a
remove redundant check for non wasm traces
mattrutherford Jul 22, 2020
64d9863
remove duplicate definition in test
mattrutherford Jul 22, 2020
4dfc683
Adding conditional events API
gnunicorn Jul 23, 2020
c4bac2d
prefer explicit parent_id over current,
mattrutherford Jul 23, 2020
c6d3b5c
Merge branch 'tracing-events' of github.com:paritytech/substrate into…
mattrutherford Jul 23, 2020
f4ee909
limit changes to client::tracing event implementation
mattrutherford Jul 23, 2020
0e14ca5
remove From impl due to fallback required on parent_id
mattrutherford Jul 23, 2020
0b7b16e
Merge branch 'master' into tracing-events
mattrutherford Jul 23, 2020
70492f5
make tracing codecable
gnunicorn Jul 23, 2020
8824a60
replace with global tracing
gnunicorn Jul 23, 2020
e0312a6
new tracing interface
gnunicorn Jul 23, 2020
b81fa39
impl TracingSubscriber in client
mattrutherford Jul 24, 2020
9a4b9a2
implement access to global TracingSubscriber from primitives
mattrutherford Jul 24, 2020
f11e316
Merge remote-tracking branch 'origin' into ben-wasm-tracer
gnunicorn Jul 25, 2020
f824918
span for wasm
gnunicorn Jul 25, 2020
4093d15
increment towards Wasm Tracing Subscriber implementation
mattrutherford Jul 28, 2020
6a8e6b5
increment, remove sp-tracing from runtime-interface
mattrutherford Jul 29, 2020
a812a70
Merge branch 'master' into matt-tracing-wasm
mattrutherford Jul 29, 2020
60430e1
increment, it compiles
mattrutherford Jul 29, 2020
20a4479
attained original functionality with new mechanism
mattrutherford Jul 29, 2020
3fb87a0
implement remaining TracingSubscriber functions
mattrutherford Jul 30, 2020
d3c2a96
Merge branch 'master' into ben-wasm-tracer
mattrutherford Jul 30, 2020
c4dfd7f
Merge branch 'matt-tracing-wasm' into ben-wasm-tracer
mattrutherford Jul 30, 2020
eb6730a
remove spans from decl_module
mattrutherford Jul 30, 2020
1559195
add handling for encoded values
mattrutherford Jul 30, 2020
6a57066
merge master
gnunicorn Aug 11, 2020
bd2d560
Revert "replace with global tracing"
gnunicorn Aug 11, 2020
ca46e02
Wasm Side Tracing
gnunicorn Aug 11, 2020
36318c1
tracing on wasm
gnunicorn Aug 11, 2020
5ee6320
enable tracing wasm on node-runtime
gnunicorn Aug 11, 2020
c319881
export all the macros in std
gnunicorn Aug 11, 2020
b133bcf
tracing subscriber on wasm-side only
gnunicorn Aug 11, 2020
8f54143
pass spans and events over and record them
gnunicorn Aug 11, 2020
94b16d0
reactivate previous code and cleanup
gnunicorn Aug 12, 2020
6b2754b
further cleaning up
gnunicorn Aug 12, 2020
dad8480
extend the span macros, activate through executive
gnunicorn Aug 12, 2020
54d62f7
tracking the actual extrinsic, too
gnunicorn Aug 12, 2020
e5e4c50
style
gnunicorn Aug 12, 2020
59cfdb9
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Aug 12, 2020
f368f1f
fixing tests
gnunicorn Aug 13, 2020
ed6770b
spaces -> tabs
gnunicorn Aug 13, 2020
f26f147
attempting to reactivate params
gnunicorn Aug 14, 2020
44c92e8
activate our tests in CI
gnunicorn Aug 14, 2020
0ee102a
some passing
gnunicorn Aug 14, 2020
da0d131
tests passing
gnunicorn Aug 14, 2020
fe05f04
with core lazy
gnunicorn Aug 14, 2020
8ef3f6a
global tracer for wasm side with pass over
gnunicorn Aug 18, 2020
7ec1784
fixing metadata referencing
gnunicorn Aug 18, 2020
516a27a
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Aug 18, 2020
6f4ecb9
remove const_fn feature requirement
gnunicorn Aug 19, 2020
f29ce39
reenable dispatch traces
gnunicorn Aug 20, 2020
a1e8284
reset client tracing
gnunicorn Aug 20, 2020
f4c9076
further cleaning up
gnunicorn Aug 20, 2020
38e8af5
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Aug 21, 2020
bc4b6b0
fixing runtime-test
gnunicorn Aug 21, 2020
99fcfc8
move tracing-build setup into runtime-test
gnunicorn Aug 21, 2020
001b064
Merge DebugWriter from tracing and frame-support, move to sp-std
gnunicorn Aug 21, 2020
564f88c
remove dangling fixme
gnunicorn Aug 21, 2020
bad9ad0
Docs for tracing primitives
gnunicorn Aug 24, 2020
29c9da7
cleaning up a bit more
gnunicorn Aug 24, 2020
8e76ca7
Wasm interface docs
gnunicorn Aug 24, 2020
21fff39
optimise docs.rs setup
gnunicorn Aug 24, 2020
afd5ef2
adding tracing flags to uncomment
gnunicorn Aug 25, 2020
8cb5800
remove brace
mattrutherford Aug 25, 2020
780fab3
fixing imports
gnunicorn Aug 25, 2020
0880b70
fixing broken syntax
gnunicorn Aug 25, 2020
6c7cb0a
add required modules
mattrutherford Aug 25, 2020
a5185bd
Merge branch 'ben-wasm-tracer' of github.com:paritytech/substrate int…
mattrutherford Aug 25, 2020
d98f5bd
nicer formatting
gnunicorn Aug 25, 2020
a4b92b3
better target management
gnunicorn Aug 25, 2020
d2d74a9
Merge branch 'ben-wasm-tracer' of github.com:paritytech/substrate int…
mattrutherford Aug 25, 2020
85dab68
adding low level storage tracing events into frame
gnunicorn Aug 25, 2020
da0f2b5
Merge branch 'ben-wasm-tracer' of github.com:paritytech/substrate int…
mattrutherford Aug 26, 2020
7394b57
add custom Debug impl for WasmMetadata
mattrutherford Aug 26, 2020
79f278d
cloning profiler
gnunicorn Sep 1, 2020
ec3934c
adding info about cloning profiler
gnunicorn Sep 1, 2020
d9e8e31
using in-scope for within calls
gnunicorn Sep 1, 2020
f68a8e5
proper time tracing, cleaning up println
gnunicorn Sep 1, 2020
7db90f3
allow to disable tracing on runtime_interface-macro
gnunicorn Sep 1, 2020
a08cb44
disable tracing for wasm-tracing-interface
gnunicorn Sep 1, 2020
4395a6c
simplify wasm-tracing-api
gnunicorn Sep 1, 2020
e779202
update client to new interface
gnunicorn Sep 1, 2020
849bccf
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Sep 2, 2020
c2d856d
fixing docs and tests for sp-tracing
gnunicorn Sep 2, 2020
5cbae70
update integration tests
gnunicorn Sep 2, 2020
4d892fa
re-activating enter_span
gnunicorn Sep 2, 2020
d7ab2b6
dropping FIXME, it's documented
gnunicorn Sep 2, 2020
8536f77
fix formatting
gnunicorn Sep 2, 2020
5194d0d
fix formatting
gnunicorn Sep 2, 2020
21eddad
fix imports
gnunicorn Sep 2, 2020
47cb390
more debug info
gnunicorn Sep 3, 2020
e3c6e0a
inform wasm about it being disabled by returning 1
gnunicorn Sep 3, 2020
5fa4a8b
only one tracer, but enabled multi-all support
gnunicorn Sep 3, 2020
3d67c9d
make trait pub again for tests
gnunicorn Sep 3, 2020
4897926
Apply suggestions from code review
gnunicorn Sep 7, 2020
00d0d1c
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Sep 7, 2020
c00dd61
fixing wasm doc tests for proper usage
gnunicorn Sep 7, 2020
88b5957
remove unnecessary import
gnunicorn Sep 7, 2020
7419129
fixing formatting
gnunicorn Sep 7, 2020
38c1e42
minor style fixes
gnunicorn Sep 7, 2020
6d54ad6
downgrading wabt
gnunicorn Sep 7, 2020
7ae8264
update error message for UI
gnunicorn Sep 7, 2020
637d763
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Sep 8, 2020
c69a51e
Fix interface test
gnunicorn Sep 8, 2020
71cca7a
next attempt to fix macros
gnunicorn Sep 9, 2020
97156db
geee
gnunicorn Sep 9, 2020
c7521ed
revert tracing on hashed for future PR
gnunicorn Sep 9, 2020
7a31707
remove local macros, use originals
gnunicorn Sep 9, 2020
3afa77e
we are able to convert to static items
gnunicorn Sep 10, 2020
7b99c9c
implement more WasmValue types
gnunicorn Sep 10, 2020
959c401
adding support to convert str, debug and encoded values
gnunicorn Sep 11, 2020
b9a8658
more minor fixes
gnunicorn Sep 11, 2020
4e960c6
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Sep 11, 2020
4530b81
revert unsafe 'static making
gnunicorn Sep 11, 2020
a7c92bf
fix indentation
gnunicorn Sep 14, 2020
c83834b
remove commented lines
gnunicorn Sep 14, 2020
5381565
bump all them tracing versions
gnunicorn Sep 14, 2020
0f531bb
Merge remote-tracking branch 'origin/master' into ben-wasm-tracer
gnunicorn Sep 17, 2020
6e4e60a
cleaning up docs and info
gnunicorn Sep 17, 2020
ed6ec09
document new flag
gnunicorn Sep 17, 2020
0c17fd1
the new layered system handles span cloning better
gnunicorn Sep 17, 2020
e616c81
Apply suggestions from code review
gnunicorn Sep 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ check-web-wasm:
- time cargo build --target=wasm32-unknown-unknown -p sc-telemetry
# Note: the command below is a bit weird because several Cargo issues prevent us from compiling the node in a more straight-forward way.
- time cargo +nightly build --manifest-path=bin/node/cli/Cargo.toml --no-default-features --features browser --target=wasm32-unknown-unknown -Z features=itarget
# with-tracing must be explicitly activated, we run a test to ensure this works as expected in both cases
- time cargo +nightly test --manifest-path primitives/tracing/Cargo.toml --no-default-features
- time cargo +nightly test --manifest-path primitives/tracing/Cargo.toml --no-default-features --features=with-tracing
- sccache -s

test-full-crypto-feature:
Expand Down
42 changes: 14 additions & 28 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ hex-literal = "0.3.1"
log = "0.4.8"
rand = "0.7.2"
structopt = { version = "0.3.8", optional = true }
tracing = "0.1.18"
tracing = "0.1.19"
parking_lot = "0.10.0"

# primitives
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sp-io = { version = "2.0.0-rc6", path = "../../../primitives/io" }

[features]
default = ["std"]
with-tracing = [ "frame-executive/with-tracing" ]
std = [
"sp-authority-discovery/std",
"pallet-authority-discovery/std",
Expand Down
2 changes: 1 addition & 1 deletion client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test-case = "0.3.3"
sp-runtime = { version = "2.0.0-rc6", path = "../../primitives/runtime" }
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
sc-tracing = { version = "2.0.0-rc6", path = "../tracing" }
tracing = "0.1.18"
tracing = "0.1.19"
tracing-subscriber = "0.2.10"

[features]
Expand Down
2 changes: 2 additions & 0 deletions client/executor/runtime-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ std = [
"sp-io/std",
"sp-sandbox/std",
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
"sp-allocator/std",
]
13 changes: 12 additions & 1 deletion client/executor/runtime-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@
use wasm_builder_runner::WasmBuilder;

fn main() {
// regular build
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder")
.export_heap_base()
.import_memory()
.build()
.build();

// and building with tracing activated
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder")
.export_heap_base()
.import_memory()
.set_file_name("wasm_binary_with_tracing.rs")
.append_to_rust_flags("--cfg feature=\\\"with-tracing\\\"")
.build();
}
4 changes: 2 additions & 2 deletions client/executor/runtime-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ sp_core::wasm_export_functions! {
}

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

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

fn returns_mutable_static() -> u64 {
Expand Down
49 changes: 4 additions & 45 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
// Create subscriber with wasm_tracing disabled
let test_subscriber = tracing_subscriber::fmt().finish().with(
sc_tracing::ProfilingLayer::new_with_handler(
Box::new(handler), "integration_test_span_target"
Box::new(handler), "default"
)
);

Expand All @@ -690,49 +690,9 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
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",
&[],
Default::default(),
wasm_method,
&mut ext,
).unwrap();
Expand All @@ -756,8 +716,7 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {

let span_datum = traces.lock().unwrap().pop().unwrap();
let values = span_datum.values;
assert_eq!(span_datum.target, "integration_test_span_target");
assert_eq!(span_datum.name, "integration_test_span_name");
assert_eq!(span_datum.target, "default");
assert_eq!(span_datum.name, "");
assert_eq!(values.bool_values.get("wasm").unwrap(), &true);
assert_eq!(values.bool_values.get("is_valid_trace").unwrap(), &true);
}
3 changes: 2 additions & 1 deletion client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ sc-telemetry = { version = "2.0.0-rc6", path = "../telemetry" }
sc-offchain = { version = "2.0.0-rc6", path = "../offchain" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc6"}
sc-tracing = { version = "2.0.0-rc6", path = "../tracing" }
tracing = "0.1.18"
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
tracing = "0.1.19"
parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
Expand Down
3 changes: 2 additions & 1 deletion client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ rustc-hash = "1.1.0"
serde = "1.0.101"
serde_json = "1.0.41"
slog = { version = "2.5.2", features = ["nested-values"] }
tracing = "0.1.18"
tracing = "0.1.19"
tracing-core = "0.1.13"
tracing-subscriber = "0.2.10"
sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" }
sc-telemetry = { version = "2.0.0-rc6", path = "../telemetry" }
22 changes: 7 additions & 15 deletions client/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ use tracing::{
use tracing_subscriber::{CurrentSpan, layer::{Layer, Context}};

use sc_telemetry::{telemetry, SUBSTRATE_INFO};
use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER};

use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER};
const ZERO_DURATION: Duration = Duration::from_nanos(0);

/// Responsible for assigning ids to new spans, which are not re-used.
gnunicorn marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -275,12 +274,6 @@ impl<S: Subscriber> Layer<S> for ProfilingLayer {
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, _ctx: Context<S>) {
let mut values = Values::default();
attrs.record(&mut values);
// If this is a wasm trace, check if target/level is enabled
if let Some(wasm_target) = values.string_values.get(WASM_TARGET_KEY) {
if !self.check_target(wasm_target, attrs.metadata().level()) {
return
}
}
let span_datum = SpanDatum {
id: id.clone(),
parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()),
Expand Down Expand Up @@ -327,18 +320,13 @@ impl<S: Subscriber> Layer<S> for ProfilingLayer {
fn on_exit(&self, span: &Id, _ctx: Context<S>) {
self.current_span.exit();
let end_time = Instant::now();
let mut span_data = self.span_data.lock();
if let Some(mut s) = span_data.get_mut(&span) {
s.overall_time = end_time - s.start_time + s.overall_time;
}
}

fn on_close(&self, span: Id, _ctx: Context<S>) {
let span_datum = {
let mut span_data = self.span_data.lock();
span_data.remove(&span)
};

if let Some(mut span_datum) = span_datum {
span_datum.overall_time += end_time - span_datum.start_time;
if span_datum.name == WASM_TRACE_IDENTIFIER {
span_datum.values.bool_values.insert("wasm".to_owned(), true);
if let Some(n) = span_datum.values.string_values.remove(WASM_NAME_KEY) {
Expand All @@ -355,6 +343,10 @@ impl<S: Subscriber> Layer<S> for ProfilingLayer {
}
};
}

fn on_close(&self, span: Id, ctx: Context<S>) {
self.on_exit(&span, ctx)
}
}

/// TraceHandler for sending span data to the logger
Expand Down
39 changes: 22 additions & 17 deletions client/transaction-pool/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,28 @@ where
Client::Api: TaggedTransactionQueue<Block>,
sp_api::ApiErrorFor<Client, Block>: Send + std::fmt::Display,
{
sp_tracing::enter_span!("validate_transaction");
let runtime_api = client.runtime_api();
let has_v2 = sp_tracing::tracing_span! { "check_version";
runtime_api
.has_api_with::<dyn TaggedTransactionQueue<Block, Error=()>, _>(&at, |v| v >= 2)
.unwrap_or_default()
};

sp_tracing::enter_span!("runtime::validate_transaction");
let res = if has_v2 {
runtime_api.validate_transaction(&at, source, uxt)
} else {
#[allow(deprecated)] // old validate_transaction
runtime_api.validate_transaction_before_version_2(&at, uxt)
};

res.map_err(|e| Error::RuntimeApi(e.to_string()))
sp_tracing::within_span!(sp_tracing::Level::TRACE, "validate_transaction";
{
let runtime_api = client.runtime_api();
let has_v2 = sp_tracing::within_span! { sp_tracing::Level::TRACE, "check_version";
runtime_api
.has_api_with::<dyn TaggedTransactionQueue<Block, Error=()>, _>(&at, |v| v >= 2)
.unwrap_or_default()
};

let res = sp_tracing::within_span!(
sp_tracing::Level::TRACE, "runtime::validate_transaction";
{
if has_v2 {
runtime_api.validate_transaction(&at, source, uxt)
} else {
#[allow(deprecated)] // old validate_transaction
runtime_api.validate_transaction_before_version_2(&at, uxt)
}
});

res.map_err(|e| Error::RuntimeApi(e.to_string()))
})
}

impl<Client, Block> FullChainApi<Client, Block>
Expand Down
Loading