From e43faebadc74137e7e76fd6ac94f68b584b8b871 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 16 Jul 2020 13:31:46 +0100 Subject: [PATCH 001/113] implement events handling, implement parent_id for spans & events --- Cargo.lock | 74 ++++++++++++++++++++-- client/tracing/Cargo.toml | 1 + client/tracing/src/lib.rs | 112 +++++++++++++++++++++++++++++----- primitives/tracing/src/lib.rs | 18 ++++++ 4 files changed, 185 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6cdc764d9d0f2..4500250c5dcd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3157,6 +3157,15 @@ dependencies = [ "libc", ] +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.8" @@ -5782,6 +5791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ "byteorder", + "regex-syntax", ] [[package]] @@ -7029,6 +7039,7 @@ dependencies = [ "sp-tracing", "tracing", "tracing-core", + "tracing-subscriber", ] [[package]] @@ -7299,6 +7310,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "0.1.1" @@ -7822,6 +7842,7 @@ dependencies = [ "sp-tracing", "sp-trie", "sp-wasm-interface", + "tracing", ] [[package]] @@ -9161,9 +9182,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c6b59d116d218cb2d990eb06b77b64043e0268ef7323aae63d8b30ae462923" +checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" dependencies = [ "cfg-if", "tracing-attributes", @@ -9172,9 +9193,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" dependencies = [ "proc-macro2", "quote 1.0.6", @@ -9183,11 +9204,52 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.10" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-log" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" +checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" dependencies = [ "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659" +dependencies = [ + "ansi_term 0.11.0", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec 1.4.1", + "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index c4564e5fe53f5..a1c846f67bf8c 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -20,6 +20,7 @@ serde = "1.0.101" serde_json = "1.0.41" slog = { version = "2.5.2", features = ["nested-values"] } tracing-core = "0.1.7" +tracing-subscriber = "0.2.7" sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc4", path = "../telemetry" } diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index c62b8d5b1e9c9..0b5f3c9d4d4b3 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -40,12 +40,15 @@ use tracing_core::{ span::{Attributes, Id, Record}, subscriber::Subscriber, }; +use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; +// To ensure we don't accumulate too many associated events +const LEN_LIMIT: usize = 128; /// Used to configure how to receive the metrics #[derive(Debug, Clone)] @@ -66,12 +69,25 @@ impl Default for TracingReceiver { pub trait TraceHandler: Send + Sync { /// Process a `SpanDatum` fn process_span(&self, span: SpanDatum); + /// Process a `TraceEvent` + fn process_event(&self, event: TraceEvent); +} + +/// Represents a tracing event, complete with values +#[derive(Debug)] +pub struct TraceEvent { + pub name: &'static str, + pub target: String, + pub level: Level, + pub visitor: Visitor, + pub parent_id: Option, } /// Represents a single instance of a tracing span #[derive(Debug)] pub struct SpanDatum { pub id: u64, + pub parent_id: Option, pub name: String, pub target: String, pub level: Level, @@ -79,6 +95,16 @@ pub struct SpanDatum { pub start_time: Instant, pub overall_time: Duration, pub values: Visitor, + pub events: Vec, +} + +/// Responsible for assigning ids to new spans, which are not re-used. +pub struct ProfilingSubscriber { + next_id: AtomicU64, + targets: Vec<(String, Level)>, + trace_handler: Box, + span_data: Mutex>, + current_span: CurrentSpan, } /// Holds associated values for a tracing span @@ -154,14 +180,6 @@ impl Value for Visitor { } } -/// Responsible for assigning ids to new spans, which are not re-used. -pub struct ProfilingSubscriber { - next_id: AtomicU64, - targets: Vec<(String, Level)>, - trace_handler: Box, - span_data: Mutex>, -} - impl ProfilingSubscriber { /// Takes a `TracingReceiver` and a comma separated list of targets, /// either with a level: "pallet=trace,frame=debug" @@ -191,6 +209,7 @@ impl ProfilingSubscriber { targets, trace_handler, span_data: Mutex::new(FxHashMap::default()), + current_span: Default::default() } } @@ -244,6 +263,7 @@ impl Subscriber for ProfilingSubscriber { } let span_datum = SpanDatum { id, + parent_id: self.current_span.id().map(|p| p.into_u64()), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -251,6 +271,7 @@ impl Subscriber for ProfilingSubscriber { start_time: Instant::now(), overall_time: ZERO_DURATION, values, + events: Vec::new(), }; self.span_data.lock().insert(id, span_datum); Id::from_u64(id) @@ -265,9 +286,44 @@ impl Subscriber for ProfilingSubscriber { fn record_follows_from(&self, _span: &Id, _follows: &Id) {} - fn event(&self, _event: &Event<'_>) {} + fn event(&self, event: &Event<'_>) { + let mut visitor = Visitor(FxHashMap::default()); + event.record(&mut visitor); + let trace_event = TraceEvent { + name: event.metadata().name(), + target: event.metadata().target().to_owned(), + level: event.metadata().level().clone(), + visitor, + parent_id: self.current_span.id().map(|id| id.into_u64()), + }; + // Q: Should all events be emitted immediately, rather than grouping with parent span? + match trace_event.parent_id { + Some(parent_id) => { + if let Some(span) = self.span_data.lock().get_mut(&parent_id) { + if span.events.len() > LEN_LIMIT { + log::warn!( + target: "tracing", + "Accumulated too many events for span id: {}, sending event separately", + parent_id + ); + self.trace_handler.process_event(trace_event); + } else { + span.events.push(trace_event); + } + } else { + log::warn!( + target: "tracing", + "Parent span missing" + ); + self.trace_handler.process_event(trace_event); + } + } + None => self.trace_handler.process_event(trace_event), + } + } fn enter(&self, span: &Id) { + self.current_span.enter(span.clone()); let mut span_data = self.span_data.lock(); let start_time = Instant::now(); if let Some(mut s) = span_data.get_mut(&span.into_u64()) { @@ -276,6 +332,7 @@ impl Subscriber for ProfilingSubscriber { } fn exit(&self, span: &Id) { + 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.into_u64()) { @@ -323,23 +380,40 @@ impl TraceHandler for LogTraceHandler { fn process_span(&self, span_datum: SpanDatum) { if span_datum.values.0.is_empty() { log::log!( - log_level(span_datum.level), - "{}: {}, time: {}", + log_level(span_datum.level), + "{}: {}, time: {}, id: {}, parent_id: {:?}, events: {:?}", span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), + span_datum.id, + span_datum.parent_id, + span_datum.events, ); } else { log::log!( log_level(span_datum.level), - "{}: {}, time: {}, {}", + "{}: {}, time: {}, id: {}, parent_id: {:?}, values: {}, events: {:?}", span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), + span_datum.id, + span_datum.parent_id, span_datum.values, + span_datum.events, ); } } + + fn process_event(&self, event: TraceEvent) { + log::log!( + log_level(event.level), + "{}: {}, parent_id: {:?}, values: {}", + event.name, + event.target, + event.parent_id, + event.visitor + ); + } } /// TraceHandler for sending span data to telemetry, @@ -349,12 +423,22 @@ pub struct TelemetryTraceHandler; impl TraceHandler for TelemetryTraceHandler { fn process_span(&self, span_datum: SpanDatum) { - telemetry!(SUBSTRATE_INFO; "tracing.profiling"; + telemetry!(SUBSTRATE_INFO; "tracing.span"; "name" => span_datum.name, "target" => span_datum.target, - "line" => span_datum.line, "time" => span_datum.overall_time.as_nanos(), + "id" => span_datum.id, + "parent_id" => span_datum.parent_id, "values" => span_datum.values ); } + + fn process_event(&self, event: TraceEvent) { + telemetry!(SUBSTRATE_INFO; "tracing.event"; + "name" => event.name, + "target" => event.target, + "parent_id" => event.parent_id, + "values" => event.visitor + ); + } } diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index e82d8861cd3f5..0469ec1c49137 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -93,6 +93,24 @@ macro_rules! enter_span { } } +/// Create a tracing Event +/// +/// See the documentation for the tracing::event! macro for details +/// +/// # Example +/// +/// ``` +/// sp_tracing::tracing_event!(key = "value", "test-event"); +/// ``` +#[macro_export] +macro_rules! tracing_event { + ( $( $code:tt )* ) => { + $crate::if_tracing!( + $crate::tracing::event!( $( $code )* ) + ); + } +} + /// Generates the given code if the tracing dependency is enabled. #[macro_export] #[cfg(feature = "std")] From 5d0d25a2e4e0e32a5c13467af32f5e3041f8d652 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 16 Jul 2020 14:26:23 +0100 Subject: [PATCH 002/113] add events to sp_io::storage --- primitives/io/Cargo.toml | 2 ++ primitives/io/src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 06df2cc5ed6c4..2dbe44a2c470d 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -25,6 +25,7 @@ sp-runtime-interface = { version = "2.0.0-rc4", default-features = false, path = sp-trie = { version = "2.0.0-rc4", optional = true, path = "../../primitives/trie" } sp-externalities = { version = "0.8.0-rc4", optional = true, path = "../externalities" } sp-tracing = { version = "2.0.0-rc4", default-features = false, path = "../tracing" } +tracing = { version = "0.1.16", optional = true } log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } @@ -45,6 +46,7 @@ std = [ "log", "futures", "parking_lot", + "tracing" ] # These two features are used for `no_std` builds for the environments which already provides diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 6c99a5c75195b..4d86d8e5f2e9c 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -100,12 +100,25 @@ pub trait Storage { /// Set `key` to `value` in the storage. fn set(&mut self, key: &[u8], value: &[u8]) { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + ?key, + ?value, + "set" + ); self.set_storage(key.to_vec(), value.to_vec()); } /// Clear the storage of the given `key` and its value. fn clear(&mut self, key: &[u8]) { - self.clear_storage(key) + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + ?key, + "clear" + ); + self.clear_storage(key); } /// Check whether the given `key` exists in storage. @@ -115,7 +128,13 @@ pub trait Storage { /// Clear the storage of each key-value pair where the key starts with the given `prefix`. fn clear_prefix(&mut self, prefix: &[u8]) { - Externalities::clear_prefix(*self, prefix) + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + ?prefix, + "clear_prefix" + ); + Externalities::clear_prefix(*self, prefix); } /// Append the encoded `value` to the storage item at `key`. @@ -127,6 +146,13 @@ pub trait Storage { /// If the storage item does not support [`EncodeAppend`](codec::EncodeAppend) or /// something else fails at appending, the storage item will be set to `[value]`. fn append(&mut self, key: &[u8], value: Vec) { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + ?key, + ?value, + "append" + ); self.storage_append(key.to_vec(), value); } @@ -136,6 +162,11 @@ pub trait Storage { /// /// Returns a `Vec` that holds the SCALE encoded hash. fn root(&mut self) -> Vec { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + "root" + ); self.storage_root() } @@ -147,6 +178,12 @@ pub trait Storage { /// Returns `Some(Vec)` which holds the SCALE encoded hash or `None` when /// changes trie is disabled. fn changes_root(&mut self, parent_hash: &[u8]) -> Option> { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + ?parent_hash, + "changes_root" + ); self.storage_changes_root(parent_hash) .expect("Invalid `parent_hash` given to `changes_root`.") } @@ -169,6 +206,11 @@ pub trait Storage { /// in unbalanced transactions. For example, FRAME users should use high level storage /// abstractions. fn start_transaction(&mut self) { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + "start_transaction" + ); self.storage_start_transaction(); } @@ -180,6 +222,11 @@ pub trait Storage { /// /// Will panic if there is no open transaction. fn rollback_transaction(&mut self) { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + "rollback_transaction" + ); self.storage_rollback_transaction() .expect("No open transaction that can be rolled back."); } @@ -192,6 +239,11 @@ pub trait Storage { /// /// Will panic if there is no open transaction. fn commit_transaction(&mut self) { + #[cfg(feature = "std")] + tracing::event!( + tracing::Level::INFO, + "commit_transaction" + ); self.storage_commit_transaction() .expect("No open transaction that can be committed."); } From 0b7f4f8cc5a0dc02587f2c2614adc8177ccce3d4 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 16 Jul 2020 14:33:13 +0100 Subject: [PATCH 003/113] update test --- client/executor/src/integration_tests/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 21924270b8c1e..c0019e8dc70a3 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -662,12 +662,14 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { use std::sync::{Arc, Mutex}; - use sc_tracing::SpanDatum; + use sc_tracing::{SpanDatum, TraceEvent}; impl sc_tracing::TraceHandler for TestTraceHandler { fn process_span(&self, sd: SpanDatum) { self.0.lock().unwrap().push(sd); } + + fn process_event(&self, _event: TraceEvent) {} } struct TestTraceHandler(Arc>>); From f7981fcdca6e35f49928194ac862994c4583ecd2 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 16 Jul 2020 15:15:45 +0100 Subject: [PATCH 004/113] add tests --- client/tracing/Cargo.toml | 2 +- client/tracing/src/lib.rs | 107 ++++++++++++++++++++++++++++++++++ primitives/tracing/src/lib.rs | 18 ------ 3 files changed, 108 insertions(+), 19 deletions(-) diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index a1c846f67bf8c..77a8967eca259 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -26,4 +26,4 @@ sp-tracing = { version = "2.0.0-rc2", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc4", path = "../telemetry" } [dev-dependencies] -tracing = "0.1.10" +tracing = "0.1.16" diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 0b5f3c9d4d4b3..e8c322439fb05 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -442,3 +442,110 @@ impl TraceHandler for TelemetryTraceHandler { ); } } + +#[cfg(test)] +mod tests { + use super::*; + use std::sync::Arc; + + struct TestTraceHandler{ + spans: Arc>>, + events: Arc>>, + } + + impl TraceHandler for TestTraceHandler { + fn process_span(&self, sd: SpanDatum) { + self.spans.lock().push(sd); + } + + fn process_event(&self, event: TraceEvent) { + self.events.lock().push(event); + } + } + + fn setup_subscriber() -> (ProfilingSubscriber, Arc>>, Arc>>) { + let spans = Arc::new(Mutex::new(Vec::new())); + let events = Arc::new(Mutex::new(Vec::new())); + let handler = TestTraceHandler { + spans: spans.clone(), + events: events.clone(), + }; + let test_subscriber = ProfilingSubscriber::new_with_handler( + Box::new(handler), + "test_target" + ); + (test_subscriber, spans, events) + } + + #[test] + fn test_span() { + let (sub, spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + let span = tracing::info_span!(target: "test_target", "test_span1"); + assert_eq!(spans.lock().len(), 0); + assert_eq!(events.lock().len(), 0); + let _guard = span.enter(); + assert_eq!(spans.lock().len(), 0); + assert_eq!(events.lock().len(), 0); + drop(_guard); + drop(span); + assert_eq!(spans.lock().len(), 1); + assert_eq!(events.lock().len(), 0); + let sd = spans.lock().remove(0); + assert_eq!(sd.name, "test_span1"); + assert_eq!(sd.target, "test_target"); + let time: u128 = sd.overall_time.as_nanos(); + assert!(time > 0); + } + + #[test] + fn test_span_parent_id() { + let (sub, spans, _events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + let span2 = tracing::info_span!(target: "test_target", "test_span2"); + let _guard2 = span2.enter(); + drop(_guard2); + drop(span2); + let sd2 = spans.lock().remove(0); + drop(_guard1); + drop(span1); + let sd1 = spans.lock().remove(0); + assert_eq!(sd1.id, sd2.parent_id.unwrap()) + } + + #[test] + fn test_event() { + let (sub, _spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event"); + let mut te1 = events.lock().remove(0); + assert_eq!(te1.visitor.0.remove(&"message".to_owned()).unwrap(), "test_event".to_owned()); + } + + #[test] + fn test_event_parent_id() { + let (sub, spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + + // enter span + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + + // emit event + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event"); + + //exit span + drop(_guard1); + drop(span1); + + // check span is not emitted separately + assert!(events.lock().is_empty()); + + let sd1 = spans.lock().remove(0); + + // Check span contains the event + assert_eq!(sd1.events.len(), 1); + } +} \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 0469ec1c49137..e82d8861cd3f5 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -93,24 +93,6 @@ macro_rules! enter_span { } } -/// Create a tracing Event -/// -/// See the documentation for the tracing::event! macro for details -/// -/// # Example -/// -/// ``` -/// sp_tracing::tracing_event!(key = "value", "test-event"); -/// ``` -#[macro_export] -macro_rules! tracing_event { - ( $( $code:tt )* ) => { - $crate::if_tracing!( - $crate::tracing::event!( $( $code )* ) - ); - } -} - /// Generates the given code if the tracing dependency is enabled. #[macro_export] #[cfg(feature = "std")] From f892b57dd218b96d04449623c3a969a42372d7f4 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 16 Jul 2020 15:28:29 +0100 Subject: [PATCH 005/113] adjust limit --- client/tracing/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index e8c322439fb05..bd02b41fc39be 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -48,7 +48,7 @@ use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; // To ensure we don't accumulate too many associated events -const LEN_LIMIT: usize = 128; +const LEN_LIMIT: usize = 256; /// Used to configure how to receive the metrics #[derive(Debug, Clone)] From ffb871374138f1f6dfddbe3c78d855a64484b1c5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 22 Jul 2020 14:54:45 +0200 Subject: [PATCH 006/113] let tracing crate handle parent_ids --- client/tracing/src/lib.rs | 105 ++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 60 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 3a6bac73fa18c..a10b57e7e5271 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -39,15 +39,12 @@ use tracing_core::{ span::{Attributes, Id, Record}, subscriber::Subscriber, }; -use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; -// To ensure we don't accumulate too many associated events -const LEN_LIMIT: usize = 256; /// Used to configure how to receive the metrics #[derive(Debug, Clone)] @@ -79,15 +76,30 @@ pub struct TraceEvent { pub target: String, pub level: Level, pub values: Values, - pub parent_id: Option, + pub parent_id: Option, +} + +impl From<&Event<'_>> for TraceEvent { + fn from(event: &Event<'_>) -> TraceEvent { + let mut values = Values::new(); + event.record(&mut values); + TraceEvent { + name: event.metadata().name(), + target: event.metadata().target().to_owned(), + level: event.metadata().level().clone(), + parent_id: event.parent().cloned(), + values, + } + } } /// Represents a single instance of a tracing span #[derive(Debug)] pub struct SpanDatum { /// id for this span - pub id: u64, - pub parent_id: Option, + pub id: Id, + /// + pub parent_id: Option, /// Name of the span pub name: String, /// Target, typically module @@ -102,6 +114,7 @@ pub struct SpanDatum { pub overall_time: Duration, /// Values recorded to this span pub values: Values, + /// pub events: Vec, } @@ -110,8 +123,7 @@ pub struct ProfilingSubscriber { next_id: AtomicU64, targets: Vec<(String, Level)>, trace_handler: Box, - span_data: Mutex>, - current_span: CurrentSpan, + span_data: Mutex>, } /// Holds associated values for a tracing span @@ -246,8 +258,7 @@ impl ProfilingSubscriber { next_id: AtomicU64::new(1), targets, trace_handler, - span_data: Mutex::new(FxHashMap::default()), - current_span: Default::default() + span_data: Mutex::new(Default::default()), } } @@ -290,18 +301,18 @@ impl Subscriber for ProfilingSubscriber { } fn new_span(&self, attrs: &Attributes<'_>) -> Id { - let id = self.next_id.fetch_add(1, Ordering::Relaxed); + let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed)); 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 Id::from_u64(id); + return id } } let span_datum = SpanDatum { - id, - parent_id: self.current_span.id().map(|p| p.into_u64()), + id: id.clone(), + parent_id: attrs.parent().cloned(), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -311,13 +322,13 @@ impl Subscriber for ProfilingSubscriber { values, events: Vec::new(), }; - self.span_data.lock().insert(id, span_datum); - Id::from_u64(id) + self.span_data.lock().insert(id.clone(), span_datum); + id } fn record(&self, span: &Id, values: &Record<'_>) { let mut span_data = self.span_data.lock(); - if let Some(s) = span_data.get_mut(&span.into_u64()) { + if let Some(s) = span_data.get_mut(&span) { values.record(&mut s.values); } } @@ -325,55 +336,29 @@ impl Subscriber for ProfilingSubscriber { fn record_follows_from(&self, _span: &Id, _follows: &Id) {} fn event(&self, event: &Event<'_>) { - let mut values = Values::new(); - event.record(&mut values); - let trace_event = TraceEvent { - name: event.metadata().name(), - target: event.metadata().target().to_owned(), - level: event.metadata().level().clone(), - values, - parent_id: self.current_span.id().map(|id| id.into_u64()), - }; - // Q: Should all events be emitted immediately, rather than grouping with parent span? - match trace_event.parent_id { - Some(parent_id) => { - if let Some(span) = self.span_data.lock().get_mut(&parent_id) { - if span.events.len() > LEN_LIMIT { - log::warn!( - target: "tracing", - "Accumulated too many events for span id: {}, sending event separately", - parent_id - ); - self.trace_handler.process_event(trace_event); - } else { - span.events.push(trace_event); - } - } else { - log::warn!( - target: "tracing", - "Parent span missing" - ); - self.trace_handler.process_event(trace_event); - } + let event : TraceEvent = event.into(); + if let Some(parent_id) = event.parent_id.as_ref() { + if let Some(span) = self.span_data.lock().get_mut(parent_id) { + span.events.push(event); + return; } - None => self.trace_handler.process_event(trace_event), } + + self.trace_handler.process_event(event); } fn enter(&self, span: &Id) { - self.current_span.enter(span.clone()); let mut span_data = self.span_data.lock(); let start_time = Instant::now(); - if let Some(mut s) = span_data.get_mut(&span.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.start_time = start_time; } } fn exit(&self, span: &Id) { - 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.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.overall_time = end_time - s.start_time + s.overall_time; } } @@ -381,7 +366,7 @@ impl Subscriber for ProfilingSubscriber { fn try_close(&self, span: Id) -> bool { let span_datum = { let mut span_data = self.span_data.lock(); - span_data.remove(&span.into_u64()) + span_data.remove(&span) }; if let Some(mut span_datum) = span_datum { if span_datum.name == WASM_TRACE_IDENTIFIER { @@ -423,8 +408,8 @@ impl TraceHandler for LogTraceHandler { span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), - span_datum.id, - span_datum.parent_id, + span_datum.id.into_u64(), + span_datum.parent_id.map(|s| s.into_u64()), span_datum.events, ); } else { @@ -434,8 +419,8 @@ impl TraceHandler for LogTraceHandler { span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), - span_datum.id, - span_datum.parent_id, + span_datum.id.into_u64(), + span_datum.parent_id.map(|s| s.into_u64()), span_datum.values, span_datum.events, ); @@ -465,8 +450,8 @@ impl TraceHandler for TelemetryTraceHandler { "name" => span_datum.name, "target" => span_datum.target, "time" => span_datum.overall_time.as_nanos(), - "id" => span_datum.id, - "parent_id" => span_datum.parent_id, + "id" => span_datum.id.into_u64(), + "parent_id" => span_datum.parent_id.map(|i| i.into_u64()), "values" => span_datum.values ); } @@ -475,7 +460,7 @@ impl TraceHandler for TelemetryTraceHandler { telemetry!(SUBSTRATE_INFO; "tracing.event"; "name" => event.name, "target" => event.target, - "parent_id" => event.parent_id, + "parent_id" => event.parent_id.map(|i| i.into_u64()), "values" => event.values ); } From cc3e5e3d6827d6a66c455c9609eb8a535797fa44 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 22 Jul 2020 15:27:09 +0200 Subject: [PATCH 007/113] re-enable current-id tracking --- client/tracing/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index a10b57e7e5271..af245b2592b5f 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -29,7 +29,7 @@ use std::fmt; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{Duration, Instant}; -use parking_lot::Mutex; +use parking_lot::{RwLock, Mutex}; use serde::ser::{Serialize, Serializer, SerializeMap}; use tracing_core::{ event::Event, @@ -124,6 +124,7 @@ pub struct ProfilingSubscriber { targets: Vec<(String, Level)>, trace_handler: Box, span_data: Mutex>, + current_span: RwLock>, } /// Holds associated values for a tracing span @@ -259,6 +260,7 @@ impl ProfilingSubscriber { targets, trace_handler, span_data: Mutex::new(Default::default()), + current_span: RwLock::new(None), } } @@ -312,7 +314,7 @@ impl Subscriber for ProfilingSubscriber { } let span_datum = SpanDatum { id: id.clone(), - parent_id: attrs.parent().cloned(), + parent_id: attrs.parent().cloned().or_else(|| self.current_span.read().clone()), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -336,7 +338,10 @@ impl Subscriber for ProfilingSubscriber { fn record_follows_from(&self, _span: &Id, _follows: &Id) {} fn event(&self, event: &Event<'_>) { - let event : TraceEvent = event.into(); + let mut event : TraceEvent = event.into(); + if event.parent_id.is_none() { + event.parent_id = self.current_span.read().clone(); + } if let Some(parent_id) = event.parent_id.as_ref() { if let Some(span) = self.span_data.lock().get_mut(parent_id) { span.events.push(event); @@ -348,6 +353,7 @@ impl Subscriber for ProfilingSubscriber { } fn enter(&self, span: &Id) { + *self.current_span.write() = Some(span.clone()); let mut span_data = self.span_data.lock(); let start_time = Instant::now(); if let Some(mut s) = span_data.get_mut(&span) { @@ -360,6 +366,9 @@ impl Subscriber for ProfilingSubscriber { 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; + *self.current_span.write() = s.parent_id.clone() + } else { + *self.current_span.write() = None } } @@ -544,7 +553,7 @@ mod tests { let _sub_guard = tracing::subscriber::set_default(sub); tracing::event!(target: "test_target", tracing::Level::INFO, "test_event"); let mut te1 = events.lock().remove(0); - assert_eq!(te1.values.0.remove(&"message".to_owned()).unwrap(), "test_event".to_owned()); + assert_eq!(te1.values.string_values.remove(&"message".to_owned()).unwrap(), "test_event".to_owned()); } #[test] From 1855a9aecad44827866873f440d550add7cd73cf Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 22 Jul 2020 16:42:18 +0100 Subject: [PATCH 008/113] add test for threads with CurrentSpan --- client/tracing/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 827015f211b7b..7def338fd60f4 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -599,4 +599,56 @@ mod tests { assert_eq!(sd1.id, te1.parent_id.unwrap()); } + #[test] + fn test_parent_id_with_threads() { + use std::sync::mpsc; + + let (sub, spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_global_default(sub); + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + + let (tx, rx) = mpsc::channel(); + let handle = std::thread::spawn(move || { + let span2 = tracing::info_span!(target: "test_target", "test_span2"); + let _guard2 = span2.enter(); + // emit event + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event1"); + for msg in rx.recv() { + if msg == false { + break; + } + } + // gard2 and span2 dropped / exited + }); + + // wait for Event to be dispatched and stored + while events.lock().is_empty() { + std::thread::sleep(Duration::from_millis(1)); + } + + // emit new event while span2 still active in other thread - (will be second item in Vec) + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event2"); + + // stop thread and drop span + let _ = tx.send(false); + let _ = handle.join(); + + // wait for Span to be dispatched and stored + while spans.lock().is_empty() { + std::thread::sleep(Duration::from_millis(1)); + } + let span2 = spans.lock().remove(0); + let event1 = events.lock().remove(0); + drop(_guard1); + drop(span1); + let span1 = spans.lock().remove(0); + let event2 = events.lock().remove(0); + + assert_eq!(event1.values.string_values.get("message").unwrap(), "test_event1"); + assert_eq!(event2.values.string_values.get("message").unwrap(), "test_event2"); + assert_eq!(span2.id, event1.parent_id.unwrap()); + assert_eq!(span1.id, event2.parent_id.unwrap()); + assert_ne!(span2.id, span1.id); + } } From 2081e5d3da6fb038628dc838991090d31eb0be69 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 22 Jul 2020 17:06:53 +0100 Subject: [PATCH 009/113] fix log level --- client/cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index c7f48d2721468..51a16fc3efb1b 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -239,7 +239,7 @@ pub fn init_logger(pattern: &str) { builder.filter(Some("hyper"), log::LevelFilter::Warn); builder.filter(Some("cranelift_wasm"), log::LevelFilter::Warn); // Always log the special target `sc_tracing`, overrides global level - builder.filter(Some("sc_tracing"), log::LevelFilter::Info); + builder.filter(Some("sc_tracing"), log::LevelFilter::Trace); // Enable info for others. builder.filter(None, log::LevelFilter::Info); From 8da1d7a1bd445392e7e95d1ac34c10975807bdc1 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 22 Jul 2020 17:07:56 +0100 Subject: [PATCH 010/113] remove redundant check for non wasm traces --- client/tracing/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 7def338fd60f4..447fe826da786 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -380,8 +380,10 @@ impl Subscriber for ProfilingSubscriber { if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { span_datum.target = t; } - } - if self.check_target(&span_datum.target, &span_datum.level) { + if self.check_target(&span_datum.target, &span_datum.level) { + self.trace_handler.handle_span(span_datum); + } + } else { self.trace_handler.handle_span(span_datum); } }; @@ -627,7 +629,7 @@ mod tests { std::thread::sleep(Duration::from_millis(1)); } - // emit new event while span2 still active in other thread - (will be second item in Vec) + // emit new event (will be second item in Vec) while span2 still active in other thread tracing::event!(target: "test_target", tracing::Level::INFO, "test_event2"); // stop thread and drop span From 64d9863f22be7df39bd6dc9a1be86fdf1290774b Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 22 Jul 2020 18:09:08 +0100 Subject: [PATCH 011/113] remove duplicate definition in test --- client/executor/src/integration_tests/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 999886a2bb6d3..c2398a4a5886c 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -674,8 +674,6 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { fn handle_event(&self, _event: TraceEvent) {} } - struct TestTraceHandler(Arc>>); - let traces = Arc::new(Mutex::new(Vec::new())); let handler = TestTraceHandler(traces.clone()); From 4dfc683d5f3610f7939dd5ba6a3be77aa305d608 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 23 Jul 2020 11:57:00 +0200 Subject: [PATCH 012/113] Adding conditional events API --- client/transaction-pool/Cargo.toml | 2 +- frame/executive/Cargo.toml | 5 +- frame/executive/src/lib.rs | 25 +- frame/support/Cargo.toml | 5 +- primitives/tracing/Cargo.toml | 5 +- primitives/tracing/src/lib.rs | 406 +++++++++++++++++++++++++++-- 6 files changed, 419 insertions(+), 29 deletions(-) diff --git a/client/transaction-pool/Cargo.toml b/client/transaction-pool/Cargo.toml index 6ae3f5a8abbf3..8fd4c48a0e859 100644 --- a/client/transaction-pool/Cargo.toml +++ b/client/transaction-pool/Cargo.toml @@ -26,7 +26,7 @@ sc-transaction-graph = { version = "2.0.0-rc5", path = "./graph" } sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } sp-core = { version = "2.0.0-rc5", path = "../../primitives/core" } sp-runtime = { version = "2.0.0-rc5", path = "../../primitives/runtime" } -sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } +sp-tracing = { version = "2.0.0-rc5", features = ["with-tracing"], path = "../../primitives/tracing" } sp-transaction-pool = { version = "2.0.0-rc5", path = "../../primitives/transaction-pool" } sp-blockchain = { version = "2.0.0-rc5", path = "../../primitives/blockchain" } sp-utils = { version = "2.0.0-rc5", path = "../../primitives/utils" } diff --git a/frame/executive/Cargo.toml b/frame/executive/Cargo.toml index fdc49628a42cb..90f2cb6b671c1 100644 --- a/frame/executive/Cargo.toml +++ b/frame/executive/Cargo.toml @@ -31,7 +31,7 @@ pallet-transaction-payment = { version = "2.0.0-rc5", path = "../transaction-pay sp-version = { version = "2.0.0-rc5", path = "../../primitives/version" } [features] -default = ["std"] +default = ["std", "with-tracing"] std = [ "codec/std", "frame-support/std", @@ -41,3 +41,6 @@ std = [ "sp-tracing/std", "sp-std/std", ] +with-tracing = [ + "sp-tracing/with-tracing" +] diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 24dccf8b0b4a4..e3ea70e4d7538 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -197,7 +197,7 @@ impl< COnRuntimeUpgrade: OnRuntimeUpgrade, > Executive where - Block::Extrinsic: Checkable + Codec, + Block::Extrinsic: Checkable + tg vbhghhhhggc, CheckedOf: Applyable + GetDispatchInfo, @@ -207,6 +207,7 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "initialize block" }; let digests = Self::extract_pre_digest(&header); Self::initialize_block_impl( header.number(), @@ -270,6 +271,7 @@ where } fn initial_checks(block: &Block) { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "initial checks" }; let header = block.header(); // Check that `parent_hash` is correct. @@ -309,12 +311,19 @@ where /// Execute given extrinsics and take care of post-extrinsics book-keeping. fn execute_extrinsics_with_book_keeping(extrinsics: Vec, block_number: NumberFor) { - extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); + { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "executing extrinsics" }; + extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); + } - // post-extrinsics book-keeping - >::note_finished_extrinsics(); - as OnFinalize>::on_finalize(block_number); - >::on_finalize(block_number); + { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "finalizing" }; + // post-extrinsics book-keeping + >::note_finished_extrinsics(); + + as OnFinalize>::on_finalize(block_number); + >::on_finalize(block_number); + } } /// Finalize the block - it is up the caller to ensure that all header fields are valid @@ -355,6 +364,9 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "applying extrinsic"}; + // FIXME: add support for Codec + // sp_tracing::event!(sp_tracing::Level::INFO, extrinsic = ?uxt); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; @@ -377,6 +389,7 @@ where } fn final_checks(header: &System::Header) { + sp_tracing::enter_span! { sp_tracing::Level::INFO, "final checks" }; // remove temporaries let new_header = >::finalize(); diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 24e898e1692fa..40867f316e4cb 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -37,7 +37,7 @@ frame-system = { version = "2.0.0-rc5", path = "../system" } parity-util-mem = { version = "0.7.0", features = ["primitive-types"] } [features] -default = ["std"] +default = ["std", "with-tracing"] std = [ "once_cell", "bitmask/std", @@ -52,6 +52,9 @@ std = [ "sp-inherents/std", "sp-state-machine", ] +with-tracing = [ + "sp-tracing/with-tracing" +] nightly = [] strict = [] runtime-benchmarks = [] diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index fc3d311298dde..e4fdf3cac780a 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,10 +12,11 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -tracing = { version = "0.1.13", optional = true } +tracing = { version = "0.1.13", optional = true, default-features = false } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } [features] default = [ "std" ] -std = [ "tracing", "rental", "log" ] +with-tracing = [ "tracing" ] +std = [ "with-tracing", "tracing/std", "rental", "log" ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index e82d8861cd3f5..caf0eb76ab421 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,14 +30,20 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "with-tracing")] +use core::{module_path, format_args}; + #[cfg(feature = "std")] #[macro_use] extern crate rental; -#[cfg(feature = "std")] +#[cfg(feature = "with-tracing")] #[doc(hidden)] pub use tracing; +#[cfg(feature = "with-tracing")] +pub use tracing::Level; + #[cfg(feature = "std")] pub mod proxy; @@ -55,7 +61,14 @@ static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); /// # Example /// /// ``` -/// sp_tracing::tracing_span! { +/// sp_tracing::tracing_span! { // default level LEVEL:TRACE +/// "test-span"; +/// 1 + 1; +/// // some other complex code +/// } +/// +/// sp_tracing::tracing_span! { // specified log level +/// Level::DEBUG, /// "test-span"; /// 1 + 1; /// // some other complex code @@ -71,39 +84,396 @@ macro_rules! tracing_span { $crate::enter_span!($name); $( $code )* } - } + }; + ( + $lvl:expr, + $name:expr; + $( $code:tt )* + ) => { + { + $crate::enter_span!($lvl, $name); + $( $code )* + } + }; } /// Enter a span. /// -/// The span will be valid, until the scope is left. +/// The span will be valid, until the scope is left. noop unless `with-tracing`-feature is enabled /// /// # Example /// /// ``` -/// sp_tracing::enter_span!("test-span"); +/// sp_tracing::enter_span!("test-span"); // defaults to Level::TRACE +/// sp_tracing::enter_span!(sp_tracing::Level::DEBUG, "debug-span"); /// ``` #[macro_export] +#[cfg(feature = "with-tracing")] macro_rules! enter_span { - ( $name:expr ) => { - let __tracing_span__ = $crate::if_tracing!( - $crate::tracing::span!($crate::tracing::Level::TRACE, $name) - ); - let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); - } + ( $name:expr ) => ({ + $crate::enter_span!($crate::tracing::Level::TRACE, $name); + }); + ( $lvl:expr, $name:expr ) => ({ + // FIXME: we need to make the variable names based on $name or they might overlap + let __tracing_span__ = $crate::tracing::span!($lvl, $name); + let __tracing_guard__ = __tracing_span__.enter(); + }); } -/// Generates the given code if the tracing dependency is enabled. + +/// Enter a span. +/// +/// The span will be valid, until the scope is left. noop unless `with-tracing`-feature is enabled +/// +/// # Example +/// +/// ``` +/// sp_tracing::enter_span!("test-span"); // defaults to Level::TRACE +/// sp_tracing::enter_span!(sp_tracing::Level::DEBUG, "debug-span"); +/// ``` #[macro_export] -#[cfg(feature = "std")] -macro_rules! if_tracing { - ( $if:expr ) => {{ $if }} +#[cfg(not(feature = "with-tracing"))] +macro_rules! enter_span { + ( $name:expr ) => ({ {} }); + ( $lvl:expr, $name:expr ) => ({ {} }); } +/// Trace an Event. +/// +/// see `tracing`-crate for details on usage +/// noop if `with-tracing`-feature is not enabled. +#[macro_export] +#[cfg(feature = "with-tracing")] +macro_rules! event { + + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + $crate::tracing::event!(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($k).+ = $($fields)* }) + }); + + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::tracing::event!( + target: $target, + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) + ); + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) + }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::tracing::event!( + target: $target, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!(target: $target, $lvl, { $($arg)+ }) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + parent: $parent, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { $($k).+ = $($field)*} + ) + ); + ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { $($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { ?$($k).+, $($field)*} + ) + ); + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + target: module_path!(), + $lvl, + { %$($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+) => ( + $crate::tracing::event!($lvl, ?$($k).+,) + ); + ($lvl:expr, %$($k:ident).+) => ( + $crate::tracing::event!($lvl, %$($k).+,) + ); + ($lvl:expr, $($k:ident).+) => ( + $crate::tracing::event!($lvl, $($k).+,) + ); + ( $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!(target: module_path!(), $lvl, { $($arg)+ }) + ); + + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::tracing::event!(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($k).+ = $($fields)* }, { $($arg)+ }) + }); + + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) + ); + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::tracing::event!( + target: $target, + $lvl, + { $($k).+ = $($fields)* }, + { $($arg)+ } + ) + }); + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!(target: $target, $lvl, { $($arg)+ }) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { $($k).+ = $($fields)* }, + { $($arg)+ } + ) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + $lvl, + parent: $parent, + { $($k).+ = $($fields)* }, + { $($arg)+ } + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + parent: $parent, + $lvl, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!(parent: $parent, $lvl, { $($arg)+ }) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + $lvl, + { $($arg)+, $($fields)* } + ) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::tracing::event!( + $lvl, + { $($arg)+, $($fields)* } + ) + ); + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::tracing::event!( + $lvl, + { $($k).+ = $($field)*} + ) + ); + ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + $lvl, + { $($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + $lvl, + { ?$($k).+, $($field)*} + ) + ); + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::tracing::event!( + $lvl, + { %$($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+) => ( + $crate::tracing::event!($lvl, ?$($k).+,) + ); + ($lvl:expr, %$($k:ident).+) => ( + $crate::tracing::event!($lvl, %$($k).+,) + ); + ($lvl:expr, $($k:ident).+) => ( + $crate::tracing::event!($lvl, $($k).+,) + ); + ( $lvl:expr, $($arg:tt)+ ) => ( + $crate::tracing::event!($lvl, { $($arg)+ }) + ); +} + +/// Trace an Event. +/// +/// see `tracing`-crate for details on usage +/// noop if `with-tracing`-feature is not enabled. #[macro_export] -#[cfg(not(feature = "std"))] -macro_rules! if_tracing { - ( $if:expr ) => {{}} +#[cfg(not(feature = "with-tracing"))] +macro_rules! event { + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ {} }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ({ {} }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ({ {} }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ {} }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ({ {} }); + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ({ {} }); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ({ {} }); + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ({ {} }); + ($lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + ($lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ({ {} }); + ($lvl:expr, $($k:ident).+, $($field:tt)*) => ({ {} }); + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ({ {} }); + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ({ {} }); + ($lvl:expr, ?$($k:ident).+) => ({ {} }); + ($lvl:expr, %$($k:ident).+) => ({ {} }); + ($lvl:expr, $($k:ident).+) => ({ {} }); + ($lvl:expr, $($arg:tt)+ ) => ({ {} }); } #[cfg(feature = "std")] From c4bac2d1b12109b9763f2d5818c815e6f2f9fb4a Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 23 Jul 2020 11:36:56 +0100 Subject: [PATCH 013/113] prefer explicit parent_id over current, enhance test --- client/tracing/src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 447fe826da786..8cfaa7844cf80 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -313,7 +313,7 @@ impl Subscriber for ProfilingSubscriber { } let span_datum = SpanDatum { id: id.clone(), - parent_id: self.current_span.id(), + parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -343,7 +343,7 @@ impl Subscriber for ProfilingSubscriber { target: event.metadata().target().to_owned(), level: event.metadata().level().clone(), values, - parent_id: self.current_span.id(), + parent_id: event.parent().cloned().or_else(|| self.current_span.id()), }; self.trace_handler.handle_event(trace_event); } @@ -604,6 +604,7 @@ mod tests { #[test] fn test_parent_id_with_threads() { use std::sync::mpsc; + use std::thread; let (sub, spans, events) = setup_subscriber(); let _sub_guard = tracing::subscriber::set_global_default(sub); @@ -611,7 +612,7 @@ mod tests { let _guard1 = span1.enter(); let (tx, rx) = mpsc::channel(); - let handle = std::thread::spawn(move || { + let handle = thread::spawn(move || { let span2 = tracing::info_span!(target: "test_target", "test_span2"); let _guard2 = span2.enter(); // emit event @@ -626,7 +627,7 @@ mod tests { // wait for Event to be dispatched and stored while events.lock().is_empty() { - std::thread::sleep(Duration::from_millis(1)); + thread::sleep(Duration::from_millis(1)); } // emit new event (will be second item in Vec) while span2 still active in other thread @@ -638,19 +639,34 @@ mod tests { // wait for Span to be dispatched and stored while spans.lock().is_empty() { - std::thread::sleep(Duration::from_millis(1)); + thread::sleep(Duration::from_millis(1)); } let span2 = spans.lock().remove(0); let event1 = events.lock().remove(0); drop(_guard1); drop(span1); + + // emit event with no parent + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event3"); + let span1 = spans.lock().remove(0); let event2 = events.lock().remove(0); assert_eq!(event1.values.string_values.get("message").unwrap(), "test_event1"); assert_eq!(event2.values.string_values.get("message").unwrap(), "test_event2"); + assert!(span1.parent_id.is_none()); + assert!(span2.parent_id.is_none()); assert_eq!(span2.id, event1.parent_id.unwrap()); assert_eq!(span1.id, event2.parent_id.unwrap()); assert_ne!(span2.id, span1.id); + + let event3 = events.lock().remove(0); + assert!(event3.parent_id.is_none()); } } + +struct WasmSpan<'a>{ + name: &'a str, + target: &'a str, + data: &'a +} From f4ee909b29386037bdaf424844877c7375011b73 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 23 Jul 2020 14:56:17 +0100 Subject: [PATCH 014/113] limit changes to client::tracing event implementation --- Cargo.lock | 1 - client/tracing/src/lib.rs | 6 - client/transaction-pool/Cargo.toml | 2 +- frame/executive/Cargo.toml | 5 +- frame/executive/src/lib.rs | 25 +- frame/support/Cargo.toml | 5 +- primitives/io/Cargo.toml | 2 - primitives/io/src/lib.rs | 56 +--- primitives/tracing/Cargo.toml | 5 +- primitives/tracing/src/lib.rs | 406 ++--------------------------- 10 files changed, 31 insertions(+), 482 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e928b0141f02..e9f8e7eefa4a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7965,7 +7965,6 @@ dependencies = [ "sp-tracing", "sp-trie", "sp-wasm-interface", - "tracing", ] [[package]] diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 8cfaa7844cf80..aae5395d53eb5 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -664,9 +664,3 @@ mod tests { assert!(event3.parent_id.is_none()); } } - -struct WasmSpan<'a>{ - name: &'a str, - target: &'a str, - data: &'a -} diff --git a/client/transaction-pool/Cargo.toml b/client/transaction-pool/Cargo.toml index 8fd4c48a0e859..6ae3f5a8abbf3 100644 --- a/client/transaction-pool/Cargo.toml +++ b/client/transaction-pool/Cargo.toml @@ -26,7 +26,7 @@ sc-transaction-graph = { version = "2.0.0-rc5", path = "./graph" } sp-api = { version = "2.0.0-rc5", path = "../../primitives/api" } sp-core = { version = "2.0.0-rc5", path = "../../primitives/core" } sp-runtime = { version = "2.0.0-rc5", path = "../../primitives/runtime" } -sp-tracing = { version = "2.0.0-rc5", features = ["with-tracing"], path = "../../primitives/tracing" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } sp-transaction-pool = { version = "2.0.0-rc5", path = "../../primitives/transaction-pool" } sp-blockchain = { version = "2.0.0-rc5", path = "../../primitives/blockchain" } sp-utils = { version = "2.0.0-rc5", path = "../../primitives/utils" } diff --git a/frame/executive/Cargo.toml b/frame/executive/Cargo.toml index 90f2cb6b671c1..fdc49628a42cb 100644 --- a/frame/executive/Cargo.toml +++ b/frame/executive/Cargo.toml @@ -31,7 +31,7 @@ pallet-transaction-payment = { version = "2.0.0-rc5", path = "../transaction-pay sp-version = { version = "2.0.0-rc5", path = "../../primitives/version" } [features] -default = ["std", "with-tracing"] +default = ["std"] std = [ "codec/std", "frame-support/std", @@ -41,6 +41,3 @@ std = [ "sp-tracing/std", "sp-std/std", ] -with-tracing = [ - "sp-tracing/with-tracing" -] diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index e3ea70e4d7538..24dccf8b0b4a4 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -197,7 +197,7 @@ impl< COnRuntimeUpgrade: OnRuntimeUpgrade, > Executive where - Block::Extrinsic: Checkable + tg vbhghhhhggc, + Block::Extrinsic: Checkable + Codec, CheckedOf: Applyable + GetDispatchInfo, @@ -207,7 +207,6 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "initialize block" }; let digests = Self::extract_pre_digest(&header); Self::initialize_block_impl( header.number(), @@ -271,7 +270,6 @@ where } fn initial_checks(block: &Block) { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "initial checks" }; let header = block.header(); // Check that `parent_hash` is correct. @@ -311,19 +309,12 @@ where /// Execute given extrinsics and take care of post-extrinsics book-keeping. fn execute_extrinsics_with_book_keeping(extrinsics: Vec, block_number: NumberFor) { - { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "executing extrinsics" }; - extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); - } + extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); - { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "finalizing" }; - // post-extrinsics book-keeping - >::note_finished_extrinsics(); - - as OnFinalize>::on_finalize(block_number); - >::on_finalize(block_number); - } + // post-extrinsics book-keeping + >::note_finished_extrinsics(); + as OnFinalize>::on_finalize(block_number); + >::on_finalize(block_number); } /// Finalize the block - it is up the caller to ensure that all header fields are valid @@ -364,9 +355,6 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "applying extrinsic"}; - // FIXME: add support for Codec - // sp_tracing::event!(sp_tracing::Level::INFO, extrinsic = ?uxt); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; @@ -389,7 +377,6 @@ where } fn final_checks(header: &System::Header) { - sp_tracing::enter_span! { sp_tracing::Level::INFO, "final checks" }; // remove temporaries let new_header = >::finalize(); diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 40867f316e4cb..24e898e1692fa 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -37,7 +37,7 @@ frame-system = { version = "2.0.0-rc5", path = "../system" } parity-util-mem = { version = "0.7.0", features = ["primitive-types"] } [features] -default = ["std", "with-tracing"] +default = ["std"] std = [ "once_cell", "bitmask/std", @@ -52,9 +52,6 @@ std = [ "sp-inherents/std", "sp-state-machine", ] -with-tracing = [ - "sp-tracing/with-tracing" -] nightly = [] strict = [] runtime-benchmarks = [] diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 6155dbca4b603..04ee4efd97a24 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -28,7 +28,6 @@ sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../traci log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } -tracing = { version = "0.1.16", optional = true } [features] default = ["std"] @@ -46,7 +45,6 @@ std = [ "log", "futures", "parking_lot", - "tracing" ] # These two features are used for `no_std` builds for the environments which already provides diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 4d86d8e5f2e9c..6c99a5c75195b 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -100,25 +100,12 @@ pub trait Storage { /// Set `key` to `value` in the storage. fn set(&mut self, key: &[u8], value: &[u8]) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - ?key, - ?value, - "set" - ); self.set_storage(key.to_vec(), value.to_vec()); } /// Clear the storage of the given `key` and its value. fn clear(&mut self, key: &[u8]) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - ?key, - "clear" - ); - self.clear_storage(key); + self.clear_storage(key) } /// Check whether the given `key` exists in storage. @@ -128,13 +115,7 @@ pub trait Storage { /// Clear the storage of each key-value pair where the key starts with the given `prefix`. fn clear_prefix(&mut self, prefix: &[u8]) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - ?prefix, - "clear_prefix" - ); - Externalities::clear_prefix(*self, prefix); + Externalities::clear_prefix(*self, prefix) } /// Append the encoded `value` to the storage item at `key`. @@ -146,13 +127,6 @@ pub trait Storage { /// If the storage item does not support [`EncodeAppend`](codec::EncodeAppend) or /// something else fails at appending, the storage item will be set to `[value]`. fn append(&mut self, key: &[u8], value: Vec) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - ?key, - ?value, - "append" - ); self.storage_append(key.to_vec(), value); } @@ -162,11 +136,6 @@ pub trait Storage { /// /// Returns a `Vec` that holds the SCALE encoded hash. fn root(&mut self) -> Vec { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - "root" - ); self.storage_root() } @@ -178,12 +147,6 @@ pub trait Storage { /// Returns `Some(Vec)` which holds the SCALE encoded hash or `None` when /// changes trie is disabled. fn changes_root(&mut self, parent_hash: &[u8]) -> Option> { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - ?parent_hash, - "changes_root" - ); self.storage_changes_root(parent_hash) .expect("Invalid `parent_hash` given to `changes_root`.") } @@ -206,11 +169,6 @@ pub trait Storage { /// in unbalanced transactions. For example, FRAME users should use high level storage /// abstractions. fn start_transaction(&mut self) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - "start_transaction" - ); self.storage_start_transaction(); } @@ -222,11 +180,6 @@ pub trait Storage { /// /// Will panic if there is no open transaction. fn rollback_transaction(&mut self) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - "rollback_transaction" - ); self.storage_rollback_transaction() .expect("No open transaction that can be rolled back."); } @@ -239,11 +192,6 @@ pub trait Storage { /// /// Will panic if there is no open transaction. fn commit_transaction(&mut self) { - #[cfg(feature = "std")] - tracing::event!( - tracing::Level::INFO, - "commit_transaction" - ); self.storage_commit_transaction() .expect("No open transaction that can be committed."); } diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index e4fdf3cac780a..fc3d311298dde 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,11 +12,10 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -tracing = { version = "0.1.13", optional = true, default-features = false } +tracing = { version = "0.1.13", optional = true } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } [features] default = [ "std" ] -with-tracing = [ "tracing" ] -std = [ "with-tracing", "tracing/std", "rental", "log" ] +std = [ "tracing", "rental", "log" ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index caf0eb76ab421..e82d8861cd3f5 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,20 +30,14 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "with-tracing")] -use core::{module_path, format_args}; - #[cfg(feature = "std")] #[macro_use] extern crate rental; -#[cfg(feature = "with-tracing")] +#[cfg(feature = "std")] #[doc(hidden)] pub use tracing; -#[cfg(feature = "with-tracing")] -pub use tracing::Level; - #[cfg(feature = "std")] pub mod proxy; @@ -61,14 +55,7 @@ static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); /// # Example /// /// ``` -/// sp_tracing::tracing_span! { // default level LEVEL:TRACE -/// "test-span"; -/// 1 + 1; -/// // some other complex code -/// } -/// -/// sp_tracing::tracing_span! { // specified log level -/// Level::DEBUG, +/// sp_tracing::tracing_span! { /// "test-span"; /// 1 + 1; /// // some other complex code @@ -84,396 +71,39 @@ macro_rules! tracing_span { $crate::enter_span!($name); $( $code )* } - }; - ( - $lvl:expr, - $name:expr; - $( $code:tt )* - ) => { - { - $crate::enter_span!($lvl, $name); - $( $code )* - } - }; + } } /// Enter a span. /// -/// The span will be valid, until the scope is left. noop unless `with-tracing`-feature is enabled +/// The span will be valid, until the scope is left. /// /// # Example /// /// ``` -/// sp_tracing::enter_span!("test-span"); // defaults to Level::TRACE -/// sp_tracing::enter_span!(sp_tracing::Level::DEBUG, "debug-span"); +/// sp_tracing::enter_span!("test-span"); /// ``` #[macro_export] -#[cfg(feature = "with-tracing")] macro_rules! enter_span { - ( $name:expr ) => ({ - $crate::enter_span!($crate::tracing::Level::TRACE, $name); - }); - ( $lvl:expr, $name:expr ) => ({ - // FIXME: we need to make the variable names based on $name or they might overlap - let __tracing_span__ = $crate::tracing::span!($lvl, $name); - let __tracing_guard__ = __tracing_span__.enter(); - }); + ( $name:expr ) => { + let __tracing_span__ = $crate::if_tracing!( + $crate::tracing::span!($crate::tracing::Level::TRACE, $name) + ); + let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); + } } - -/// Enter a span. -/// -/// The span will be valid, until the scope is left. noop unless `with-tracing`-feature is enabled -/// -/// # Example -/// -/// ``` -/// sp_tracing::enter_span!("test-span"); // defaults to Level::TRACE -/// sp_tracing::enter_span!(sp_tracing::Level::DEBUG, "debug-span"); -/// ``` -#[macro_export] -#[cfg(not(feature = "with-tracing"))] -macro_rules! enter_span { - ( $name:expr ) => ({ {} }); - ( $lvl:expr, $name:expr ) => ({ {} }); -} - -/// Trace an Event. -/// -/// see `tracing`-crate for details on usage -/// noop if `with-tracing`-feature is not enabled. +/// Generates the given code if the tracing dependency is enabled. #[macro_export] -#[cfg(feature = "with-tracing")] -macro_rules! event { - - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - $crate::tracing::event!(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($k).+ = $($fields)* }) - }); - - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::tracing::event!( - target: $target, - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( - $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) - ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) - }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::tracing::event!( - target: $target, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - }); - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!(target: $target, $lvl, { $($arg)+ }) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - parent: $parent, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { $($k).+ = $($field)*} - ) - ); - ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { $($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { ?$($k).+, $($field)*} - ) - ); - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - target: module_path!(), - $lvl, - { %$($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+) => ( - $crate::tracing::event!($lvl, ?$($k).+,) - ); - ($lvl:expr, %$($k:ident).+) => ( - $crate::tracing::event!($lvl, %$($k).+,) - ); - ($lvl:expr, $($k:ident).+) => ( - $crate::tracing::event!($lvl, $($k).+,) - ); - ( $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!(target: module_path!(), $lvl, { $($arg)+ }) - ); - - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::tracing::event!(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($k).+ = $($fields)* }, { $($arg)+ }) - }); - - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( - $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) - ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - $crate::tracing::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) - }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::tracing::event!( - target: $target, - $lvl, - { $($k).+ = $($fields)* }, - { $($arg)+ } - ) - }); - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::tracing::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!(target: $target, $lvl, { $($arg)+ }) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { $($k).+ = $($fields)* }, - { $($arg)+ } - ) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - $lvl, - parent: $parent, - { $($k).+ = $($fields)* }, - { $($arg)+ } - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - parent: $parent, - $lvl, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!(parent: $parent, $lvl, { $($arg)+ }) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - $lvl, - { $($arg)+, $($fields)* } - ) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::tracing::event!( - $lvl, - { $($arg)+, $($fields)* } - ) - ); - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::tracing::event!( - $lvl, - { $($k).+ = $($field)*} - ) - ); - ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - $lvl, - { $($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - $lvl, - { ?$($k).+, $($field)*} - ) - ); - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::tracing::event!( - $lvl, - { %$($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+) => ( - $crate::tracing::event!($lvl, ?$($k).+,) - ); - ($lvl:expr, %$($k:ident).+) => ( - $crate::tracing::event!($lvl, %$($k).+,) - ); - ($lvl:expr, $($k:ident).+) => ( - $crate::tracing::event!($lvl, $($k).+,) - ); - ( $lvl:expr, $($arg:tt)+ ) => ( - $crate::tracing::event!($lvl, { $($arg)+ }) - ); +#[cfg(feature = "std")] +macro_rules! if_tracing { + ( $if:expr ) => {{ $if }} } -/// Trace an Event. -/// -/// see `tracing`-crate for details on usage -/// noop if `with-tracing`-feature is not enabled. #[macro_export] -#[cfg(not(feature = "with-tracing"))] -macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ {} }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ({ {} }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ({ {} }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ {} }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ({ {} }); - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ({ {} }); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ({ {} }); - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ({ {} }); - ($lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - ($lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ {} }); - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ({ {} }); - ($lvl:expr, $($k:ident).+, $($field:tt)*) => ({ {} }); - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ({ {} }); - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ({ {} }); - ($lvl:expr, ?$($k:ident).+) => ({ {} }); - ($lvl:expr, %$($k:ident).+) => ({ {} }); - ($lvl:expr, $($k:ident).+) => ({ {} }); - ($lvl:expr, $($arg:tt)+ ) => ({ {} }); +#[cfg(not(feature = "std"))] +macro_rules! if_tracing { + ( $if:expr ) => {{}} } #[cfg(feature = "std")] From 0e14ca51c78c71a0a1c0116561e062c99939edc4 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 23 Jul 2020 15:09:44 +0100 Subject: [PATCH 015/113] remove From impl due to fallback required on parent_id --- client/tracing/src/lib.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index aae5395d53eb5..d6ba0b3b35bbf 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -80,20 +80,6 @@ pub struct TraceEvent { pub parent_id: Option, } -impl From<&Event<'_>> for TraceEvent { - fn from(event: &Event<'_>) -> TraceEvent { - let mut values = Values::new(); - event.record(&mut values); - TraceEvent { - name: event.metadata().name(), - target: event.metadata().target().to_owned(), - level: event.metadata().level().clone(), - parent_id: event.parent().cloned(), - values, - } - } -} - /// Represents a single instance of a tracing span #[derive(Debug)] pub struct SpanDatum { From 70492f502a7066d515df7b4d9380d4773d9a4e5e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 23 Jul 2020 17:54:11 +0200 Subject: [PATCH 016/113] make tracing codecable --- Cargo.lock | 2 + primitives/tracing/Cargo.toml | 20 ++- primitives/tracing/src/proxy.rs | 272 +++++++++++++++++--------------- 3 files changed, 167 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b0262d918ac1..03fea95a7794b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8221,8 +8221,10 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", + "parity-scale-codec", "rental", "tracing", + "tracing-core", ] [[package]] diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index fc3d311298dde..5209542dd8eef 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,10 +12,26 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -tracing = { version = "0.1.13", optional = true } +codec = { version = "1.3.1", package = "parity-scale-codec", optional = true, default-features = false} +tracing = { version = "0.1.13", optional = true, default-features = false } +tracing-core = { version = "0.1.11", optional = true, default-features = false } rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } [features] default = [ "std" ] -std = [ "tracing", "rental", "log" ] +with-tracing = [ + "tracing", + "tracing-core", + "codec", + "codec/derive", + "codec/full", +] +std = [ + "with-tracing", + "tracing/std", + "tracing-core/std", + "codec/std", + "rental", + "log" +] diff --git a/primitives/tracing/src/proxy.rs b/primitives/tracing/src/proxy.rs index 270f57aaa69f0..7e33b27e144ff 100644 --- a/primitives/tracing/src/proxy.rs +++ b/primitives/tracing/src/proxy.rs @@ -14,152 +14,174 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +#![cfg_attr(not(feature = "std"), no_std)] //! Proxy to allow entering tracing spans from wasm. -//! -//! Use `enter_span` and `exit_span` to surround the code that you wish to trace -use rental; -use tracing::info_span; - -/// Used to identify a proxied WASM trace -pub const WASM_TRACE_IDENTIFIER: &'static str = "WASM_TRACE"; -/// Used to extract the real `target` from the associated values of the span -pub const WASM_TARGET_KEY: &'static str = "proxied_wasm_target"; -/// Used to extract the real `name` from the associated values of the span -pub const WASM_NAME_KEY: &'static str = "proxied_wasm_name"; - -const MAX_SPANS_LEN: usize = 1000; - -rental! { - pub mod rent_span { - #[rental] - pub struct SpanAndGuard { - span: Box, - guard: tracing::span::Entered<'span>, - } +use core::{ + default::Default, + fmt::Debug, +}; +use codec::{Encode, Decode}; +use tracing_core::{ + subscriber::Subscriber, + metadata::Metadata, + field::{Field, Visit}, + event::{Event}, + span::{ + Attributes, + Id, + Record, + }, + Level, +}; + +struct WasmProxySubscriber; +impl Subscriber for WasmProxySubscriber { + fn enabled(&self, metadata: &Metadata) -> bool { + todo!{} + // host_functions::tracing_enabled(metadata.into()) + } + fn record_follows_from(&self, span: &Id, follows: &Id) { + todo!{} + // host_functions::tracing_record_follows_from(span.into_u64(), follows.into_u64()) + } + fn new_span(&self, span: &Attributes) -> Id { + todo!{} + // Id::from_u64(host_functions::tracing_new_span(span.into()) + } + fn record(&self, span: &Id, values: &Record) { + todo!{} + // host_functions::tracing_record(span.into_u64(), value.into()) + } + fn event(&self, event: &Event) { + todo!{} + // host_functions::tracing_enter(event.into()) + } + fn enter(&self, span: &Id) { + todo!{} + // host_functions::tracing_enter(span.into_u64()) + } + fn exit(&self, span: &Id) { + todo!{} + // host_functions::tracing_exit(span.into_u64()) } } -/// Requires a tracing::Subscriber to process span traces, -/// this is available when running with client (and relevant cli params). -pub struct TracingProxy { - next_id: u64, - spans: Vec<(u64, rent_span::SpanAndGuard)>, +#[derive(Encode, Decode)] +pub enum FieldValue { + I64(i64), + U64(u64), + Bool(bool), + Str(Vec), + Debug(Vec), } -impl Drop for TracingProxy { - fn drop(&mut self) { - if !self.spans.is_empty() { - log::debug!( - target: "tracing", - "Dropping TracingProxy with {} un-exited spans, marking as not valid", self.spans.len() - ); - while let Some((_, mut sg)) = self.spans.pop() { - sg.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); - } - } + +#[derive(Encode, Decode)] +pub struct Fields (pub Vec<(Vec, FieldValue)>); + +impl Visit for Fields { + fn record_debug(&mut self, field: &Field, value: &dyn Debug) { + todo!{} + // self.0.push((field.name().as_bytes().into(), FieldValue::Debug(format!("{:?}", value).into()))); + } + fn record_i64(&mut self, field: &Field, value: i64) { + self.0.push((field.name().as_bytes().into(), FieldValue::I64(value))); + } + fn record_u64(&mut self, field: &Field, value: u64) { + self.0.push((field.name().as_bytes().into(), FieldValue::U64(value))); + } + fn record_bool(&mut self, field: &Field, value: bool) { + self.0.push((field.name().as_bytes().into(), FieldValue::Bool(value))); } + fn record_str(&mut self, field: &Field, value: &str) { + self.0.push((field.name().as_bytes().into(), FieldValue::Str(value.as_bytes().into()))); + } +} + +#[derive(Encode, Decode)] +pub struct TracingAttributes { + pub parent_id: Option, + pub fields: Fields } -impl TracingProxy { - pub fn new() -> TracingProxy { - TracingProxy { - next_id: 0, - spans: Vec::new(), +impl From<&Attributes<'_>> for TracingAttributes { + fn from(a: &Attributes) -> TracingAttributes { + let mut fields = Fields(Vec::new()); + a.record(&mut fields); + TracingAttributes { + parent_id: a.parent().map(|a| a.into_u64()), + fields } } } -impl TracingProxy { - /// Create and enter a `tracing` Span, returning the span id, - /// which should be passed to `exit_span(id)` to signal that the span should exit. - pub fn enter_span(&mut self, proxied_wasm_target: &str, proxied_wasm_name: &str) -> u64 { - // The identifiers `proxied_wasm_target` and `proxied_wasm_name` must match their associated const, - // WASM_TARGET_KEY and WASM_NAME_KEY. - let span = info_span!(WASM_TRACE_IDENTIFIER, is_valid_trace = true, proxied_wasm_target, proxied_wasm_name); - self.next_id += 1; - let sg = rent_span::SpanAndGuard::new( - Box::new(span), - |span| span.enter(), - ); - self.spans.push((self.next_id, sg)); - if self.spans.len() > MAX_SPANS_LEN { - // This is to prevent unbounded growth of Vec and could mean one of the following: - // 1. Too many nested spans, or MAX_SPANS_LEN is too low. - // 2. Not correctly exiting spans due to misconfiguration / misuse - log::warn!( - target: "tracing", - "TracingProxy MAX_SPANS_LEN exceeded, removing oldest span." - ); - let mut sg = self.spans.remove(0).1; - sg.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); + +#[derive(Encode, Decode)] +pub enum TracingLevel { + ERROR, + WARN, + INFO, + DEBUG, + TRACE +} + +impl From<&Level> for TracingLevel { + fn from(lvl: &Level) -> TracingLevel { + match *lvl { + Level::ERROR => TracingLevel::ERROR, + Level::WARN => TracingLevel::WARN, + Level::INFO => TracingLevel::INFO, + Level::DEBUG => TracingLevel::DEBUG, + Level::TRACE => TracingLevel::TRACE, } - self.next_id } +} - /// Exit a span by dropping it along with it's associated guard. - pub fn exit_span(&mut self, id: u64) { - if self.spans.last().map(|l| id > l.0).unwrap_or(true) { - log::warn!(target: "tracing", "Span id not found in TracingProxy: {}", id); - return; - } - let mut last_span = self.spans.pop().expect("Just checked that there is an element to pop; qed"); - while id < last_span.0 { - log::warn!( - target: "tracing", - "TracingProxy Span ids not equal! id parameter given: {}, last span: {}", - id, - last_span.0, - ); - last_span.1.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); - if let Some(s) = self.spans.pop() { - last_span = s; - } else { - log::warn!(target: "tracing", "Span id not found in TracingProxy {}", id); - return; - } +impl Into for TracingLevel { + fn into(self) -> Level { + match self { + TracingLevel::ERROR => Level::ERROR, + TracingLevel::WARN => Level::WARN, + TracingLevel::INFO => Level::INFO, + TracingLevel::DEBUG => Level::DEBUG, + TracingLevel::TRACE => Level::TRACE, } } } +#[derive(Encode, Decode)] +struct TracingMetadata { + name: Vec, + target: Vec, + level: TracingLevel, + file: Option>, + line: Option, + module_path: Option>, + fields: Vec>, + is_span: bool, +} -#[cfg(test)] -mod tests { - use super::*; - - fn create_spans(proxy: &mut TracingProxy, qty: usize) -> Vec { - let mut spans = Vec::new(); - for n in 0..qty { - spans.push(proxy.enter_span("target", &format!("{}", n))); +impl From<&Metadata<'_>> for TracingMetadata { + fn from(m: &Metadata) -> TracingMetadata { + TracingMetadata { + name: m.name().as_bytes().into(), + target: m.target().as_bytes().into(), + module_path: m.module_path().map(|m| m.as_bytes().into()), + file: m.file().map(|m| m.as_bytes().into()), + line: m.line().clone(), + level: m.level().into(), + fields: m.fields().iter().map(|f| f.name().as_bytes().into()).collect(), + is_span: m.is_span(), } - spans - } - - #[test] - fn max_spans_len_respected() { - let mut proxy = TracingProxy::new(); - let _spans = create_spans(&mut proxy, MAX_SPANS_LEN + 10); - assert_eq!(proxy.spans.len(), MAX_SPANS_LEN); - // ensure oldest spans removed - assert_eq!(proxy.spans[0].0, 11); - } - - #[test] - fn handles_span_exit_scenarios() { - let mut proxy = TracingProxy::new(); - let _spans = create_spans(&mut proxy, 10); - assert_eq!(proxy.spans.len(), 10); - // exit span normally - proxy.exit_span(10); - assert_eq!(proxy.spans.len(), 9); - // skip and exit outer span without exiting inner, id: 8 instead of 9 - proxy.exit_span(8); - // should have also removed the inner span that was lost - assert_eq!(proxy.spans.len(), 7); - // try to exit span not held - proxy.exit_span(9); - assert_eq!(proxy.spans.len(), 7); - // exit all spans - proxy.exit_span(1); - assert_eq!(proxy.spans.len(), 0); } } + + +trait WasmTracingInterface { + fn enabled(&self, metadata: &Metadata) -> bool; + fn new_span(&self, span: TracingAttributes) -> Id; + fn record(&self, span: &Id, values: &Record); + fn event(&self, event: &Event); + fn enter(&self, span: &Id); + fn exit(&self, span: &Id); +} \ No newline at end of file From 8824a60deea54d9b437407a21c8ceaf6a1902ee5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 24 Jul 2020 00:45:09 +0200 Subject: [PATCH 017/113] replace with global tracing --- primitives/runtime-interface/Cargo.toml | 5 ++-- .../runtime-interface/proc-macro/src/lib.rs | 4 ++- .../bare_function_interface.rs | 15 ++++++++-- .../host_function_interface.rs | 28 +++++++++++++++---- .../proc-macro/src/runtime_interface/mod.rs | 10 +++++-- primitives/runtime-interface/src/lib.rs | 3 +- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/primitives/runtime-interface/Cargo.toml b/primitives/runtime-interface/Cargo.toml index 16d5a14e889b1..f50f11c42d319 100644 --- a/primitives/runtime-interface/Cargo.toml +++ b/primitives/runtime-interface/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-wasm-interface = { version = "2.0.0-rc5", path = "../wasm-interface", default-features = false } sp-std = { version = "2.0.0-rc5", default-features = false, path = "../std" } -sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../tracing" } +tracing = { version = "0.1.17", default-features = false, optional = true } sp-runtime-interface-proc-macro = { version = "2.0.0-rc5", path = "proc-macro" } sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false } @@ -35,7 +35,8 @@ default = [ "std" ] std = [ "sp-wasm-interface/std", "sp-std/std", - "sp-tracing/std", + "tracing", + "tracing/std", "codec/std", "sp-externalities", "primitive-types/std", diff --git a/primitives/runtime-interface/proc-macro/src/lib.rs b/primitives/runtime-interface/proc-macro/src/lib.rs index 2f5b9de1c14e7..49f42f82408f7 100644 --- a/primitives/runtime-interface/proc-macro/src/lib.rs +++ b/primitives/runtime-interface/proc-macro/src/lib.rs @@ -39,8 +39,10 @@ pub fn runtime_interface( ) -> proc_macro::TokenStream { let trait_def = parse_macro_input!(input as ItemTrait); let wasm_only = parse_macro_input!(attrs as Option); + // FIXME: actual parse for this + let no_tracing : Option<()> = None; //parse_macro_input!(tracing_attrs as Option); - runtime_interface::runtime_interface_impl(trait_def, wasm_only.is_some()) + runtime_interface::runtime_interface_impl(trait_def, wasm_only.is_some(), no_tracing.is_none()) .unwrap_or_else(|e| e.to_compile_error()) .into() } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index 6760e9656113a..2cc0c3551e87b 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -46,7 +46,7 @@ use std::iter; /// Generate one bare function per trait method. The name of the bare function is equal to the name /// of the trait method. -pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result { +pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool, with_tracing: bool) -> Result { let trait_name = &trait_def.ident; let runtime_interface = get_runtime_interface(trait_def)?; @@ -63,7 +63,7 @@ pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result = runtime_interface.all_versions().try_fold(token_stream?, |mut t, (version, method)| { - t.extend(function_std_impl(trait_name, method, version, is_wasm_only)?); + t.extend(function_std_impl(trait_name, method, version, is_wasm_only, with_tracing)?); Ok(t) }); @@ -145,6 +145,7 @@ fn function_std_impl( method: &TraitItemMethod, version: u32, is_wasm_only: bool, + with_tracing: bool, ) -> Result { let function_name = create_function_ident_with_version(&method.sig.ident, version); let function_name_str = function_name.to_string(); @@ -164,6 +165,14 @@ fn function_std_impl( } ).take(1), ); + let tracing = if with_tracing { + Some(quote!( + let __trace_span = #crate_::tracing::trace_span!(#function_name_str); + let __guard = __trace_span.enter(); + )) + } else { + None + }; let return_value = &method.sig.output; let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version")); // Don't make the function public accessible when this is a wasm only interface. @@ -174,7 +183,7 @@ fn function_std_impl( #[cfg(feature = "std")] #( #attrs )* fn #function_name( #( #args, )* ) #return_value { - #crate_::sp_tracing::enter_span!(#function_name_str); + #tracing #call_to_trait } } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 721eed649c25d..ac436e1512180 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -43,7 +43,7 @@ use std::iter::{Iterator, self}; /// Generate the extern host functions for wasm and the `HostFunctions` struct that provides the /// implementations for the host functions on the host. -pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result { +pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool, with_tracing: bool) -> Result { let trait_name = &trait_def.ident; let extern_host_function_impls = get_runtime_interface(trait_def)? .latest_versions() @@ -57,7 +57,7 @@ pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result(t) })?; - let host_functions_struct = generate_host_functions_struct(trait_def, is_wasm_only)?; + let host_functions_struct = generate_host_functions_struct(trait_def, is_wasm_only, with_tracing)?; Ok( quote! { @@ -158,13 +158,21 @@ fn generate_exchangeable_host_function(method: &TraitItemMethod) -> Result Result { +fn generate_host_functions_struct(trait_def: &ItemTrait, is_wasm_only: bool, with_tracing: bool) + -> Result +{ let crate_ = generate_crate_access(); let host_functions = get_runtime_interface(trait_def)? .all_versions() .map(|(version, method)| - generate_host_function_implementation(&trait_def.ident, method, version, is_wasm_only) + generate_host_function_implementation( + &trait_def.ident, + method, + version, + is_wasm_only, + with_tracing + ) ) .collect::>>()?; @@ -194,6 +202,7 @@ fn generate_host_function_implementation( method: &TraitItemMethod, version: u32, is_wasm_only: bool, + with_tracing: bool, ) -> Result { let name = create_host_function_ident(&method.sig.ident, version, trait_name).to_string(); let struct_name = Ident::new(&name.to_pascal_case(), Span::call_site()); @@ -207,6 +216,15 @@ fn generate_host_function_implementation( let host_function_call = generate_host_function_call(&method.sig, version, is_wasm_only); let into_preallocated_ffi_value = generate_into_preallocated_ffi_value(&method.sig)?; let convert_return_value = generate_return_value_into_wasm_value(&method.sig); + let tracing = if with_tracing { + Some(quote!( + let __trace_span = #crate_::tracing::trace_span!(#name); + let __guard = __trace_span.enter(); + )) + } else { + None + }; + Ok( quote! { @@ -227,7 +245,7 @@ fn generate_host_function_implementation( __function_context__: &mut dyn #crate_::sp_wasm_interface::FunctionContext, args: &mut dyn Iterator, ) -> std::result::Result, String> { - #crate_::sp_tracing::enter_span!(#name); + #tracing #( #wasm_to_ffi_values )* #( #ffi_to_host_values )* #host_function_call diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs index c9b6edf68fd5a..0fce47c20aed4 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs @@ -33,18 +33,22 @@ mod trait_decl_impl; pub mod keywords { // Custom keyword `wasm_only` that can be given as attribute to [`runtime_interface`]. syn::custom_keyword!(wasm_only); + // Custom keyword `no_tracing` that can be given as attribute to [`runtime_interface`]. + syn::custom_keyword!(no_tracing); } /// Implementation of the `runtime_interface` attribute. /// /// It expects the trait definition the attribute was put above and if this should be an wasm only /// interface. -pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool) -> Result { - let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only)?; +pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool, with_tracing: bool) + -> Result +{ + let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only, with_tracing)?; let crate_include = generate_runtime_interface_include(); let mod_name = Ident::new(&trait_def.ident.to_string().to_snake_case(), Span::call_site()); let trait_decl_impl = trait_decl_impl::process(&trait_def, is_wasm_only)?; - let host_functions = host_function_interface::generate(&trait_def, is_wasm_only)?; + let host_functions = host_function_interface::generate(&trait_def, is_wasm_only, with_tracing)?; let vis = trait_def.vis; let attrs = &trait_def.attrs; diff --git a/primitives/runtime-interface/src/lib.rs b/primitives/runtime-interface/src/lib.rs index 562f94b278efc..6511f93e8de2a 100644 --- a/primitives/runtime-interface/src/lib.rs +++ b/primitives/runtime-interface/src/lib.rs @@ -111,7 +111,8 @@ extern crate self as sp_runtime_interface; pub use sp_wasm_interface; #[doc(hidden)] -pub use sp_tracing; +#[cfg(feature = "std")] +use tracing; #[doc(hidden)] pub use sp_std; From e0312a6ffc1d2d66d1245c37aee04ffaaa0dd7cb Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 24 Jul 2020 00:45:42 +0200 Subject: [PATCH 018/113] new tracing interface --- Cargo.lock | 9 +- primitives/io/Cargo.toml | 2 + primitives/io/src/lib.rs | 51 +------ primitives/tracing/Cargo.toml | 8 +- primitives/tracing/src/interface.rs | 220 ++++++++++++++++++++++++++++ primitives/tracing/src/lib.rs | 4 +- primitives/tracing/src/proxy.rs | 187 ----------------------- 7 files changed, 238 insertions(+), 243 deletions(-) create mode 100644 primitives/tracing/src/interface.rs delete mode 100644 primitives/tracing/src/proxy.rs diff --git a/Cargo.lock b/Cargo.lock index 03fea95a7794b..f930bda8f7c7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8056,9 +8056,9 @@ dependencies = [ "sp-runtime-interface-test-wasm", "sp-state-machine", "sp-std", - "sp-tracing", "sp-wasm-interface", "static_assertions", + "tracing", "trybuild", ] @@ -8223,6 +8223,9 @@ dependencies = [ "log", "parity-scale-codec", "rental", + "sp-externalities", + "sp-runtime-interface", + "sp-std", "tracing", "tracing-core", ] @@ -9219,9 +9222,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" +checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" dependencies = [ "cfg-if", "tracing-attributes", diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 04ee4efd97a24..7730f8337bce2 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -42,6 +42,8 @@ std = [ "sp-runtime-interface/std", "sp-externalities", "sp-wasm-interface/std", + "sp-tracing/std", + "sp-tracing/with-tracing", "log", "futures", "parking_lot", diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 6c99a5c75195b..cc26fa64e7edc 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -997,55 +997,6 @@ pub trait Logging { } } -#[cfg(feature = "std")] -sp_externalities::decl_extension! { - /// Extension to allow running traces in wasm via Proxy - pub struct TracingProxyExt(sp_tracing::proxy::TracingProxy); -} - -/// Interface that provides functions for profiling the runtime. -#[runtime_interface] -pub trait WasmTracing { - /// To create and enter a `tracing` span, using `sp_tracing::proxy` - /// Returns 0 value to indicate that no further traces should be attempted - fn enter_span(&mut self, target: &str, name: &str) -> u64 { - if sp_tracing::wasm_tracing_enabled() { - match self.extension::() { - Some(proxy) => return proxy.enter_span(target, name), - None => { - if self.register_extension(TracingProxyExt(sp_tracing::proxy::TracingProxy::new())).is_ok() { - if let Some(proxy) = self.extension::() { - return proxy.enter_span(target, name); - } - } else { - log::warn!( - target: "tracing", - "Unable to register extension: TracingProxyExt" - ); - } - } - } - } - log::debug!( - target: "tracing", - "Notify to runtime that tracing is disabled." - ); - 0 - } - - /// Exit a `tracing` span, using `sp_tracing::proxy` - fn exit_span(&mut self, id: u64) { - if let Some(proxy) = self.extension::() { - proxy.exit_span(id) - } else { - log::warn!( - target: "tracing", - "Unable to load extension: TracingProxyExt" - ); - } - } -} - /// Wasm-only interface that provides functions for interacting with the sandbox. #[runtime_interface(wasm_only)] pub trait Sandbox { @@ -1192,7 +1143,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - wasm_tracing::HostFunctions, + sp_tracing::wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 5209542dd8eef..afb1a9b3c936d 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,7 +12,10 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] +sp-std = { version = "2.0.0-rc5", path = "../std", default-feature = false} +sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} codec = { version = "1.3.1", package = "parity-scale-codec", optional = true, default-features = false} +sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } tracing = { version = "0.1.13", optional = true, default-features = false } tracing-core = { version = "0.1.11", optional = true, default-features = false } rental = { version = "0.5.5", optional = true } @@ -26,12 +29,15 @@ with-tracing = [ "codec", "codec/derive", "codec/full", + "sp-externalities", ] std = [ "with-tracing", "tracing/std", "tracing-core/std", "codec/std", + "sp-std/std", + "sp-runtime-interface/std", "rental", - "log" + "log", ] diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs new file mode 100644 index 0000000000000..6022f48df4077 --- /dev/null +++ b/primitives/tracing/src/interface.rs @@ -0,0 +1,220 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] +//! Proxy to allow entering tracing spans from wasm. +use core::{ + default::Default, + fmt::Debug, +}; + +use codec::{Encode, Decode}; +use tracing_core::{ + subscriber::Subscriber, + metadata::{Metadata, Kind}, + field::{Field, Visit}, + event::{Event}, + span::{ + Attributes, + Id, + Record, + }, + Level, +}; + +use sp_std::vec::Vec; +use sp_runtime_interface::runtime_interface; + + +#[derive(Encode, Decode, Debug)] +pub enum FieldValue { + I64(i64), + U64(u64), + Bool(bool), + Str(Vec), + Debug(Vec), +} + + +#[derive(Encode, Decode, Debug)] +pub struct Fields (pub Vec<(Vec, FieldValue)>); + +impl Visit for Fields { + fn record_debug(&mut self, field: &Field, value: &dyn Debug) { + todo!{} + // self.0.push((field.name().as_bytes().into(), FieldValue::Debug(format!("{:?}", value).into()))); + } + fn record_i64(&mut self, field: &Field, value: i64) { + self.0.push((field.name().as_bytes().into(), FieldValue::I64(value))); + } + fn record_u64(&mut self, field: &Field, value: u64) { + self.0.push((field.name().as_bytes().into(), FieldValue::U64(value))); + } + fn record_bool(&mut self, field: &Field, value: bool) { + self.0.push((field.name().as_bytes().into(), FieldValue::Bool(value))); + } + fn record_str(&mut self, field: &Field, value: &str) { + self.0.push((field.name().as_bytes().into(), FieldValue::Str(value.as_bytes().into()))); + } +} + +#[derive(Encode, Decode)] +pub struct WasmTracingAttributes { + pub parent_id: Option, + pub fields: Fields +} + +impl From<&Attributes<'_>> for WasmTracingAttributes { + fn from(a: &Attributes) -> WasmTracingAttributes { + let mut fields = Fields(Vec::new()); + a.record(&mut fields); + WasmTracingAttributes { + parent_id: a.parent().map(|a| a.into_u64()), + fields + } + } +} + + +#[derive(Encode, Decode)] +pub enum WasmTracingLevel { + ERROR, + WARN, + INFO, + DEBUG, + TRACE +} + +impl From<&Level> for WasmTracingLevel { + fn from(lvl: &Level) -> WasmTracingLevel { + match *lvl { + Level::ERROR => WasmTracingLevel::ERROR, + Level::WARN => WasmTracingLevel::WARN, + Level::INFO => WasmTracingLevel::INFO, + Level::DEBUG => WasmTracingLevel::DEBUG, + Level::TRACE => WasmTracingLevel::TRACE, + } + } +} + +impl Into for WasmTracingLevel { + fn into(self) -> Level { + match self { + WasmTracingLevel::ERROR => Level::ERROR, + WasmTracingLevel::WARN => Level::WARN, + WasmTracingLevel::INFO => Level::INFO, + WasmTracingLevel::DEBUG => Level::DEBUG, + WasmTracingLevel::TRACE => Level::TRACE, + } + } +} + +#[derive(Encode, Decode)] +struct WasmTracingMetadata { + target: Vec, + level: WasmTracingLevel, + file: Option>, + line: Option, + module_path: Option>, + is_span: bool, +} + +impl From<&Metadata<'_>> for WasmTracingMetadata { + fn from(m: &Metadata) -> WasmTracingMetadata { + WasmTracingMetadata { + target: m.target().as_bytes().into(), + module_path: m.module_path().map(|m| m.as_bytes().into()), + file: m.file().map(|m| m.as_bytes().into()), + line: m.line().clone(), + level: m.level().into(), + is_span: m.is_span(), + } + } +} + +// #[cfg(feature="std")] +// impl<'a> Into> for WasmTracingMetadata { +// fn into(self) -> Metadata<'a> { +// Metadata::new( +// "wasm_tracing", // must be static, it's the same for all then +// std::str::from_utf8(self.target.as_slice()).unwrap_or(""), +// self.level.into(), +// self.file.as_ref().and_then(|s| std::str::from_utf8(s.as_slice()).ok()), +// self.line, +// self.module_path.as_ref().and_then(|s| std::str::from_utf8(s.as_slice()).ok()), +// Default::default(), +// if self.is_span { Kind::SPAN } else { Kind::EVENT } +// ) +// } +// } + + +#[derive(Encode, Decode)] +struct WasmTracingEvent; + +#[derive(Encode, Decode)] +struct WasmTracingRecord; + +pub trait TracingSubscriber { + fn enabled(&self, metadata: WasmTracingMetadata) -> bool; + fn new_span(&self, span: WasmTracingAttributes) -> u64; + fn record(&self, span: u64, values: WasmTracingRecord); + fn event(&self, event: WasmTracingEvent); + fn enter(&self, span: u64); + fn exit(&self, span: u64); +} + +sp_externalities::decl_extension! { + /// The keystore extension to register/retrieve from the externalities. + pub struct WasmTracer(dyn TracingSubscriber + 'static + Send); +} + + +/// Interface that provides tracing functions +// #[runtime_interface(wasm_only, no_tracing)] +#[runtime_interface] +pub trait WasmTracing { + fn enabled(&self, metadata: WasmTracingMetadata) -> bool { + self.extension::().map(|t|{ + t.enabled(metadata) + }).unwrap_or(false) + } + fn new_span(&self, span: WasmTracingAttributes) -> u64 { + self.extension::().map(|t|{ + t.new_span(span) + }).unwrap_or(0) + } + fn record(&self, span: u64, values: WasmTracingRecord) { + self.extension::().map(|t|{ + t.record(span, values) + }); + } + fn event(&self, event: WasmTracingEvent) { + self.extension::().map(|t|{ + t.event(event) + }); + } + fn enter(&self, span: u64) { + self.extension::().map(|t|{ + t.enter(span) + }); + } + fn exit(&self, span: u64) { + self.extension::().map(|t|{ + t.exit(span) + }); + } +} \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index e82d8861cd3f5..b06eb88652f09 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -38,8 +38,8 @@ extern crate rental; #[doc(hidden)] pub use tracing; -#[cfg(feature = "std")] -pub mod proxy; +#[cfg(feature = "with-tracing")] +pub mod interface; #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/primitives/tracing/src/proxy.rs b/primitives/tracing/src/proxy.rs deleted file mode 100644 index 7e33b27e144ff..0000000000000 --- a/primitives/tracing/src/proxy.rs +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -#![cfg_attr(not(feature = "std"), no_std)] -//! Proxy to allow entering tracing spans from wasm. -use core::{ - default::Default, - fmt::Debug, -}; -use codec::{Encode, Decode}; -use tracing_core::{ - subscriber::Subscriber, - metadata::Metadata, - field::{Field, Visit}, - event::{Event}, - span::{ - Attributes, - Id, - Record, - }, - Level, -}; - -struct WasmProxySubscriber; -impl Subscriber for WasmProxySubscriber { - fn enabled(&self, metadata: &Metadata) -> bool { - todo!{} - // host_functions::tracing_enabled(metadata.into()) - } - fn record_follows_from(&self, span: &Id, follows: &Id) { - todo!{} - // host_functions::tracing_record_follows_from(span.into_u64(), follows.into_u64()) - } - fn new_span(&self, span: &Attributes) -> Id { - todo!{} - // Id::from_u64(host_functions::tracing_new_span(span.into()) - } - fn record(&self, span: &Id, values: &Record) { - todo!{} - // host_functions::tracing_record(span.into_u64(), value.into()) - } - fn event(&self, event: &Event) { - todo!{} - // host_functions::tracing_enter(event.into()) - } - fn enter(&self, span: &Id) { - todo!{} - // host_functions::tracing_enter(span.into_u64()) - } - fn exit(&self, span: &Id) { - todo!{} - // host_functions::tracing_exit(span.into_u64()) - } -} - -#[derive(Encode, Decode)] -pub enum FieldValue { - I64(i64), - U64(u64), - Bool(bool), - Str(Vec), - Debug(Vec), -} - - -#[derive(Encode, Decode)] -pub struct Fields (pub Vec<(Vec, FieldValue)>); - -impl Visit for Fields { - fn record_debug(&mut self, field: &Field, value: &dyn Debug) { - todo!{} - // self.0.push((field.name().as_bytes().into(), FieldValue::Debug(format!("{:?}", value).into()))); - } - fn record_i64(&mut self, field: &Field, value: i64) { - self.0.push((field.name().as_bytes().into(), FieldValue::I64(value))); - } - fn record_u64(&mut self, field: &Field, value: u64) { - self.0.push((field.name().as_bytes().into(), FieldValue::U64(value))); - } - fn record_bool(&mut self, field: &Field, value: bool) { - self.0.push((field.name().as_bytes().into(), FieldValue::Bool(value))); - } - fn record_str(&mut self, field: &Field, value: &str) { - self.0.push((field.name().as_bytes().into(), FieldValue::Str(value.as_bytes().into()))); - } -} - -#[derive(Encode, Decode)] -pub struct TracingAttributes { - pub parent_id: Option, - pub fields: Fields -} - -impl From<&Attributes<'_>> for TracingAttributes { - fn from(a: &Attributes) -> TracingAttributes { - let mut fields = Fields(Vec::new()); - a.record(&mut fields); - TracingAttributes { - parent_id: a.parent().map(|a| a.into_u64()), - fields - } - } -} - - -#[derive(Encode, Decode)] -pub enum TracingLevel { - ERROR, - WARN, - INFO, - DEBUG, - TRACE -} - -impl From<&Level> for TracingLevel { - fn from(lvl: &Level) -> TracingLevel { - match *lvl { - Level::ERROR => TracingLevel::ERROR, - Level::WARN => TracingLevel::WARN, - Level::INFO => TracingLevel::INFO, - Level::DEBUG => TracingLevel::DEBUG, - Level::TRACE => TracingLevel::TRACE, - } - } -} - -impl Into for TracingLevel { - fn into(self) -> Level { - match self { - TracingLevel::ERROR => Level::ERROR, - TracingLevel::WARN => Level::WARN, - TracingLevel::INFO => Level::INFO, - TracingLevel::DEBUG => Level::DEBUG, - TracingLevel::TRACE => Level::TRACE, - } - } -} - -#[derive(Encode, Decode)] -struct TracingMetadata { - name: Vec, - target: Vec, - level: TracingLevel, - file: Option>, - line: Option, - module_path: Option>, - fields: Vec>, - is_span: bool, -} - -impl From<&Metadata<'_>> for TracingMetadata { - fn from(m: &Metadata) -> TracingMetadata { - TracingMetadata { - name: m.name().as_bytes().into(), - target: m.target().as_bytes().into(), - module_path: m.module_path().map(|m| m.as_bytes().into()), - file: m.file().map(|m| m.as_bytes().into()), - line: m.line().clone(), - level: m.level().into(), - fields: m.fields().iter().map(|f| f.name().as_bytes().into()).collect(), - is_span: m.is_span(), - } - } -} - - -trait WasmTracingInterface { - fn enabled(&self, metadata: &Metadata) -> bool; - fn new_span(&self, span: TracingAttributes) -> Id; - fn record(&self, span: &Id, values: &Record); - fn event(&self, event: &Event); - fn enter(&self, span: &Id); - fn exit(&self, span: &Id); -} \ No newline at end of file From b81fa399baca3475b3a03ae87469baaac6163134 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Fri, 24 Jul 2020 18:50:21 +0100 Subject: [PATCH 019/113] impl TracingSubscriber in client --- client/tracing/src/lib.rs | 132 +++++++++++++++++++++------- primitives/tracing/src/interface.rs | 6 +- 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index d6ba0b3b35bbf..3c6e6e8ead692 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -42,11 +42,28 @@ use tracing_core::{ use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; -use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; +use sp_tracing::interface::{ + Fields, + FieldValue, + TracingSubscriber, + WasmTracingAttributes, + WasmTracingEvent, + WasmTracingMetadata, + WasmTracingRecord +}; const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; +/// Responsible for assigning ids to new spans, which are not re-used. +pub struct ProfilingSubscriber { + next_id: AtomicU64, + targets: Vec<(String, Level)>, + trace_handler: Box, + span_data: Mutex>, + current_span: CurrentSpan, +} + /// Used to configure how to receive the metrics #[derive(Debug, Clone)] pub enum TracingReceiver { @@ -207,15 +224,6 @@ impl slog::Value for Values { } } -/// Responsible for assigning ids to new spans, which are not re-used. -pub struct ProfilingSubscriber { - next_id: AtomicU64, - targets: Vec<(String, Level)>, - trace_handler: Box, - span_data: Mutex>, - current_span: CurrentSpan, -} - impl ProfilingSubscriber { /// Takes a `TracingReceiver` and a comma separated list of targets, /// either with a level: "pallet=trace,frame=debug" @@ -245,7 +253,7 @@ impl ProfilingSubscriber { targets, trace_handler, span_data: Mutex::new(FxHashMap::default()), - current_span: Default::default() + current_span: CurrentSpan::new() } } @@ -276,9 +284,87 @@ fn parse_target(s: &str) -> (String, Level) { } } +impl From for Values { + fn from(fields: Fields) -> Self { + let mut values = Values::default(); + for (k,v) in fields.0 { + if let Ok(key) = String::from_utf8(k) { + match v { + FieldValue::Bool(v) => values.bool_values.insert(key, v), + FieldValue::I64(v) => values.i64_values.insert(key, v), + FieldValue::U64(v) => values.u64_values.insert(key, v), + FieldValue::Str(v) => { + if let Ok(val) = String::from_utf8(v) { + values.string_values.insert(key, val) ; + } + }, + FieldValue::Debug(v) => { + if let Ok(val) = String::from_utf8(v) { + values.string_values.insert(key, val) ; + } + }, + } + } + } + values + } +} +impl TracingSubscriber for ProfilingSubscriber { + fn enabled(&self, metadata: WasmTracingMetadata) -> bool { + // TODO move levels into static and implement + true + } + + fn new_span(&self, span: WasmTracingAttributes) -> u64 { + let id = self.next_id.fetch_add(1, Ordering::Relaxed); + let values = span.fields.into(); + let span_datum = SpanDatum { + id: ID::from_u64(id.clone()), + parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), + name: attrs.metadata().name().to_owned(), + target: attrs.metadata().target().to_owned(), + level: attrs.metadata().level().clone(), + line: attrs.metadata().line().unwrap_or(0), + start_time: Instant::now(), + overall_time: ZERO_DURATION, + values, + }; + self.span_data.lock().insert(span_datum.id.clone(), span_datum); + id + } + + fn record(&self, _span: u64, _values: WasmTracingRecord) { + // TODO + } + + fn event(&self, _event: WasmTracingEvent) { + // TODO + } + + fn enter(&self, span: u64) { + let id = Id::from_u64(span); + self.current_span.enter(id.clone()); + let mut span_data = self.span_data.lock(); + let start_time = Instant::now(); + if let Some(mut s) = span_data.get_mut(&id) { + s.start_time = start_time; + } + } + + fn exit(&self, span: u64) { + self.current_span.exit(); + let end_time = Instant::now(); + let mut span_data = self.span_data.lock(); + if let Some(mut s) = span_data.remove(&Id::from_u64(span)) { + s.overall_time = end_time - s.start_time + s.overall_time; + self.trace_handler.handle_span(s); + } + } +} + impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if metadata.target() == PROXY_TARGET || self.check_target(metadata.target(), metadata.level()) { + if metadata.target() == self.check_target(metadata.target(), metadata.level()) { log::debug!(target: "tracing", "Enabled target: {}, level: {}", metadata.target(), metadata.level()); true } else { @@ -353,26 +439,12 @@ impl Subscriber for ProfilingSubscriber { } fn try_close(&self, span: Id) -> bool { - let span_datum = { + if let Some(span_datum) = { let mut span_data = self.span_data.lock(); span_data.remove(&span) - }; - if let Some(mut span_datum) = span_datum { - 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) { - span_datum.name = n; - } - if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { - span_datum.target = t; - } - if self.check_target(&span_datum.target, &span_datum.level) { - self.trace_handler.handle_span(span_datum); - } - } else { - self.trace_handler.handle_span(span_datum); - } - }; + } { + self.trace_handler.handle_span(span_datum); + } true } } diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs index 6022f48df4077..b6f992d73d315 100644 --- a/primitives/tracing/src/interface.rs +++ b/primitives/tracing/src/interface.rs @@ -123,7 +123,7 @@ impl Into for WasmTracingLevel { } #[derive(Encode, Decode)] -struct WasmTracingMetadata { +pub struct WasmTracingMetadata { target: Vec, level: WasmTracingLevel, file: Option>, @@ -163,10 +163,10 @@ impl From<&Metadata<'_>> for WasmTracingMetadata { #[derive(Encode, Decode)] -struct WasmTracingEvent; +pub struct WasmTracingEvent; #[derive(Encode, Decode)] -struct WasmTracingRecord; +pub struct WasmTracingRecord; pub trait TracingSubscriber { fn enabled(&self, metadata: WasmTracingMetadata) -> bool; From 9a4b9a25546408b324650d3b809f1bc0e79bdae2 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Fri, 24 Jul 2020 21:52:42 +0100 Subject: [PATCH 020/113] implement access to global TracingSubscriber from primitives --- Cargo.lock | 30 +++++------------------------- client/service/Cargo.toml | 1 + client/service/src/builder.rs | 1 + primitives/tracing/Cargo.toml | 4 ++-- primitives/tracing/src/lib.rs | 20 ++++++++++++++++---- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f930bda8f7c7f..3abfd9f23de15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4025,11 +4025,11 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" dependencies = [ - "parking_lot 0.9.0", + "parking_lot 0.10.2", ] [[package]] @@ -5896,27 +5896,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "rental" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8545debe98b2b139fb04cad8618b530e9b07c152d99a5de83c860b877d67847f" -dependencies = [ - "rental-impl", - "stable_deref_trait", -] - -[[package]] -name = "rental-impl" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" -dependencies = [ - "proc-macro2", - "quote 1.0.6", - "syn 1.0.33", -] - [[package]] name = "retain_mut" version = "0.1.1" @@ -7024,6 +7003,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-state-machine", + "sp-tracing", "sp-transaction-pool", "sp-trie", "sp-utils", @@ -8221,8 +8201,8 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", + "once_cell", "parity-scale-codec", - "rental", "sp-externalities", "sp-runtime-interface", "sp-std", diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 3511c29038299..f90a111256b48 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -72,6 +72,7 @@ sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } sc-offchain = { version = "2.0.0-rc5", path = "../offchain" } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc5"} sc-tracing = { version = "2.0.0-rc5", path = "../tracing" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } tracing = "0.1.10" parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index c71746f48a890..0d6eb217ce3a2 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -577,6 +577,7 @@ pub fn build( let subscriber = sc_tracing::ProfilingSubscriber::new( config.tracing_receiver, tracing_targets ); + sp_tracing::set_tracing_subscriber(Box::new(subscriber.clone())); match tracing::subscriber::set_global_default(subscriber) { Ok(_) => (), Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index afb1a9b3c936d..35692d3051a15 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -18,8 +18,8 @@ codec = { version = "1.3.1", package = "parity-scale-codec", optional = true, de sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } tracing = { version = "0.1.13", optional = true, default-features = false } tracing-core = { version = "0.1.11", optional = true, default-features = false } -rental = { version = "0.5.5", optional = true } log = { version = "0.4.8", optional = true } +once_cell = { version = "1.4.0", optional = true } [features] default = [ "std" ] @@ -30,6 +30,7 @@ with-tracing = [ "codec/derive", "codec/full", "sp-externalities", + "once_cell", ] std = [ "with-tracing", @@ -38,6 +39,5 @@ std = [ "codec/std", "sp-std/std", "sp-runtime-interface/std", - "rental", "log", ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index b06eb88652f09..d5ede24a94a69 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,10 +30,6 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -#[macro_use] -extern crate rental; - #[cfg(feature = "std")] #[doc(hidden)] pub use tracing; @@ -43,11 +39,17 @@ pub mod interface; #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; +#[cfg(feature = "std")] +use once_cell::sync::OnceCell; /// Flag to signal whether to run wasm tracing #[cfg(feature = "std")] static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); +/// Instance of the native subscriber in use +#[cfg(feature = "std")] +static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); + /// Runs given code within a tracing span, measuring it's execution time. /// /// If tracing is not enabled, the code is still executed. @@ -114,4 +116,14 @@ pub fn wasm_tracing_enabled() -> bool { #[cfg(feature = "std")] pub fn set_wasm_tracing(b: bool) { WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) +} + +#[cfg(feature = "std")] +pub fn set_tracing_subscriber(subscriber: Box) { + let _ = SUBSCRIBER_INSTANCE.set(subscriber); +} + +#[cfg(feature = "std")] +pub fn get_tracing_subscriber() -> Option> { + SUBSCRIBER_INSTANCE.get().cloned() } \ No newline at end of file From f8249188326254b6689f8deb7cf9102eae372fcf Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Sat, 25 Jul 2020 16:54:57 +0200 Subject: [PATCH 021/113] span for wasm --- Cargo.lock | 1 - primitives/io/Cargo.toml | 6 +- primitives/io/src/lib.rs | 2 +- primitives/runtime-interface/src/lib.rs | 2 +- primitives/tracing/Cargo.toml | 5 +- primitives/tracing/src/interface.rs | 182 +- primitives/tracing/src/lib.rs | 47 +- primitives/tracing/src/types.rs | 75 + primitives/tracing/src/wasm_tracing.rs | 2139 +++++++++++++++++++++++ 9 files changed, 2276 insertions(+), 183 deletions(-) create mode 100644 primitives/tracing/src/types.rs create mode 100644 primitives/tracing/src/wasm_tracing.rs diff --git a/Cargo.lock b/Cargo.lock index eab59693b6471..73a2329647027 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7930,7 +7930,6 @@ dependencies = [ "sp-runtime-interface", "sp-state-machine", "sp-std", - "sp-tracing", "sp-trie", "sp-wasm-interface", ] diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 7730f8337bce2..009092db91a87 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -24,7 +24,7 @@ sp-wasm-interface = { version = "2.0.0-rc5", path = "../../primitives/wasm-inter sp-runtime-interface = { version = "2.0.0-rc5", default-features = false, path = "../runtime-interface" } sp-trie = { version = "2.0.0-rc5", optional = true, path = "../../primitives/trie" } sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } -sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../tracing" } +# sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../tracing" } log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } @@ -42,8 +42,8 @@ std = [ "sp-runtime-interface/std", "sp-externalities", "sp-wasm-interface/std", - "sp-tracing/std", - "sp-tracing/with-tracing", + # "sp-tracing/std", + # "sp-tracing/with-tracing", "log", "futures", "parking_lot", diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index cc26fa64e7edc..e2ea43e8f7d15 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1143,7 +1143,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - sp_tracing::wasm_tracing::HostFunctions, + // sp_tracing::wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/runtime-interface/src/lib.rs b/primitives/runtime-interface/src/lib.rs index 6511f93e8de2a..83aca82e41ef0 100644 --- a/primitives/runtime-interface/src/lib.rs +++ b/primitives/runtime-interface/src/lib.rs @@ -112,7 +112,7 @@ pub use sp_wasm_interface; #[doc(hidden)] #[cfg(feature = "std")] -use tracing; +pub use tracing; #[doc(hidden)] pub use sp_std; diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 35692d3051a15..fc4cf926f01da 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-std = { version = "2.0.0-rc5", path = "../std", default-feature = false} sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} -codec = { version = "1.3.1", package = "parity-scale-codec", optional = true, default-features = false} +codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } tracing = { version = "0.1.13", optional = true, default-features = false } tracing-core = { version = "0.1.11", optional = true, default-features = false } @@ -26,7 +26,6 @@ default = [ "std" ] with-tracing = [ "tracing", "tracing-core", - "codec", "codec/derive", "codec/full", "sp-externalities", @@ -37,7 +36,9 @@ std = [ "tracing/std", "tracing-core/std", "codec/std", + "codec/derive", "sp-std/std", "sp-runtime-interface/std", + "sp-externalities", "log", ] diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs index b6f992d73d315..0755b9a91c8bf 100644 --- a/primitives/tracing/src/interface.rs +++ b/primitives/tracing/src/interface.rs @@ -22,164 +22,28 @@ use core::{ }; use codec::{Encode, Decode}; -use tracing_core::{ - subscriber::Subscriber, - metadata::{Metadata, Kind}, - field::{Field, Visit}, - event::{Event}, - span::{ - Attributes, - Id, - Record, - }, - Level, +use crate::{ + WasmMetadata, WasmAttributes, WasmRecord, WasmEvent }; -use sp_std::vec::Vec; -use sp_runtime_interface::runtime_interface; - - -#[derive(Encode, Decode, Debug)] -pub enum FieldValue { - I64(i64), - U64(u64), - Bool(bool), - Str(Vec), - Debug(Vec), -} - - -#[derive(Encode, Decode, Debug)] -pub struct Fields (pub Vec<(Vec, FieldValue)>); - -impl Visit for Fields { - fn record_debug(&mut self, field: &Field, value: &dyn Debug) { - todo!{} - // self.0.push((field.name().as_bytes().into(), FieldValue::Debug(format!("{:?}", value).into()))); - } - fn record_i64(&mut self, field: &Field, value: i64) { - self.0.push((field.name().as_bytes().into(), FieldValue::I64(value))); - } - fn record_u64(&mut self, field: &Field, value: u64) { - self.0.push((field.name().as_bytes().into(), FieldValue::U64(value))); - } - fn record_bool(&mut self, field: &Field, value: bool) { - self.0.push((field.name().as_bytes().into(), FieldValue::Bool(value))); - } - fn record_str(&mut self, field: &Field, value: &str) { - self.0.push((field.name().as_bytes().into(), FieldValue::Str(value.as_bytes().into()))); - } -} - -#[derive(Encode, Decode)] -pub struct WasmTracingAttributes { - pub parent_id: Option, - pub fields: Fields -} - -impl From<&Attributes<'_>> for WasmTracingAttributes { - fn from(a: &Attributes) -> WasmTracingAttributes { - let mut fields = Fields(Vec::new()); - a.record(&mut fields); - WasmTracingAttributes { - parent_id: a.parent().map(|a| a.into_u64()), - fields - } - } -} +#[cfg(feature = "std")] +use sp_externalities::{ExternalitiesExt, Externalities}; - -#[derive(Encode, Decode)] -pub enum WasmTracingLevel { - ERROR, - WARN, - INFO, - DEBUG, - TRACE -} - -impl From<&Level> for WasmTracingLevel { - fn from(lvl: &Level) -> WasmTracingLevel { - match *lvl { - Level::ERROR => WasmTracingLevel::ERROR, - Level::WARN => WasmTracingLevel::WARN, - Level::INFO => WasmTracingLevel::INFO, - Level::DEBUG => WasmTracingLevel::DEBUG, - Level::TRACE => WasmTracingLevel::TRACE, - } - } -} - -impl Into for WasmTracingLevel { - fn into(self) -> Level { - match self { - WasmTracingLevel::ERROR => Level::ERROR, - WasmTracingLevel::WARN => Level::WARN, - WasmTracingLevel::INFO => Level::INFO, - WasmTracingLevel::DEBUG => Level::DEBUG, - WasmTracingLevel::TRACE => Level::TRACE, - } - } -} - -#[derive(Encode, Decode)] -pub struct WasmTracingMetadata { - target: Vec, - level: WasmTracingLevel, - file: Option>, - line: Option, - module_path: Option>, - is_span: bool, -} - -impl From<&Metadata<'_>> for WasmTracingMetadata { - fn from(m: &Metadata) -> WasmTracingMetadata { - WasmTracingMetadata { - target: m.target().as_bytes().into(), - module_path: m.module_path().map(|m| m.as_bytes().into()), - file: m.file().map(|m| m.as_bytes().into()), - line: m.line().clone(), - level: m.level().into(), - is_span: m.is_span(), - } - } -} - -// #[cfg(feature="std")] -// impl<'a> Into> for WasmTracingMetadata { -// fn into(self) -> Metadata<'a> { -// Metadata::new( -// "wasm_tracing", // must be static, it's the same for all then -// std::str::from_utf8(self.target.as_slice()).unwrap_or(""), -// self.level.into(), -// self.file.as_ref().and_then(|s| std::str::from_utf8(s.as_slice()).ok()), -// self.line, -// self.module_path.as_ref().and_then(|s| std::str::from_utf8(s.as_slice()).ok()), -// Default::default(), -// if self.is_span { Kind::SPAN } else { Kind::EVENT } -// ) -// } -// } - - -#[derive(Encode, Decode)] -pub struct WasmTracingEvent; - -#[derive(Encode, Decode)] -pub struct WasmTracingRecord; +use sp_runtime_interface::runtime_interface; pub trait TracingSubscriber { - fn enabled(&self, metadata: WasmTracingMetadata) -> bool; - fn new_span(&self, span: WasmTracingAttributes) -> u64; - fn record(&self, span: u64, values: WasmTracingRecord); - fn event(&self, event: WasmTracingEvent); + fn enabled(&self, metadata: WasmMetadata) -> bool; + fn new_span(&self, span: WasmAttributes) -> u64; + fn record(&self, span: u64, values: WasmRecord); + fn event(&self, event: WasmEvent); fn enter(&self, span: u64); fn exit(&self, span: u64); } +#[cfg(feature="std")] sp_externalities::decl_extension! { /// The keystore extension to register/retrieve from the externalities. - pub struct WasmTracer(dyn TracingSubscriber + 'static + Send); + pub struct WasmTracer(Box); } @@ -187,34 +51,34 @@ sp_externalities::decl_extension! { // #[runtime_interface(wasm_only, no_tracing)] #[runtime_interface] pub trait WasmTracing { - fn enabled(&self, metadata: WasmTracingMetadata) -> bool { + fn enabled(&mut self, metadata: WasmMetadata) -> bool { self.extension::().map(|t|{ - t.enabled(metadata) + t.0.enabled(metadata) }).unwrap_or(false) } - fn new_span(&self, span: WasmTracingAttributes) -> u64 { + fn new_span(&mut self, span: WasmAttributes) -> u64 { self.extension::().map(|t|{ - t.new_span(span) + t.0.new_span(span) }).unwrap_or(0) } - fn record(&self, span: u64, values: WasmTracingRecord) { + fn record(&mut self, span: u64, values: WasmRecord) { self.extension::().map(|t|{ - t.record(span, values) + t.0.record(span, values) }); } - fn event(&self, event: WasmTracingEvent) { + fn event(&mut self, event: WasmEvent) { self.extension::().map(|t|{ - t.event(event) + t.0.event(event) }); } - fn enter(&self, span: u64) { + fn enter(&mut self, span: u64) { self.extension::().map(|t|{ - t.enter(span) + t.0.enter(span) }); } - fn exit(&self, span: u64) { + fn exit(&mut self, span: u64) { self.extension::().map(|t|{ - t.exit(span) + t.0.exit(span) }); } } \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index d5ede24a94a69..3808ef670f4bf 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,12 +30,21 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] +pub mod interface; +mod types; +pub use types::*; + +#[macro_export] +#[cfg(not(feature = "std"))] +mod wasm_tracing; + +#[macro_export] #[cfg(feature = "std")] -#[doc(hidden)] pub use tracing; -#[cfg(feature = "with-tracing")] -pub mod interface; +#[cfg(not(feature = "std"))] +pub use types::WasmLevel as Level; + #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; @@ -48,7 +57,7 @@ static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); /// Instance of the native subscriber in use #[cfg(feature = "std")] -static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); +static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); /// Runs given code within a tracing span, measuring it's execution time. /// @@ -86,15 +95,21 @@ macro_rules! tracing_span { /// sp_tracing::enter_span!("test-span"); /// ``` #[macro_export] +#[cfg(feature = "with-tracing")] macro_rules! enter_span { ( $name:expr ) => { - let __tracing_span__ = $crate::if_tracing!( - $crate::tracing::span!($crate::tracing::Level::TRACE, $name) - ); - let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); + // FIXME: this needs be name-dependent to avoid clashes + let __tracing_span__ = $crate::trace_span!($name); + let __tracing_guard__ = __tracing_span__.enter(); } } +#[macro_export] +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] +macro_rules! enter_span { + ( $name:expr ) => { {} } +} + /// Generates the given code if the tracing dependency is enabled. #[macro_export] #[cfg(feature = "std")] @@ -118,12 +133,12 @@ pub fn set_wasm_tracing(b: bool) { WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) } -#[cfg(feature = "std")] -pub fn set_tracing_subscriber(subscriber: Box) { - let _ = SUBSCRIBER_INSTANCE.set(subscriber); -} +// #[cfg(feature = "std")] +// pub fn set_tracing_subscriber(subscriber: Box) { +// let _ = SUBSCRIBER_INSTANCE.set(subscriber); +// } -#[cfg(feature = "std")] -pub fn get_tracing_subscriber() -> Option> { - SUBSCRIBER_INSTANCE.get().cloned() -} \ No newline at end of file +// #[cfg(feature = "std")] +// pub fn get_tracing_subscriber() -> Option> { +// SUBSCRIBER_INSTANCE.get().cloned() +// } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs new file mode 100644 index 0000000000000..db364a5066f93 --- /dev/null +++ b/primitives/tracing/src/types.rs @@ -0,0 +1,75 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![cfg_attr(not(feature = "std"), no_std)] + +use sp_std::{ + vec::Vec +}; +use sp_runtime_interface::pass_by::PassByCodec; +use codec::{Encode, Decode}; + + +#[derive(Encode, Decode, PassByCodec)] +pub enum WasmLevel { + ERROR, + WARN, + INFO, + DEBUG, + TRACE +} + +#[derive(Encode, Decode, PassByCodec)] +pub enum WasmFieldValue { + I64(i64), + U64(u64), + Bool(bool), + Str(Vec), + Debug(Vec), + Encoded(Vec), +} + +pub type WasmFields = Vec>; +pub type WasmValues = Vec<(Vec, WasmFieldValue)>; + +#[derive(Encode, Decode, PassByCodec)] +pub struct WasmMetadata { + pub name: Vec, + pub target: Vec, + pub level: WasmLevel, + pub file: Vec, + pub line: u32, + pub module_path: Vec, + pub is_span: bool, + pub fields: WasmFields, +} + +#[derive(Encode, Decode, PassByCodec)] +pub struct WasmAttributes { + pub parent_id: Option, + pub fields: WasmValues, +} + +#[derive(Encode, Decode, PassByCodec)] +pub struct WasmEvent { + pub parent: Option, + pub metadata: WasmMetadata, + pub fields: WasmValues, +} + +#[derive(Encode, Decode, PassByCodec)] +pub struct WasmRecord; diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs new file mode 100644 index 0000000000000..bd7627b872cf2 --- /dev/null +++ b/primitives/tracing/src/wasm_tracing.rs @@ -0,0 +1,2139 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +use sp_std::{ + vec +}; + +#[cfg(not(feature = "with-tracing"))] +mod inner { + #[doc(hidden)] + #[macro_export] + macro_rules! __tracing_mk_span { + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; + } + + + /// Constructs a new `Event` – noop + #[macro_export] + macro_rules! event { + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> { {} }; + + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => { {} }; + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> {{}}; + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; + ($lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, ?$($k:ident).+) => { {} }; + ($lvl:expr, %$($k:ident).+) => { {} }; + ($lvl:expr, $($k:ident).+) => { {} }; + ( $lvl:expr, $($arg:tt)+ ) => { {} }; + } +} + +#[cfg(feature = "with-tracing")] +mod inner { + use core::{ + module_path, concat, format_args, file, line, + }; + use crate::{WasmMetadata}; + use crate::interface::wasm_tracing; + + // just a simplistic holder for span and entered spans + // that exits on drop + pub struct Span(u64); // 0 means no item + pub struct Entered(u64); // 0 means no item + + impl Span { + pub fn enter(self) -> Entered { + if self.0 != 0 { + wasm_tracing::enter(self.0); + } + Entered(self.0) + } + } + + impl Entered { + pub fn exit(&mut self) { + if self.0 != 0 { + wasm_tracing::exit(self.0); + } + } + } + + impl Drop for Entered { + fn drop(&mut self) { + self.exit(); + } + } + + /// Constructs a new `Event`. + /// + /// The event macro is invoked with a `Level` and up to 32 key-value fields. + /// Optionally, a format string and arguments may follow the fields; this will + /// be used to construct an implicit field named "message". + /// + /// See [the top-level documentation][lib] for details on the syntax accepted by + /// this macro. + /// + /// [lib]: index.html#using-the-macros + /// + /// # Examples + /// + /// ```rust + /// use tracing::{event, Level}; + /// + /// # fn main() { + /// let data = (42, "forty-two"); + /// let private_data = "private"; + /// let error = "a bad error"; + /// + /// event!(Level::ERROR, %error, "Received error"); + /// event!( + /// target: "app_events", + /// Level::WARN, + /// private_data, + /// ?data, + /// "App warning: {}", + /// error + /// ); + /// event!(Level::INFO, the_answer = data.0); + /// # } + /// ``` + /// + // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As + // /// events are recorded immediately when the macro is invoked, there is no + // /// opportunity for fields to be recorded later. A trailing comma on the final + // /// field is valid. + // /// + // /// For example, the following does not compile: + // /// ```rust,compile_fail + // /// # #[macro_use] + // /// # extern crate tracing; + // /// # use tracing::Level; + // /// # fn main() { + // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") + // /// #} + // /// ``` + #[macro_export] + macro_rules! event { + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target, + level: $lvl, + module_path: module_path().as_bytes().to_vec(), + fields: $($fields)* + }; + if $crate::is_enabled!(&metdata) { + wasm_tracing::event(WasmEvent { + parent: $parent, + metadata, + &$crate::valueset!(meta.fields(), $($fields)*) + }) + } + } + } + }); + + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::event!( + target: $target, + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) + ); + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target, + level: $lvl, + module_path: module_path().as_bytes().to_vec(), + fields: $($fields)* + }; + if $crate::is_enabled!(&metdata) { + wasm_tracing::event(WasmEvent { + parent: None, + metadata, + &$crate::valueset!(meta.fields(), $($fields)*) + }); + } + } + } + }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::event!( + target: $target, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $lvl, { $($arg)+ }) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + parent: $parent, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { $($k).+ = $($field)*} + ) + ); + ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { $($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { ?$($k).+, $($field)*} + ) + ); + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { %$($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+) => ( + $crate::event!($lvl, ?$($k).+,) + ); + ($lvl:expr, %$($k:ident).+) => ( + $crate::event!($lvl, %$($k).+,) + ); + ($lvl:expr, $($k:ident).+) => ( + $crate::event!($lvl, $($k).+,) + ); + ( $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) + ); + } + + #[doc(hidden)] + #[macro_export] + macro_rules! __tracing_mk_span { + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; + let metadata = WasmMetadata { + name: $name.as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: true, + target: $target, + level: $lvl, + module_path: module_path().as_bytes().to_vec(), + fields: $($fields)* + }; + if $crate::is_enabled!(metadata) { + let span_id = wasm_tracing::new_span(WasmAttributes{ + parent: Some($parent), + metadata, + &$crate::valueset!(meta.fields(), $($fields)*) + }) + $crate::wasm_tracing::Span(span_id) + } else { + $crate::wasm_tracing::Span(0) + } + } else { + $crate::wasm_tracing::Span(0) + } + } + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; + let metadata = WasmMetadata { + name: $name.as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: true, + target: $target, + level: $lvl, + module_path: module_path().as_bytes().to_vec(), + fields: $($fields)* + }; + if $crate::is_enabled!(metadata) { + let span_id = wasm_tracing::new_span(WasmAttributes{ + parent: None, + metadata, + &$crate::valueset!(meta.fields(), $($fields)*) + }) + $crate::wasm_tracing::Span(span_id) + } else { + $crate::wasm_tracing::Span(0) + } + } else { + $crate::wasm_tracing::Span(0) + } + } + }; + } +} + +pub use inner::*; + +/// Constructs a new span. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// Creating a new span: +/// ``` +/// # use tracing::{span, Level}; +/// # fn main() { +/// let span = span!(Level::TRACE, "my span"); +/// let _enter = span.enter(); +/// // do work inside the span... +/// # } +/// ``` +#[macro_export] +macro_rules! span { + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, parent: $parent, $lvl, $name,) + }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::__tracing_mk_span!(target: $target, parent: $parent, $lvl, $name, $($fields)*) + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::__tracing_mk_span!(target: $target, $lvl, $name, $($fields)*) + }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, parent: $parent, $lvl, $name,) + }; + (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $lvl, + $name, + $($fields)* + ) + }; + (parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $lvl, + $name, + ) + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: $target, + $lvl, + $name, + $($fields)* + ) + }; + (target: $target:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, $lvl, $name,) + }; + ($lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: module_path!(), + $lvl, + $name, + $($fields)* + ) + }; + ($lvl:expr, $name:expr) => { + $crate::span!( + target: module_path!(), + $lvl, + $name, + ) + }; +} + +/// Constructs a span at the trace level. +/// +/// [Fields] and [attributes] are set using the same syntax as the [`span!`] +/// macro. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// [attributes]: index.html#configuring-attributes +/// [Fields]: index.html#recording-fields +/// [`span!`]: macro.span.html +/// +/// # Examples +/// +/// ```rust +/// # use tracing::{trace_span, span, Level}; +/// # fn main() { +/// trace_span!("my_span"); +/// // is equivalent to: +/// span!(Level::TRACE, "my_span"); +/// # } +/// ``` +/// +/// ```rust +/// # use tracing::{trace_span, span, Level}; +/// # fn main() { +/// let span = trace_span!("my span"); +/// span.in_scope(|| { +/// // do work inside the span... +/// }); +/// # } +/// ``` +#[macro_export] +macro_rules! trace_span { + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::trace_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::trace_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::trace_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + ($name:expr) => { $crate::trace_span!($name,) }; +} + +/// Constructs a span at the debug level. +/// +/// [Fields] and [attributes] are set using the same syntax as the [`span!`] +/// macro. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// [attributes]: index.html#configuring-attributes +/// [Fields]: index.html#recording-fields +/// [`span!`]: macro.span.html +/// +/// # Examples +/// +/// ```rust +/// # use tracing::{debug_span, span, Level}; +/// # fn main() { +/// debug_span!("my_span"); +/// // is equivalent to: +/// span!(Level::DEBUG, "my_span"); +/// # } +/// ``` +/// +/// ```rust +/// # use tracing::debug_span; +/// # fn main() { +/// let span = debug_span!("my span"); +/// span.in_scope(|| { +/// // do work inside the span... +/// }); +/// # } +/// ``` +#[macro_export] +macro_rules! debug_span { + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::debug_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::debug_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::debug_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::debug_span!($name,)}; +} + +/// Constructs a span at the info level. +/// +/// [Fields] and [attributes] are set using the same syntax as the [`span!`] +/// macro. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// [attributes]: index.html#configuring-attributes +/// [Fields]: index.html#recording-fields +/// [`span!`]: macro.span.html +/// +/// # Examples +/// +/// ```rust +/// # use tracing::{span, info_span, Level}; +/// # fn main() { +/// info_span!("my_span"); +/// // is equivalent to: +/// span!(Level::INFO, "my_span"); +/// # } +/// ``` +/// +/// ```rust +/// # use tracing::info_span; +/// # fn main() { +/// let span = info_span!("my span"); +/// span.in_scope(|| { +/// // do work inside the span... +/// }); +/// # } +/// ``` +#[macro_export] +macro_rules! info_span { + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::info_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::info_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::info_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::INFO, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::info_span!($name,)}; +} + +/// Constructs a span at the warn level. +/// +/// [Fields] and [attributes] are set using the same syntax as the [`span!`] +/// macro. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// [attributes]: index.html#configuring-attributes +/// [Fields]: index.html#recording-fields +/// [`span!`]: macro.span.html +/// +/// # Examples +/// +/// ```rust +/// # use tracing::{warn_span, span, Level}; +/// # fn main() { +/// warn_span!("my_span"); +/// // is equivalent to: +/// span!(Level::WARN, "my_span"); +/// # } +/// ``` +/// +/// ```rust +/// use tracing::warn_span; +/// # fn main() { +/// let span = warn_span!("my span"); +/// span.in_scope(|| { +/// // do work inside the span... +/// }); +/// # } +/// ``` +#[macro_export] +macro_rules! warn_span { + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::warn_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::warn_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::warn_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::WARN, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::warn_span!($name,)}; +} +/// Constructs a span at the error level. +/// +/// [Fields] and [attributes] are set using the same syntax as the [`span!`] +/// macro. +/// +/// See [the top-level documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [lib]: index.html#using-the-macros +/// [attributes]: index.html#configuring-attributes +/// [Fields]: index.html#recording-fields +/// [`span!`]: macro.span.html +/// +/// # Examples +/// +/// ```rust +/// # use tracing::{span, error_span, Level}; +/// # fn main() { +/// error_span!("my_span"); +/// // is equivalent to: +/// span!(Level::ERROR, "my_span"); +/// # } +/// ``` +/// +/// ```rust +/// # use tracing::error_span; +/// # fn main() { +/// let span = error_span!("my span"); +/// span.in_scope(|| { +/// // do work inside the span... +/// }); +/// # } +/// ``` +#[macro_export] +macro_rules! error_span { + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::error_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::error_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::error_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::error_span!($name,)}; +} + +/// Constructs an event at the trace level. +/// +/// This functions similarly to the [`event!`] macro. See [the top-level +/// documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [`event!`]: macro.event.html +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// ```rust +/// use tracing::trace; +/// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } +/// # impl Position { +/// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; +/// # fn dist(&self, other: Position) -> f32 { +/// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2(); +/// # (x + y).sqrt() +/// # } +/// # } +/// # fn main() { +/// let pos = Position { x: 3.234, y: -1.223 }; +/// let origin_dist = pos.dist(Position::ORIGIN); +/// +/// trace!(position = ?pos, ?origin_dist); +/// trace!( +/// target: "app_events", +/// position = ?pos, +/// "x is {} and y is {}", +/// if pos.x >= 0.0 { "positive" } else { "negative" }, +/// if pos.y >= 0.0 { "positive" } else { "negative" } +/// ); +/// # } +/// ``` +#[macro_export] +macro_rules! trace { + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + {}, + $($arg)+ + ) + ); +} + +/// Constructs an event at the debug level. +/// +/// This functions similarly to the [`event!`] macro. See [the top-level +/// documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [`event!`]: macro.event.html +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// ```rust +/// use tracing::debug; +/// # fn main() { +/// # #[derive(Debug)] struct Position { x: f32, y: f32 } +/// +/// let pos = Position { x: 3.234, y: -1.223 }; +/// +/// debug!(?pos.x, ?pos.y); +/// debug!(target: "app_events", position = ?pos, "New position"); +/// # } +/// ``` +#[macro_export] +macro_rules! debug { + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + {}, + $($arg)+ + ) + ); +} + +/// Constructs an event at the info level. +/// +/// This functions similarly to the [`event!`] macro. See [the top-level +/// documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [`event!`]: macro.event.html +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// ```rust +/// use tracing::info; +/// # // this is so the test will still work in no-std mode +/// # #[derive(Debug)] +/// # pub struct Ipv4Addr; +/// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } +/// # fn main() { +/// # struct Connection { port: u32, speed: f32 } +/// use tracing::field; +/// +/// let addr = Ipv4Addr::new(127, 0, 0, 1); +/// let conn = Connection { port: 40, speed: 3.20 }; +/// +/// info!(conn.port, "connected to {:?}", addr); +/// info!( +/// target: "connection_events", +/// ip = ?addr, +/// conn.port, +/// ?conn.speed, +/// ); +/// # } +/// ``` +#[macro_export] +macro_rules! info { + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + {}, + $($arg)+ + ) + ); +} + +/// Constructs an event at the warn level. +/// +/// This functions similarly to the [`event!`] macro. See [the top-level +/// documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [`event!`]: macro.event.html +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// ```rust +/// use tracing::warn; +/// # fn main() { +/// +/// let warn_description = "Invalid Input"; +/// let input = &[0x27, 0x45]; +/// +/// warn!(?input, warning = warn_description); +/// warn!( +/// target: "input_events", +/// warning = warn_description, +/// "Received warning for input: {:?}", input, +/// ); +/// # } +/// ``` +#[macro_export] +macro_rules! warn { + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + {}, + $($arg)+ + ) + ); +} + +/// Constructs an event at the error level. +/// +/// This functions similarly to the [`event!`] macro. See [the top-level +/// documentation][lib] for details on the syntax accepted by +/// this macro. +/// +/// [`event!`]: macro.event.html +/// [lib]: index.html#using-the-macros +/// +/// # Examples +/// +/// ```rust +/// use tracing::error; +/// # fn main() { +/// +/// let (err_info, port) = ("No connection", 22); +/// +/// error!(port, error = %err_info); +/// error!(target: "app_events", "App Error: {}", err_info); +/// error!({ info = err_info }, "error on port: {}", port); +/// # } +/// ``` +#[macro_export] +macro_rules! error { + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + {}, + $($arg)+ + ) + ); +} + + +#[macro_export] +// TODO: determine if this ought to be public API? +#[doc(hidden)] +macro_rules! level_enabled { + ($lvl:expr) => { + // FIXME: use the runtime interface to figure this out + true + // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL + + }; +} + +#[macro_export] +// TODO: determine if this ought to be public API? +#[doc(hidden)] +macro_rules! is_enabled { + ($metadata:expr) => {{ + // FIXME: use the runtime interface to figure this out + true + }}; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! valueset { + + // === base case === + (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { + vec![ $($val),* ] + }; + + // === recursive case (more tts) === + + // TODO(#1138): determine a new syntax for uninitialized span fields, and + // re-enable this. + // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { + // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) + // }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$val as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$val as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + $next, + ) + }; + // Remainder is unparseable, but exists --- must be format args! + (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { + $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, ) + }; + + // === entry === + ($fields:expr, $($kvs:tt)+) => { + { + #[allow(unused_imports)] + use $crate::field::{debug, display, Value}; + let mut iter = $fields.iter(); + $fields.value_set($crate::valueset!( + @ { }, + iter.next().expect("FieldSet corrupted (this is a bug)"), + $($kvs)+ + )) + } + }; + ($fields:expr,) => { + { + $fields.value_set(&[]) + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! fieldset { + // == base case == + (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { + vec![ $($out),* ] + }; + + // == recursive cases (more tts) == + (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + // TODO(#1138): determine a new syntax for uninitialized span fields, and + // re-enable this. + // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { + // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + // }; + (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + + // Remainder is unparseable, but exists --- must be format args! + (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { + $crate::fieldset!(@ { "message", $($out),*, }) + }; + + // == entry == + ($($args:tt)*) => { + $crate::fieldset!(@ { } $($args)*,) + }; + +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __tracing_stringify { + ($s:expr) => { + stringify!($s) + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! if_log_enabled { + ($e:expr;) => { + $crate::if_log_enabled! { $e } + }; + ($if_log:block) => { + $crate::if_log_enabled! { $if_log else {} } + }; + ($if_log:block else $else_block:block) => { + $else_block + }; +} \ No newline at end of file From 4093d15100b993f03ae4dd50253c802bea2e85fb Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Tue, 28 Jul 2020 15:55:45 +0100 Subject: [PATCH 022/113] increment towards Wasm Tracing Subscriber implementation --- Cargo.lock | 106 +- client/service/src/builder.rs | 1 + client/tracing/Cargo.toml | 7 +- client/tracing/src/lib.rs | 376 ++++- primitives/io/src/lib.rs | 68 +- primitives/tracing/Cargo.toml | 29 +- primitives/tracing/src/interface.rs | 84 + primitives/tracing/src/lib.rs | 46 +- primitives/tracing/src/types.rs | 76 + primitives/tracing/src/wasm_tracing.rs | 2139 ++++++++++++++++++++++++ 10 files changed, 2796 insertions(+), 136 deletions(-) create mode 100644 primitives/tracing/src/interface.rs create mode 100644 primitives/tracing/src/types.rs create mode 100644 primitives/tracing/src/wasm_tracing.rs diff --git a/Cargo.lock b/Cargo.lock index 40332c7e9e821..2a81bc8c791db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3246,6 +3246,15 @@ dependencies = [ "libc", ] +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.8" @@ -4051,11 +4060,11 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" dependencies = [ - "parking_lot 0.9.0", + "parking_lot 0.10.2", ] [[package]] @@ -5892,6 +5901,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ "byteorder", + "regex-syntax", ] [[package]] @@ -5921,27 +5931,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "rental" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8545debe98b2b139fb04cad8618b530e9b07c152d99a5de83c860b877d67847f" -dependencies = [ - "rental-impl", - "stable_deref_trait", -] - -[[package]] -name = "rental-impl" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" -dependencies = [ - "proc-macro2", - "quote 1.0.6", - "syn 1.0.33", -] - [[package]] name = "retain_mut" version = "0.1.1" @@ -7147,6 +7136,7 @@ dependencies = [ "sp-tracing", "tracing", "tracing-core", + "tracing-subscriber", ] [[package]] @@ -7431,6 +7421,15 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sharded-slab" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "0.1.1" @@ -8237,8 +8236,12 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", - "rental", + "once_cell", + "parity-scale-codec", + "sp-externalities", + "sp-std", "tracing", + "tracing-core", ] [[package]] @@ -9234,9 +9237,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.14" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c6b59d116d218cb2d990eb06b77b64043e0268ef7323aae63d8b30ae462923" +checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" dependencies = [ "cfg-if", "tracing-attributes", @@ -9245,9 +9248,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" dependencies = [ "proc-macro2", "quote 1.0.6", @@ -9256,11 +9259,52 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.10" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-log" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" +checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" dependencies = [ "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4f5dd7095c2481b7b3cbed71c8de53085fb3542bc3c2b4c73cba43e8f11c7ba" +dependencies = [ + "ansi_term 0.12.1", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec 1.4.1", + "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index a262e6488bb23..3c35bc8cee290 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -576,6 +576,7 @@ pub fn build( let subscriber = sc_tracing::ProfilingSubscriber::new( config.tracing_receiver, tracing_targets ); + sp_tracing::set_tracing_subscriber(Box::new(subscriber.clone())); match tracing::subscriber::set_global_default(subscriber) { Ok(_) => (), Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 998dfb94de0c7..ee406e025b7f5 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -19,10 +19,11 @@ 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" } +tracing-core = "0.1.11" +tracing-subscriber = "0.2.7" +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } [dev-dependencies] -tracing = "0.1.10" +tracing = "0.1.16" diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index c2b036e218f15..27ee3666ea8f5 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -26,6 +26,7 @@ use rustc_hash::FxHashMap; use std::fmt; +use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{Duration, Instant}; @@ -39,12 +40,34 @@ use tracing_core::{ span::{Attributes, Id, Record}, subscriber::Subscriber, }; +use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; -use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; +use sp_tracing::types::{ + WasmLevel, + WasmFieldValue, + WasmFields, + WasmValues, + WasmMetadata, + WasmAttributes, + WasmEvent, + WasmRecord, +}; +use sp_tracing::interface::TracingSubscriber; const ZERO_DURATION: Duration = Duration::from_nanos(0); const PROXY_TARGET: &'static str = "sp_tracing::proxy"; +const UNABLE_TO_DECODE: &'static str = "Unable to decode"; + +/// Responsible for assigning ids to new spans, which are not re-used. +#[derive(Clone)] +pub struct ProfilingSubscriber { + next_id: Arc, + targets: Arc>>, + trace_handler: Arc, + span_data: Arc>>, + current_span: Arc, +} /// Used to configure how to receive the metrics #[derive(Debug, Clone)] @@ -65,14 +88,28 @@ impl Default for TracingReceiver { pub trait TraceHandler: Send + Sync { /// Process a `SpanDatum` fn handle_span(&self, span: SpanDatum); + /// Process a `TraceEvent` + fn handle_event(&self, event: TraceEvent); +} + +/// Represents a tracing event, complete with values +#[derive(Debug)] +pub struct TraceEvent { + pub name: &'static str, + pub target: String, + pub level: Level, + pub values: Values, + pub parent_id: Option, } /// Represents a single instance of a tracing span #[derive(Debug)] pub struct SpanDatum { /// id for this span - pub id: u64, - /// Name of the span + pub id: Id, + /// id of the parent span, if any + pub parent_id: Option, + /// Name of this span pub name: String, /// Target, typically module pub target: String, @@ -192,14 +229,6 @@ impl slog::Value for Values { } } -/// Responsible for assigning ids to new spans, which are not re-used. -pub struct ProfilingSubscriber { - next_id: AtomicU64, - targets: Vec<(String, Level)>, - trace_handler: Box, - span_data: Mutex>, -} - impl ProfilingSubscriber { /// Takes a `TracingReceiver` and a comma separated list of targets, /// either with a level: "pallet=trace,frame=debug" @@ -207,9 +236,9 @@ impl ProfilingSubscriber { /// wasm_tracing indicates whether to enable wasm traces pub fn new(receiver: TracingReceiver, targets: &str) -> ProfilingSubscriber { match receiver { - TracingReceiver::Log => Self::new_with_handler(Box::new(LogTraceHandler), targets), + TracingReceiver::Log => Self::new_with_handler(Arc::new(LogTraceHandler), targets), TracingReceiver::Telemetry => Self::new_with_handler( - Box::new(TelemetryTraceHandler), + Arc::new(TelemetryTraceHandler), targets, ), } @@ -220,20 +249,21 @@ impl ProfilingSubscriber { /// either with a level, eg: "pallet=trace" /// or without: "pallet" in which case the level defaults to `trace`. /// wasm_tracing indicates whether to enable wasm traces - pub fn new_with_handler(trace_handler: Box, targets: &str) - -> ProfilingSubscriber + pub fn new_with_handler(trace_handler: Arc, targets: &str) + -> ProfilingSubscriber { let targets: Vec<_> = targets.split(',').map(|s| parse_target(s)).collect(); ProfilingSubscriber { - next_id: AtomicU64::new(1), - targets, + next_id: Arc::new(AtomicU64::new(1)), + targets: Arc::new(Mutex::new(targets)), trace_handler, - span_data: Mutex::new(FxHashMap::default()), + span_data: Arc::new(Mutex::new(FxHashMap::default())), + current_span: Arc::new(CurrentSpan::new()), } } fn check_target(&self, target: &str, level: &Level) -> bool { - for t in &self.targets { + for t in &*self.targets.lock() { if target.starts_with(t.0.as_str()) && level <= &t.1 { return true; } @@ -259,9 +289,89 @@ fn parse_target(s: &str) -> (String, Level) { } } +impl From for Values { + fn from(fields: WasmValues) -> Self { + let mut values = Values::default(); + for (k, v) in fields { + if let Ok(key) = String::from_utf8(k) { + match v { + WasmFieldValue::Bool(v) => { values.bool_values.insert(key, v); } + WasmFieldValue::I64(v) => { values.i64_values.insert(key, v); }, + WasmFieldValue::U64(v) => { values.u64_values.insert(key, v); }, + WasmFieldValue::Str(v) => { + let s = String::from_utf8(v).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()); + values.string_values.insert(key, s); + } + WasmFieldValue::Debug(v) => { + let s = String::from_utf8(v).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()); + values.string_values.insert(key, s); + } + WasmFieldValue::Encoded(_v) => { + // TODO + } + } + } + } + values + } +} + +impl TracingSubscriber for ProfilingSubscriber { + fn enabled(&self, metadata: WasmMetadata) -> bool { + // TODO move levels into static and implement + true + } + + fn new_span(&self, attrs: WasmAttributes) -> u64 { + let id = self.next_id.fetch_add(1, Ordering::Relaxed); + let values = attrs.fields.into(); + let span_datum = SpanDatum { + id: Id::from_u64(id.clone()), + parent_id: attrs.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), + name: String::from_utf8(attrs.metadata.name).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), + target: String::from_utf8(attrs.metadata.target).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), + level: attrs.metadata.level.into(), + line: attrs.metadata.line, + start_time: Instant::now(), + overall_time: ZERO_DURATION, + values, + }; + self.span_data.lock().insert(span_datum.id.clone(), span_datum); + id + } + + fn record(&self, _span: u64, _values: WasmRecord) { + // TODO + } + + fn event(&self, _event: WasmEvent) { + // TODO + } + + fn enter(&self, span: u64) { + let id = Id::from_u64(span); + self.current_span.enter(id.clone()); + let mut span_data = self.span_data.lock(); + let start_time = Instant::now(); + if let Some(mut s) = span_data.get_mut(&id) { + s.start_time = start_time; + } + } + + fn exit(&self, span: u64) { + self.current_span.exit(); + let end_time = Instant::now(); + let mut span_data = self.span_data.lock(); + if let Some(mut s) = span_data.remove(&Id::from_u64(span)) { + s.overall_time = end_time - s.start_time + s.overall_time; + self.trace_handler.handle_span(s); + } + } +} + impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if metadata.target() == PROXY_TARGET || self.check_target(metadata.target(), metadata.level()) { + if self.check_target(metadata.target(), metadata.level()) { log::debug!(target: "tracing", "Enabled target: {}, level: {}", metadata.target(), metadata.level()); true } else { @@ -271,17 +381,18 @@ impl Subscriber for ProfilingSubscriber { } fn new_span(&self, attrs: &Attributes<'_>) -> Id { - let id = self.next_id.fetch_add(1, Ordering::Relaxed); + let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed)); 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 Id::from_u64(id); - } - } + // if let Some(wasm_target) = values.string_values.get(WASM_TARGET_KEY) { + // if !self.check_target(wasm_target, attrs.metadata().level()) { + // return id + // } + // } let span_datum = SpanDatum { - id, + id: id.clone(), + parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), name: attrs.metadata().name().to_owned(), target: attrs.metadata().target().to_owned(), level: attrs.metadata().level().clone(), @@ -290,56 +401,57 @@ impl Subscriber for ProfilingSubscriber { overall_time: ZERO_DURATION, values, }; - self.span_data.lock().insert(id, span_datum); - Id::from_u64(id) + self.span_data.lock().insert(id.clone(), span_datum); + id } fn record(&self, span: &Id, values: &Record<'_>) { let mut span_data = self.span_data.lock(); - if let Some(s) = span_data.get_mut(&span.into_u64()) { + if let Some(s) = span_data.get_mut(span) { values.record(&mut s.values); } } fn record_follows_from(&self, _span: &Id, _follows: &Id) {} - fn event(&self, _event: &Event<'_>) {} + fn event(&self, event: &Event<'_>) { + let mut values = Values::default(); + event.record(&mut values); + let trace_event = TraceEvent { + name: event.metadata().name(), + target: event.metadata().target().to_owned(), + level: event.metadata().level().clone(), + values, + parent_id: event.parent().cloned().or_else(|| self.current_span.id()), + }; + self.trace_handler.handle_event(trace_event); + } fn enter(&self, span: &Id) { + self.current_span.enter(span.clone()); let mut span_data = self.span_data.lock(); let start_time = Instant::now(); - if let Some(mut s) = span_data.get_mut(&span.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.start_time = start_time; } } fn exit(&self, span: &Id) { + 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.into_u64()) { + if let Some(mut s) = span_data.get_mut(&span) { s.overall_time = end_time - s.start_time + s.overall_time; } } fn try_close(&self, span: Id) -> bool { - let span_datum = { + if let Some(span_datum) = { let mut span_data = self.span_data.lock(); - span_data.remove(&span.into_u64()) - }; - if let Some(mut span_datum) = span_datum { - 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) { - span_datum.name = n; - } - if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { - span_datum.target = t; - } - } - if self.check_target(&span_datum.target, &span_datum.level) { - self.trace_handler.handle_span(span_datum); - } - }; + span_data.remove(&span) + } { + self.trace_handler.handle_span(span_datum); + } true } } @@ -361,23 +473,38 @@ impl TraceHandler for LogTraceHandler { fn handle_span(&self, span_datum: SpanDatum) { if span_datum.values.is_empty() { log::log!( - log_level(span_datum.level), - "{}: {}, time: {}", + log_level(span_datum.level), + "{}: {}, time: {}, id: {}, parent_id: {:?}", span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), + span_datum.id.into_u64(), + span_datum.parent_id.map(|s| s.into_u64()), ); } else { log::log!( log_level(span_datum.level), - "{}: {}, time: {}, {}", + "{}: {}, time: {}, id: {}, parent_id: {:?}, values: {}", span_datum.target, span_datum.name, span_datum.overall_time.as_nanos(), + span_datum.id.into_u64(), + span_datum.parent_id.map(|s| s.into_u64()), span_datum.values, ); } } + + fn handle_event(&self, event: TraceEvent) { + log::log!( + log_level(event.level), + "{}: {}, parent_id: {:?}, values: {}", + event.name, + event.target, + event.parent_id.map(|s| s.into_u64()), + event.values + ); + } } /// TraceHandler for sending span data to telemetry, @@ -390,11 +517,21 @@ impl TraceHandler for TelemetryTraceHandler { telemetry!(SUBSTRATE_INFO; "tracing.profiling"; "name" => span_datum.name, "target" => span_datum.target, - "line" => span_datum.line, "time" => span_datum.overall_time.as_nanos(), + "id" => span_datum.id.into_u64(), + "parent_id" => span_datum.parent_id.map(|i| i.into_u64()), "values" => span_datum.values ); } + + fn handle_event(&self, event: TraceEvent) { + telemetry!(SUBSTRATE_INFO; "tracing.event"; + "name" => event.name, + "target" => event.target, + "parent_id" => event.parent_id.map(|i| i.into_u64()), + "values" => event.values + ); + } } #[cfg(test)] @@ -404,37 +541,47 @@ mod tests { struct TestTraceHandler { spans: Arc>>, + events: Arc>>, } impl TraceHandler for TestTraceHandler { fn handle_span(&self, sd: SpanDatum) { self.spans.lock().push(sd); } + + fn handle_event(&self, event: TraceEvent) { + self.events.lock().push(event); + } } - fn setup_subscriber() -> (ProfilingSubscriber, Arc>>) { + fn setup_subscriber() -> (ProfilingSubscriber, Arc>>, Arc>>) { let spans = Arc::new(Mutex::new(Vec::new())); + let events = Arc::new(Mutex::new(Vec::new())); let handler = TestTraceHandler { spans: spans.clone(), + events: events.clone(), }; let test_subscriber = ProfilingSubscriber::new_with_handler( Box::new(handler), - "test_target" + "test_target", ); - (test_subscriber, spans) + (test_subscriber, spans, events) } #[test] fn test_span() { - let (sub, spans) = setup_subscriber(); + let (sub, spans, events) = setup_subscriber(); let _sub_guard = tracing::subscriber::set_default(sub); let span = tracing::info_span!(target: "test_target", "test_span1"); assert_eq!(spans.lock().len(), 0); + assert_eq!(events.lock().len(), 0); let _guard = span.enter(); assert_eq!(spans.lock().len(), 0); + assert_eq!(events.lock().len(), 0); drop(_guard); drop(span); assert_eq!(spans.lock().len(), 1); + assert_eq!(events.lock().len(), 0); let sd = spans.lock().remove(0); assert_eq!(sd.name, "test_span1"); assert_eq!(sd.target, "test_target"); @@ -442,9 +589,26 @@ mod tests { assert!(time > 0); } + #[test] + fn test_span_parent_id() { + let (sub, spans, _events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + let span2 = tracing::info_span!(target: "test_target", "test_span2"); + let _guard2 = span2.enter(); + drop(_guard2); + drop(span2); + let sd2 = spans.lock().remove(0); + drop(_guard1); + drop(span1); + let sd1 = spans.lock().remove(0); + assert_eq!(sd1.id, sd2.parent_id.unwrap()) + } + #[test] fn test_span_values() { - let (sub, spans) = setup_subscriber(); + let (sub, spans, _events) = setup_subscriber(); let _sub_guard = tracing::subscriber::set_default(sub); let test_bool = true; let test_u64 = 1u64; @@ -470,4 +634,98 @@ mod tests { assert_eq!(values.i64_values.get("test_i64").unwrap(), &test_i64); assert_eq!(values.string_values.get("test_str").unwrap(), &test_str.to_owned()); } + + #[test] + fn test_event() { + let (sub, _spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event"); + let mut te1 = events.lock().remove(0); + assert_eq!(te1.values.string_values.remove(&"message".to_owned()).unwrap(), "test_event".to_owned()); + } + + #[test] + fn test_event_parent_id() { + let (sub, spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_default(sub); + + // enter span + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + + // emit event + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event"); + + //exit span + drop(_guard1); + drop(span1); + + let sd1 = spans.lock().remove(0); + let te1 = events.lock().remove(0); + + assert_eq!(sd1.id, te1.parent_id.unwrap()); + } + + #[test] + fn test_parent_id_with_threads() { + use std::sync::mpsc; + use std::thread; + + let (sub, spans, events) = setup_subscriber(); + let _sub_guard = tracing::subscriber::set_global_default(sub); + let span1 = tracing::info_span!(target: "test_target", "test_span1"); + let _guard1 = span1.enter(); + + let (tx, rx) = mpsc::channel(); + let handle = thread::spawn(move || { + let span2 = tracing::info_span!(target: "test_target", "test_span2"); + let _guard2 = span2.enter(); + // emit event + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event1"); + for msg in rx.recv() { + if msg == false { + break; + } + } + // gard2 and span2 dropped / exited + }); + + // wait for Event to be dispatched and stored + while events.lock().is_empty() { + thread::sleep(Duration::from_millis(1)); + } + + // emit new event (will be second item in Vec) while span2 still active in other thread + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event2"); + + // stop thread and drop span + let _ = tx.send(false); + let _ = handle.join(); + + // wait for Span to be dispatched and stored + while spans.lock().is_empty() { + thread::sleep(Duration::from_millis(1)); + } + let span2 = spans.lock().remove(0); + let event1 = events.lock().remove(0); + drop(_guard1); + drop(span1); + + // emit event with no parent + tracing::event!(target: "test_target", tracing::Level::INFO, "test_event3"); + + let span1 = spans.lock().remove(0); + let event2 = events.lock().remove(0); + + assert_eq!(event1.values.string_values.get("message").unwrap(), "test_event1"); + assert_eq!(event2.values.string_values.get("message").unwrap(), "test_event2"); + assert!(span1.parent_id.is_none()); + assert!(span2.parent_id.is_none()); + assert_eq!(span2.id, event1.parent_id.unwrap()); + assert_eq!(span1.id, event2.parent_id.unwrap()); + assert_ne!(span2.id, span1.id); + + let event3 = events.lock().remove(0); + assert!(event3.parent_id.is_none()); + } } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 59d1c4f37ef27..32dd87d97aa92 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -997,11 +997,11 @@ pub trait Logging { } } -#[cfg(feature = "std")] -sp_externalities::decl_extension! { - /// Extension to allow running traces in wasm via Proxy - pub struct TracingProxyExt(sp_tracing::proxy::TracingProxy); -} +// #[cfg(feature = "std")] +// sp_externalities::decl_extension! { +// /// Extension to allow running traces in wasm via Proxy +// pub struct TracingProxyExt(sp_tracing::proxy::TracingProxy); +// } /// Interface that provides functions for profiling the runtime. #[runtime_interface] @@ -1009,40 +1009,40 @@ pub trait WasmTracing { /// To create and enter a `tracing` span, using `sp_tracing::proxy` /// Returns 0 value to indicate that no further traces should be attempted fn enter_span(&mut self, target: &str, name: &str) -> u64 { - if sp_tracing::wasm_tracing_enabled() { - match self.extension::() { - Some(proxy) => return proxy.enter_span(target, name), - None => { - if self.register_extension(TracingProxyExt(sp_tracing::proxy::TracingProxy::new())).is_ok() { - if let Some(proxy) = self.extension::() { - return proxy.enter_span(target, name); - } - } else { - log::warn!( - target: "tracing", - "Unable to register extension: TracingProxyExt" - ); - } - } - } - } - log::debug!( - target: "tracing", - "Notify to runtime that tracing is disabled." - ); + // if sp_tracing::wasm_tracing_enabled() { + // match self.extension::() { + // Some(proxy) => return proxy.enter_span(target, name), + // None => { + // if self.register_extension(TracingProxyExt(sp_tracing::proxy::TracingProxy::new())).is_ok() { + // if let Some(proxy) = self.extension::() { + // return proxy.enter_span(target, name); + // } + // } else { + // log::warn!( + // target: "tracing", + // "Unable to register extension: TracingProxyExt" + // ); + // } + // } + // } + // } + // log::debug!( + // target: "tracing", + // "Notify to runtime that tracing is disabled." + // ); 0 } /// Exit a `tracing` span, using `sp_tracing::proxy` fn exit_span(&mut self, id: u64) { - if let Some(proxy) = self.extension::() { - proxy.exit_span(id) - } else { - log::warn!( - target: "tracing", - "Unable to load extension: TracingProxyExt" - ); - } + // if let Some(proxy) = self.extension::() { + // proxy.exit_span(id) + // } else { + // log::warn!( + // target: "tracing", + // "Unable to load extension: TracingProxyExt" + // ); + // } } } diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index fc3d311298dde..e1b2bbd271d44 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,10 +12,33 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -tracing = { version = "0.1.13", optional = true } -rental = { version = "0.5.5", optional = true } +sp-std = { version = "2.0.0-rc5", path = "../std", default-feature = false} +#sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} +codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} +sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } +tracing = { version = "0.1.13", optional = true, default-features = false } +tracing-core = { version = "0.1.11", optional = true, default-features = false } log = { version = "0.4.8", optional = true } +once_cell = { version = "1.4.0", optional = true } [features] default = [ "std" ] -std = [ "tracing", "rental", "log" ] +with-tracing = [ + "tracing", + "tracing-core", + "codec/derive", + "codec/full", + "sp-externalities", + "once_cell", +] +std = [ + "with-tracing", + "tracing/std", + "tracing-core/std", + "codec/std", + "codec/derive", + "sp-std/std", +# "sp-runtime-interface/std", + "sp-externalities", + "log", +] diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs new file mode 100644 index 0000000000000..737b4f4f0fe09 --- /dev/null +++ b/primitives/tracing/src/interface.rs @@ -0,0 +1,84 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +// #![cfg_attr(not(feature = "std"), no_std)] +// //! Proxy to allow entering tracing spans from wasm. +// use core::{ +// default::Default, +// fmt::Debug, +// }; + +// use codec::{Encode, Decode}; +use crate::{ + WasmMetadata, WasmAttributes, WasmRecord, WasmEvent +}; +// +// #[cfg(feature = "std")] +// use sp_externalities::{ExternalitiesExt, Externalities}; + +// use sp_runtime_interface::runtime_interface; + +pub trait TracingSubscriber: Send + Sync { + fn enabled(&self, metadata: WasmMetadata) -> bool; + fn new_span(&self, attrs: WasmAttributes) -> u64; + fn record(&self, span: u64, values: WasmRecord); + fn event(&self, event: WasmEvent); + fn enter(&self, span: u64); + fn exit(&self, span: u64); +} +// +// #[cfg(feature="std")] +// sp_externalities::decl_extension! { +// /// The keystore extension to register/retrieve from the externalities. +// pub struct WasmTracer(Box); +// } +// +// +// /// Interface that provides tracing functions +// // #[runtime_interface(wasm_only, no_tracing)] +// #[runtime_interface] +// pub trait WasmTracing { +// fn enabled(&mut self, metadata: WasmMetadata) -> bool { +// self.extension::().map(|t|{ +// t.0.enabled(metadata) +// }).unwrap_or(false) +// } +// fn new_span(&mut self, span: WasmAttributes) -> u64 { +// self.extension::().map(|t|{ +// t.0.new_span(span) +// }).unwrap_or(0) +// } +// fn record(&mut self, span: u64, values: WasmRecord) { +// self.extension::().map(|t|{ +// t.0.record(span, values) +// }); +// } +// fn event(&mut self, event: WasmEvent) { +// self.extension::().map(|t|{ +// t.0.event(event) +// }); +// } +// fn enter(&mut self, span: u64) { +// self.extension::().map(|t|{ +// t.0.enter(span) +// }); +// } +// fn exit(&mut self, span: u64) { +// self.extension::().map(|t|{ +// t.0.exit(span) +// }); +// } +// } \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index e82d8861cd3f5..c7f788aadc223 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,24 +30,35 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -#[macro_use] -extern crate rental; +pub mod interface; +pub mod types; +pub use types::*; + +#[macro_export] +#[cfg(not(feature = "std"))] +mod wasm_tracing; +#[macro_export] #[cfg(feature = "std")] -#[doc(hidden)] pub use tracing; -#[cfg(feature = "std")] -pub mod proxy; +#[cfg(not(feature = "std"))] +pub use types::WasmLevel as Level; + #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; +#[cfg(feature = "std")] +use once_cell::sync::OnceCell; /// Flag to signal whether to run wasm tracing #[cfg(feature = "std")] static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); +/// Instance of the native subscriber in use +#[cfg(feature = "std")] +static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); + /// Runs given code within a tracing span, measuring it's execution time. /// /// If tracing is not enabled, the code is still executed. @@ -114,4 +125,27 @@ pub fn wasm_tracing_enabled() -> bool { #[cfg(feature = "std")] pub fn set_wasm_tracing(b: bool) { WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) +} + +#[cfg(feature = "std")] +pub fn set_tracing_subscriber(subscriber: Box) { + let _ = SUBSCRIBER_INSTANCE.set(subscriber); +} + +#[cfg(feature = "std")] +pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { + SUBSCRIBER_INSTANCE.get() +} + +#[cfg(feature = "std")] +impl From for tracing::Level { + fn from(w: WasmLevel) -> Self { + match w { + WasmLevel::ERROR => tracing::Level::ERROR, + WasmLevel::WARN => tracing::Level::WARN, + WasmLevel::INFO => tracing::Level::INFO, + WasmLevel::DEBUG => tracing::Level::DEBUG, + WasmLevel::TRACE => tracing::Level::TRACE, + } + } } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs new file mode 100644 index 0000000000000..4d2a4fe4c6064 --- /dev/null +++ b/primitives/tracing/src/types.rs @@ -0,0 +1,76 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![cfg_attr(not(feature = "std"), no_std)] + +use sp_std::{ + vec::Vec +}; +// use sp_runtime_interface::pass_by::PassByCodec; +use codec::{Encode, Decode}; + + +#[derive(Encode, Decode)] +pub enum WasmLevel { + ERROR, + WARN, + INFO, + DEBUG, + TRACE +} + +#[derive(Encode, Decode)] +pub enum WasmFieldValue { + I64(i64), + U64(u64), + Bool(bool), + Str(Vec), + Debug(Vec), + Encoded(Vec), +} + +pub type WasmFields = Vec>; +pub type WasmValues = Vec<(Vec, WasmFieldValue)>; + +#[derive(Encode, Decode)] +pub struct WasmMetadata { + pub name: Vec, + pub target: Vec, + pub level: WasmLevel, + pub file: Vec, + pub line: u32, + pub module_path: Vec, + pub is_span: bool, + pub fields: WasmFields, +} + +#[derive(Encode, Decode)] +pub struct WasmAttributes { + pub parent_id: Option, + pub fields: WasmValues, + pub metadata: WasmMetadata, +} + +#[derive(Encode, Decode)] +pub struct WasmEvent { + pub parent: Option, + pub metadata: WasmMetadata, + pub fields: WasmValues, +} + +#[derive(Encode, Decode)] +pub struct WasmRecord; diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs new file mode 100644 index 0000000000000..4bd4e4b5a3749 --- /dev/null +++ b/primitives/tracing/src/wasm_tracing.rs @@ -0,0 +1,2139 @@ +// // Copyright 2020 Parity Technologies (UK) Ltd. +// // This file is part of Substrate. +// +// // Substrate is free software: you can redistribute it and/or modify +// // it under the terms of the GNU General Public License as published by +// // the Free Software Foundation, either version 3 of the License, or +// // (at your option) any later version. +// +// // Substrate is distributed in the hope that it will be useful, +// // but WITHOUT ANY WARRANTY; without even the implied warranty of +// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// // GNU General Public License for more details. +// +// // You should have received a copy of the GNU General Public License +// // along with Substrate. If not, see . +// +// #![cfg_attr(not(feature = "std"), no_std)] +// +// use sp_std::{ +// vec +// }; +// +// #[cfg(not(feature = "with-tracing"))] +// mod inner { +// #[doc(hidden)] +// #[macro_export] +// macro_rules! __tracing_mk_span { +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; +// (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; +// } +// +// +// /// Constructs a new `Event` – noop +// #[macro_export] +// macro_rules! event { +// (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> { {} }; +// +// (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => { {} }; +// (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> {{}}; +// (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; +// (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; +// (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; +// (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; +// ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; +// ($lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; +// ($lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; +// ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; +// ($lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; +// ($lvl:expr, ?$($k:ident).+) => { {} }; +// ($lvl:expr, %$($k:ident).+) => { {} }; +// ($lvl:expr, $($k:ident).+) => { {} }; +// ( $lvl:expr, $($arg:tt)+ ) => { {} }; +// } +// } +// +// #[cfg(feature = "with-tracing")] +// mod inner { +// use core::{ +// module_path, concat, format_args, file, line, +// }; +// use crate::{WasmMetadata}; +// use crate::interface::wasm_tracing; +// +// // just a simplistic holder for span and entered spans +// // that exits on drop +// pub struct Span(u64); // 0 means no item +// pub struct Entered(u64); // 0 means no item +// +// impl Span { +// pub fn enter(self) -> Entered { +// if self.0 != 0 { +// wasm_tracing::enter(self.0); +// } +// Entered(self.0) +// } +// } +// +// impl Entered { +// pub fn exit(&mut self) { +// if self.0 != 0 { +// wasm_tracing::exit(self.0); +// } +// } +// } +// +// impl Drop for Entered { +// fn drop(&mut self) { +// self.exit(); +// } +// } +// +// /// Constructs a new `Event`. +// /// +// /// The event macro is invoked with a `Level` and up to 32 key-value fields. +// /// Optionally, a format string and arguments may follow the fields; this will +// /// be used to construct an implicit field named "message". +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::{event, Level}; +// /// +// /// # fn main() { +// /// let data = (42, "forty-two"); +// /// let private_data = "private"; +// /// let error = "a bad error"; +// /// +// /// event!(Level::ERROR, %error, "Received error"); +// /// event!( +// /// target: "app_events", +// /// Level::WARN, +// /// private_data, +// /// ?data, +// /// "App warning: {}", +// /// error +// /// ); +// /// event!(Level::INFO, the_answer = data.0); +// /// # } +// /// ``` +// /// +// // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As +// // /// events are recorded immediately when the macro is invoked, there is no +// // /// opportunity for fields to be recorded later. A trailing comma on the final +// // /// field is valid. +// // /// +// // /// For example, the following does not compile: +// // /// ```rust,compile_fail +// // /// # #[macro_use] +// // /// # extern crate tracing; +// // /// # use tracing::Level; +// // /// # fn main() { +// // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") +// // /// #} +// // /// ``` +// #[macro_export] +// macro_rules! event { +// (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ +// { +// if $crate::level_enabled!($lvl) { +// #[allow(unused_imports)] +// use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; +// let metadata = WasmMetadata { +// name: concat!( +// "event ", +// file!(), +// ":", +// line!() +// ).as_bytes().to_vec(), +// file: file!().as_bytes().to_vec(), +// line: line!(), +// is_span: false, +// target: $target, +// level: $lvl, +// module_path: module_path().as_bytes().to_vec(), +// fields: $($fields)* +// }; +// if $crate::is_enabled!(&metdata) { +// wasm_tracing::event(WasmEvent { +// parent: $parent, +// metadata, +// &$crate::valueset!(meta.fields(), $($fields)*) +// }) +// } +// } +// } +// }); +// +// (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ +// $crate::event!( +// target: $target, +// parent: $parent, +// $lvl, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// }); +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) +// ); +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( +// $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) +// ); +// (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ +// { +// if $crate::level_enabled!($lvl) { +// #[allow(unused_imports)] +// use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; +// let metadata = WasmMetadata { +// name: concat!( +// "event ", +// file!(), +// ":", +// line!() +// ).as_bytes().to_vec(), +// file: file!().as_bytes().to_vec(), +// line: line!(), +// is_span: false, +// target: $target, +// level: $lvl, +// module_path: module_path().as_bytes().to_vec(), +// fields: $($fields)* +// }; +// if $crate::is_enabled!(&metdata) { +// wasm_tracing::event(WasmEvent { +// parent: None, +// metadata, +// &$crate::valueset!(meta.fields(), $($fields)*) +// }); +// } +// } +// } +// }); +// (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ +// $crate::event!( +// target: $target, +// $lvl, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// }); +// (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( +// $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) +// ); +// (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $lvl, { $($arg)+ }) +// ); +// (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// ); +// (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// parent: $parent, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// ); +// (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) +// ); +// ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// ); +// ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { message = format_args!($($arg)+), $($fields)* } +// ) +// ); +// ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { $($k).+ = $($field)*} +// ) +// ); +// ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { $($k).+, $($field)*} +// ) +// ); +// ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { ?$($k).+, $($field)*} +// ) +// ); +// ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $lvl, +// { %$($k).+, $($field)*} +// ) +// ); +// ($lvl:expr, ?$($k:ident).+) => ( +// $crate::event!($lvl, ?$($k).+,) +// ); +// ($lvl:expr, %$($k:ident).+) => ( +// $crate::event!($lvl, %$($k).+,) +// ); +// ($lvl:expr, $($k:ident).+) => ( +// $crate::event!($lvl, $($k).+,) +// ); +// ( $lvl:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) +// ); +// } +// +// #[doc(hidden)] +// #[macro_export] +// macro_rules! __tracing_mk_span { +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// { +// if $crate::level_enabled!($lvl) { +// #[allow(unused_imports)] +// use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; +// let metadata = WasmMetadata { +// name: $name.as_bytes().to_vec(), +// file: file!().as_bytes().to_vec(), +// line: line!(), +// is_span: true, +// target: $target, +// level: $lvl, +// module_path: module_path().as_bytes().to_vec(), +// fields: $($fields)* +// }; +// if $crate::is_enabled!(metadata) { +// let span_id = wasm_tracing::new_span(WasmAttributes{ +// parent: Some($parent), +// metadata, +// &$crate::valueset!(meta.fields(), $($fields)*) +// }) +// $crate::wasm_tracing::Span(span_id) +// } else { +// $crate::wasm_tracing::Span(0) +// } +// } else { +// $crate::wasm_tracing::Span(0) +// } +// } +// }; +// (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// { +// if $crate::level_enabled!($lvl) { +// #[allow(unused_imports)] +// use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; +// let metadata = WasmMetadata { +// name: $name.as_bytes().to_vec(), +// file: file!().as_bytes().to_vec(), +// line: line!(), +// is_span: true, +// target: $target, +// level: $lvl, +// module_path: module_path().as_bytes().to_vec(), +// fields: $($fields)* +// }; +// if $crate::is_enabled!(metadata) { +// let span_id = wasm_tracing::new_span(WasmAttributes{ +// parent: None, +// metadata, +// &$crate::valueset!(meta.fields(), $($fields)*) +// }) +// $crate::wasm_tracing::Span(span_id) +// } else { +// $crate::wasm_tracing::Span(0) +// } +// } else { +// $crate::wasm_tracing::Span(0) +// } +// } +// }; +// } +// } +// +// pub use inner::*; +// +// /// Constructs a new span. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// Creating a new span: +// /// ``` +// /// # use tracing::{span, Level}; +// /// # fn main() { +// /// let span = span!(Level::TRACE, "my span"); +// /// let _enter = span.enter(); +// /// // do work inside the span... +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! span { +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { +// $crate::span!(target: $target, parent: $parent, $lvl, $name,) +// }; +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// $crate::__tracing_mk_span!(target: $target, parent: $parent, $lvl, $name, $($fields)*) +// }; +// (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// $crate::__tracing_mk_span!(target: $target, $lvl, $name, $($fields)*) +// }; +// (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { +// $crate::span!(target: $target, parent: $parent, $lvl, $name,) +// }; +// (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// $name, +// $($fields)* +// ) +// }; +// (parent: $parent:expr, $lvl:expr, $name:expr) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $lvl, +// $name, +// ) +// }; +// (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { +// $crate::span!( +// target: $target, +// $lvl, +// $name, +// $($fields)* +// ) +// }; +// (target: $target:expr, $lvl:expr, $name:expr) => { +// $crate::span!(target: $target, $lvl, $name,) +// }; +// ($lvl:expr, $name:expr, $($fields:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $lvl, +// $name, +// $($fields)* +// ) +// }; +// ($lvl:expr, $name:expr) => { +// $crate::span!( +// target: module_path!(), +// $lvl, +// $name, +// ) +// }; +// } +// +// /// Constructs a span at the trace level. +// /// +// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] +// /// macro. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// [attributes]: index.html#configuring-attributes +// /// [Fields]: index.html#recording-fields +// /// [`span!`]: macro.span.html +// /// +// /// # Examples +// /// +// /// ```rust +// /// # use tracing::{trace_span, span, Level}; +// /// # fn main() { +// /// trace_span!("my_span"); +// /// // is equivalent to: +// /// span!(Level::TRACE, "my_span"); +// /// # } +// /// ``` +// /// +// /// ```rust +// /// # use tracing::{trace_span, span, Level}; +// /// # fn main() { +// /// let span = trace_span!("my span"); +// /// span.in_scope(|| { +// /// // do work inside the span... +// /// }); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! trace_span { +// (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// parent: $parent, +// $crate::Level::TRACE, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, parent: $parent:expr, $name:expr) => { +// $crate::trace_span!(target: $target, parent: $parent, $name,) +// }; +// (parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// $name, +// $($field)* +// ) +// }; +// (parent: $parent:expr, $name:expr) => { +// $crate::trace_span!(parent: $parent, $name,) +// }; +// (target: $target:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// $crate::Level::TRACE, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, $name:expr) => { +// $crate::trace_span!(target: $target, $name,) +// }; +// ($name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $crate::Level::TRACE, +// $name, +// $($field)* +// ) +// }; +// ($name:expr) => { $crate::trace_span!($name,) }; +// } +// +// /// Constructs a span at the debug level. +// /// +// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] +// /// macro. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// [attributes]: index.html#configuring-attributes +// /// [Fields]: index.html#recording-fields +// /// [`span!`]: macro.span.html +// /// +// /// # Examples +// /// +// /// ```rust +// /// # use tracing::{debug_span, span, Level}; +// /// # fn main() { +// /// debug_span!("my_span"); +// /// // is equivalent to: +// /// span!(Level::DEBUG, "my_span"); +// /// # } +// /// ``` +// /// +// /// ```rust +// /// # use tracing::debug_span; +// /// # fn main() { +// /// let span = debug_span!("my span"); +// /// span.in_scope(|| { +// /// // do work inside the span... +// /// }); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! debug_span { +// (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// parent: $parent, +// $crate::Level::DEBUG, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, parent: $parent:expr, $name:expr) => { +// $crate::debug_span!(target: $target, parent: $parent, $name,) +// }; +// (parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// $name, +// $($field)* +// ) +// }; +// (parent: $parent:expr, $name:expr) => { +// $crate::debug_span!(parent: $parent, $name,) +// }; +// (target: $target:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// $crate::Level::DEBUG, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, $name:expr) => { +// $crate::debug_span!(target: $target, $name,) +// }; +// ($name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $crate::Level::DEBUG, +// $name, +// $($field)* +// ) +// }; +// ($name:expr) => {$crate::debug_span!($name,)}; +// } +// +// /// Constructs a span at the info level. +// /// +// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] +// /// macro. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// [attributes]: index.html#configuring-attributes +// /// [Fields]: index.html#recording-fields +// /// [`span!`]: macro.span.html +// /// +// /// # Examples +// /// +// /// ```rust +// /// # use tracing::{span, info_span, Level}; +// /// # fn main() { +// /// info_span!("my_span"); +// /// // is equivalent to: +// /// span!(Level::INFO, "my_span"); +// /// # } +// /// ``` +// /// +// /// ```rust +// /// # use tracing::info_span; +// /// # fn main() { +// /// let span = info_span!("my span"); +// /// span.in_scope(|| { +// /// // do work inside the span... +// /// }); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! info_span { +// (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// parent: $parent, +// $crate::Level::INFO, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, parent: $parent:expr, $name:expr) => { +// $crate::info_span!(target: $target, parent: $parent, $name,) +// }; +// (parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// $name, +// $($field)* +// ) +// }; +// (parent: $parent:expr, $name:expr) => { +// $crate::info_span!(parent: $parent, $name,) +// }; +// (target: $target:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// $crate::Level::INFO, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, $name:expr) => { +// $crate::info_span!(target: $target, $name,) +// }; +// ($name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $crate::Level::INFO, +// $name, +// $($field)* +// ) +// }; +// ($name:expr) => {$crate::info_span!($name,)}; +// } +// +// /// Constructs a span at the warn level. +// /// +// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] +// /// macro. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// [attributes]: index.html#configuring-attributes +// /// [Fields]: index.html#recording-fields +// /// [`span!`]: macro.span.html +// /// +// /// # Examples +// /// +// /// ```rust +// /// # use tracing::{warn_span, span, Level}; +// /// # fn main() { +// /// warn_span!("my_span"); +// /// // is equivalent to: +// /// span!(Level::WARN, "my_span"); +// /// # } +// /// ``` +// /// +// /// ```rust +// /// use tracing::warn_span; +// /// # fn main() { +// /// let span = warn_span!("my span"); +// /// span.in_scope(|| { +// /// // do work inside the span... +// /// }); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! warn_span { +// (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// parent: $parent, +// $crate::Level::WARN, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, parent: $parent:expr, $name:expr) => { +// $crate::warn_span!(target: $target, parent: $parent, $name,) +// }; +// (parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// $name, +// $($field)* +// ) +// }; +// (parent: $parent:expr, $name:expr) => { +// $crate::warn_span!(parent: $parent, $name,) +// }; +// (target: $target:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// $crate::Level::WARN, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, $name:expr) => { +// $crate::warn_span!(target: $target, $name,) +// }; +// ($name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $crate::Level::WARN, +// $name, +// $($field)* +// ) +// }; +// ($name:expr) => {$crate::warn_span!($name,)}; +// } +// /// Constructs a span at the error level. +// /// +// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] +// /// macro. +// /// +// /// See [the top-level documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [lib]: index.html#using-the-macros +// /// [attributes]: index.html#configuring-attributes +// /// [Fields]: index.html#recording-fields +// /// [`span!`]: macro.span.html +// /// +// /// # Examples +// /// +// /// ```rust +// /// # use tracing::{span, error_span, Level}; +// /// # fn main() { +// /// error_span!("my_span"); +// /// // is equivalent to: +// /// span!(Level::ERROR, "my_span"); +// /// # } +// /// ``` +// /// +// /// ```rust +// /// # use tracing::error_span; +// /// # fn main() { +// /// let span = error_span!("my span"); +// /// span.in_scope(|| { +// /// // do work inside the span... +// /// }); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! error_span { +// (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// parent: $parent, +// $crate::Level::ERROR, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, parent: $parent:expr, $name:expr) => { +// $crate::error_span!(target: $target, parent: $parent, $name,) +// }; +// (parent: $parent:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// $name, +// $($field)* +// ) +// }; +// (parent: $parent:expr, $name:expr) => { +// $crate::error_span!(parent: $parent, $name,) +// }; +// (target: $target:expr, $name:expr, $($field:tt)*) => { +// $crate::span!( +// target: $target, +// $crate::Level::ERROR, +// $name, +// $($field)* +// ) +// }; +// (target: $target:expr, $name:expr) => { +// $crate::error_span!(target: $target, $name,) +// }; +// ($name:expr, $($field:tt)*) => { +// $crate::span!( +// target: module_path!(), +// $crate::Level::ERROR, +// $name, +// $($field)* +// ) +// }; +// ($name:expr) => {$crate::error_span!($name,)}; +// } +// +// /// Constructs an event at the trace level. +// /// +// /// This functions similarly to the [`event!`] macro. See [the top-level +// /// documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [`event!`]: macro.event.html +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::trace; +// /// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } +// /// # impl Position { +// /// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; +// /// # fn dist(&self, other: Position) -> f32 { +// /// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2(); +// /// # (x + y).sqrt() +// /// # } +// /// # } +// /// # fn main() { +// /// let pos = Position { x: 3.234, y: -1.223 }; +// /// let origin_dist = pos.dist(Position::ORIGIN); +// /// +// /// trace!(position = ?pos, ?origin_dist); +// /// trace!( +// /// target: "app_events", +// /// position = ?pos, +// /// "x is {} and y is {}", +// /// if pos.x >= 0.0 { "positive" } else { "negative" }, +// /// if pos.y >= 0.0 { "positive" } else { "negative" } +// /// ); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! trace { +// (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) +// ); +// (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::TRACE, +// {}, +// $($arg)+ +// ) +// ); +// (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) +// ); +// ({ $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// ($($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { $($k).+ = $($field)*} +// ) +// ); +// ($($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { $($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { ?$($k).+, $($field)*} +// ) +// ); +// (%$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { %$($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { ?$($k).+ } +// ) +// ); +// (%$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { %$($k).+ } +// ) +// ); +// ($($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { $($k).+ } +// ) +// ); +// ($($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// {}, +// $($arg)+ +// ) +// ); +// } +// +// /// Constructs an event at the debug level. +// /// +// /// This functions similarly to the [`event!`] macro. See [the top-level +// /// documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [`event!`]: macro.event.html +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::debug; +// /// # fn main() { +// /// # #[derive(Debug)] struct Position { x: f32, y: f32 } +// /// +// /// let pos = Position { x: 3.234, y: -1.223 }; +// /// +// /// debug!(?pos.x, ?pos.y); +// /// debug!(target: "app_events", position = ?pos, "New position"); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! debug { +// (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) +// ); +// (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::DEBUG, +// {}, +// $($arg)+ +// ) +// ); +// (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) +// ); +// ({ $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// ($($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { $($k).+ = $($field)*} +// ) +// ); +// (?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (%$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { %$($k).+ = $($field)*} +// ) +// ); +// ($($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { $($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { ?$($k).+, $($field)*} +// ) +// ); +// (%$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { %$($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { ?$($k).+ } +// ) +// ); +// (%$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { %$($k).+ } +// ) +// ); +// ($($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// { $($k).+ } +// ) +// ); +// ($($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::DEBUG, +// {}, +// $($arg)+ +// ) +// ); +// } +// +// /// Constructs an event at the info level. +// /// +// /// This functions similarly to the [`event!`] macro. See [the top-level +// /// documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [`event!`]: macro.event.html +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::info; +// /// # // this is so the test will still work in no-std mode +// /// # #[derive(Debug)] +// /// # pub struct Ipv4Addr; +// /// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } +// /// # fn main() { +// /// # struct Connection { port: u32, speed: f32 } +// /// use tracing::field; +// /// +// /// let addr = Ipv4Addr::new(127, 0, 0, 1); +// /// let conn = Connection { port: 40, speed: 3.20 }; +// /// +// /// info!(conn.port, "connected to {:?}", addr); +// /// info!( +// /// target: "connection_events", +// /// ip = ?addr, +// /// conn.port, +// /// ?conn.speed, +// /// ); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! info { +// (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) +// ); +// (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::INFO, +// {}, +// $($arg)+ +// ) +// ); +// (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) +// ); +// ({ $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// ($($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { $($k).+ = $($field)*} +// ) +// ); +// (?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (%$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { %$($k).+ = $($field)*} +// ) +// ); +// ($($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { $($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { ?$($k).+, $($field)*} +// ) +// ); +// (%$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { %$($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { ?$($k).+ } +// ) +// ); +// (%$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { %$($k).+ } +// ) +// ); +// ($($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// { $($k).+ } +// ) +// ); +// ($($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::INFO, +// {}, +// $($arg)+ +// ) +// ); +// } +// +// /// Constructs an event at the warn level. +// /// +// /// This functions similarly to the [`event!`] macro. See [the top-level +// /// documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [`event!`]: macro.event.html +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::warn; +// /// # fn main() { +// /// +// /// let warn_description = "Invalid Input"; +// /// let input = &[0x27, 0x45]; +// /// +// /// warn!(?input, warning = warn_description); +// /// warn!( +// /// target: "input_events", +// /// warning = warn_description, +// /// "Received warning for input: {:?}", input, +// /// ); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! warn { +// (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) +// ); +// (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::WARN, +// {}, +// $($arg)+ +// ) +// ); +// (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) +// ); +// ({ $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// ($($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { $($k).+ = $($field)*} +// ) +// ); +// (?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (%$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { %$($k).+ = $($field)*} +// ) +// ); +// ($($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { $($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { ?$($k).+, $($field)*} +// ) +// ); +// (%$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { %$($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { ?$($k).+ } +// ) +// ); +// (%$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { %$($k).+ } +// ) +// ); +// ($($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// { $($k).+ } +// ) +// ); +// ($($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::WARN, +// {}, +// $($arg)+ +// ) +// ); +// } +// +// /// Constructs an event at the error level. +// /// +// /// This functions similarly to the [`event!`] macro. See [the top-level +// /// documentation][lib] for details on the syntax accepted by +// /// this macro. +// /// +// /// [`event!`]: macro.event.html +// /// [lib]: index.html#using-the-macros +// /// +// /// # Examples +// /// +// /// ```rust +// /// use tracing::error; +// /// # fn main() { +// /// +// /// let (err_info, port) = ("No connection", 22); +// /// +// /// error!(port, error = %err_info); +// /// error!(target: "app_events", "App Error: {}", err_info); +// /// error!({ info = err_info }, "error on port: {}", port); +// /// # } +// /// ``` +// #[macro_export] +// macro_rules! error { +// (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) +// ); +// (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { $($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { %$($k).+ = $($field)*} +// ) +// ); +// (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { $($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { ?$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// { %$($k).+, $($field)*} +// ) +// ); +// (parent: $parent:expr, $($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// parent: $parent, +// $crate::Level::ERROR, +// {}, +// $($arg)+ +// ) +// ); +// (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( +// $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) +// ); +// (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) +// ); +// (target: $target:expr, $($arg:tt)+ ) => ( +// $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) +// ); +// ({ $($field:tt)+ }, $($arg:tt)+ ) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { $($field)+ }, +// $($arg)+ +// ) +// ); +// ($($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { $($k).+ = $($field)*} +// ) +// ); +// (?$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { ?$($k).+ = $($field)*} +// ) +// ); +// (%$($k:ident).+ = $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::TRACE, +// { %$($k).+ = $($field)*} +// ) +// ); +// ($($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { $($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { ?$($k).+, $($field)*} +// ) +// ); +// (%$($k:ident).+, $($field:tt)*) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { %$($k).+, $($field)*} +// ) +// ); +// (?$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { ?$($k).+ } +// ) +// ); +// (%$($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { %$($k).+ } +// ) +// ); +// ($($k:ident).+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// { $($k).+ } +// ) +// ); +// ($($arg:tt)+) => ( +// $crate::event!( +// target: module_path!(), +// $crate::Level::ERROR, +// {}, +// $($arg)+ +// ) +// ); +// } +// +// +// #[macro_export] +// // TODO: determine if this ought to be public API? +// #[doc(hidden)] +// macro_rules! level_enabled { +// ($lvl:expr) => { +// // FIXME: use the runtime interface to figure this out +// true +// // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL +// +// }; +// } +// +// #[macro_export] +// // TODO: determine if this ought to be public API? +// #[doc(hidden)] +// macro_rules! is_enabled { +// ($metadata:expr) => {{ +// // FIXME: use the runtime interface to figure this out +// true +// }}; +// } +// +// #[doc(hidden)] +// #[macro_export] +// macro_rules! valueset { +// +// // === base case === +// (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { +// vec![ $($val),* ] +// }; +// +// // === recursive case (more tts) === +// +// // TODO(#1138): determine a new syntax for uninitialized span fields, and +// // re-enable this. +// // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { +// // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) +// // }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&$val as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, +// $next, +// $($rest)* +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, +// $next, +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, +// $next, +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&$val as &Value)) }, +// $next, +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, +// $next, +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, +// $next, +// ) +// }; +// (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { +// $crate::valueset!( +// @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, +// $next, +// ) +// }; +// // Remainder is unparseable, but exists --- must be format args! +// (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { +// $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, ) +// }; +// +// // === entry === +// ($fields:expr, $($kvs:tt)+) => { +// { +// #[allow(unused_imports)] +// use $crate::field::{debug, display, Value}; +// let mut iter = $fields.iter(); +// $fields.value_set($crate::valueset!( +// @ { }, +// iter.next().expect("FieldSet corrupted (this is a bug)"), +// $($kvs)+ +// )) +// } +// }; +// ($fields:expr,) => { +// { +// $fields.value_set(&[]) +// } +// }; +// } +// +// #[doc(hidden)] +// #[macro_export] +// macro_rules! fieldset { +// // == base case == +// (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { +// vec![ $($out),* ] +// }; +// +// // == recursive cases (more tts) == +// (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// // TODO(#1138): determine a new syntax for uninitialized span fields, and +// // re-enable this. +// // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { +// // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// // }; +// (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { +// $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) +// }; +// +// // Remainder is unparseable, but exists --- must be format args! +// (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { +// $crate::fieldset!(@ { "message", $($out),*, }) +// }; +// +// // == entry == +// ($($args:tt)*) => { +// $crate::fieldset!(@ { } $($args)*,) +// }; +// +// } +// +// #[doc(hidden)] +// #[macro_export] +// macro_rules! __tracing_stringify { +// ($s:expr) => { +// stringify!($s) +// }; +// } +// +// #[doc(hidden)] +// #[macro_export] +// macro_rules! if_log_enabled { +// ($e:expr;) => { +// $crate::if_log_enabled! { $e } +// }; +// ($if_log:block) => { +// $crate::if_log_enabled! { $if_log else {} } +// }; +// ($if_log:block else $else_block:block) => { +// $else_block +// }; +// } \ No newline at end of file From 6a8e6b5a4a0695a855adff52d0027ecd3af667a4 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 29 Jul 2020 10:32:06 +0100 Subject: [PATCH 023/113] increment, remove sp-tracing from runtime-interface --- Cargo.lock | 4 +- client/service/Cargo.toml | 1 + client/tracing/Cargo.toml | 1 - primitives/runtime-interface/Cargo.toml | 2 - .../bare_function_interface.rs | 1 - .../host_function_interface.rs | 1 - primitives/runtime-interface/src/lib.rs | 3 - primitives/runtime-interface/test/Cargo.toml | 1 - primitives/runtime-interface/test/src/lib.rs | 43 ----- primitives/tracing/Cargo.toml | 4 +- primitives/tracing/src/lib.rs | 17 +- primitives/tracing/src/proxy.rs | 165 ------------------ primitives/tracing/src/types.rs | 51 ++++-- 13 files changed, 39 insertions(+), 255 deletions(-) delete mode 100644 primitives/tracing/src/proxy.rs diff --git a/Cargo.lock b/Cargo.lock index 2a81bc8c791db..81b5debdcb8e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7038,6 +7038,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-state-machine", + "sp-tracing", "sp-transaction-pool", "sp-trie", "sp-utils", @@ -8071,7 +8072,6 @@ dependencies = [ "sp-runtime-interface-test-wasm", "sp-state-machine", "sp-std", - "sp-tracing", "sp-wasm-interface", "static_assertions", "trybuild", @@ -8100,7 +8100,6 @@ dependencies = [ "sp-runtime-interface-test-wasm", "sp-runtime-interface-test-wasm-deprecated", "sp-state-machine", - "tracing", ] [[package]] @@ -8239,6 +8238,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "sp-externalities", + "sp-runtime-interface", "sp-std", "tracing", "tracing-core", diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 3511c29038299..f90a111256b48 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -72,6 +72,7 @@ sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } sc-offchain = { version = "2.0.0-rc5", path = "../offchain" } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc5"} sc-tracing = { version = "2.0.0-rc5", path = "../tracing" } +sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } tracing = "0.1.10" parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index ee406e025b7f5..27bb4d098eed4 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -22,7 +22,6 @@ slog = { version = "2.5.2", features = ["nested-values"] } tracing-core = "0.1.11" tracing-subscriber = "0.2.7" sp-tracing = { version = "2.0.0-rc5", path = "../../primitives/tracing" } - sc-telemetry = { version = "2.0.0-rc5", path = "../telemetry" } [dev-dependencies] diff --git a/primitives/runtime-interface/Cargo.toml b/primitives/runtime-interface/Cargo.toml index 16d5a14e889b1..70b892495ea5f 100644 --- a/primitives/runtime-interface/Cargo.toml +++ b/primitives/runtime-interface/Cargo.toml @@ -15,7 +15,6 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-wasm-interface = { version = "2.0.0-rc5", path = "../wasm-interface", default-features = false } sp-std = { version = "2.0.0-rc5", default-features = false, path = "../std" } -sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../tracing" } sp-runtime-interface-proc-macro = { version = "2.0.0-rc5", path = "proc-macro" } sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false } @@ -35,7 +34,6 @@ default = [ "std" ] std = [ "sp-wasm-interface/std", "sp-std/std", - "sp-tracing/std", "codec/std", "sp-externalities", "primitive-types/std", diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index 6760e9656113a..701d9c0ea57e2 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -174,7 +174,6 @@ fn function_std_impl( #[cfg(feature = "std")] #( #attrs )* fn #function_name( #( #args, )* ) #return_value { - #crate_::sp_tracing::enter_span!(#function_name_str); #call_to_trait } } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 721eed649c25d..7a4dbc5773a28 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -227,7 +227,6 @@ fn generate_host_function_implementation( __function_context__: &mut dyn #crate_::sp_wasm_interface::FunctionContext, args: &mut dyn Iterator, ) -> std::result::Result, String> { - #crate_::sp_tracing::enter_span!(#name); #( #wasm_to_ffi_values )* #( #ffi_to_host_values )* #host_function_call diff --git a/primitives/runtime-interface/src/lib.rs b/primitives/runtime-interface/src/lib.rs index 562f94b278efc..423a4b1ae9a64 100644 --- a/primitives/runtime-interface/src/lib.rs +++ b/primitives/runtime-interface/src/lib.rs @@ -110,9 +110,6 @@ extern crate self as sp_runtime_interface; #[cfg(feature = "std")] pub use sp_wasm_interface; -#[doc(hidden)] -pub use sp_tracing; - #[doc(hidden)] pub use sp_std; diff --git a/primitives/runtime-interface/test/Cargo.toml b/primitives/runtime-interface/test/Cargo.toml index 5e2ea5a62349b..af4490a0d7c32 100644 --- a/primitives/runtime-interface/test/Cargo.toml +++ b/primitives/runtime-interface/test/Cargo.toml @@ -20,4 +20,3 @@ sp-state-machine = { version = "0.8.0-rc5", path = "../../../primitives/state-ma sp-runtime = { version = "2.0.0-rc5", path = "../../runtime" } sp-core = { version = "2.0.0-rc5", path = "../../core" } sp-io = { version = "2.0.0-rc5", path = "../../io" } -tracing = "0.1.13" diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index c213c977829e6..619ffd17a171c 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -155,46 +155,3 @@ fn test_versionining_with_new_host_works() { ); } -#[test] -fn test_tracing() { - use tracing::span::Id as SpanId; - - #[derive(Clone)] - struct TracingSubscriber(Arc>); - - #[derive(Default)] - struct Inner { - spans: HashSet<&'static str>, - } - - impl tracing::subscriber::Subscriber for TracingSubscriber { - fn enabled(&self, _: &tracing::Metadata) -> bool { true } - - fn new_span(&self, span: &tracing::span::Attributes) -> tracing::Id { - let mut inner = self.0.lock().unwrap(); - let id = SpanId::from_u64((inner.spans.len() + 1) as _); - inner.spans.insert(span.metadata().name()); - id - } - - fn record(&self, _: &SpanId, _: &tracing::span::Record) {} - - fn record_follows_from(&self, _: &SpanId, _: &SpanId) {} - - fn event(&self, _: &tracing::Event) {} - - fn enter(&self, _: &SpanId) {} - - fn exit(&self, _: &SpanId) {} - } - - let subscriber = TracingSubscriber(Default::default()); - let _guard = tracing::subscriber::set_default(subscriber.clone()); - - // Call some method to generate a trace - call_wasm_method::(&wasm_binary_unwrap()[..], "test_return_data"); - - let inner = subscriber.0.lock().unwrap(); - assert!(inner.spans.contains("return_input_version_1")); - assert!(inner.spans.contains("ext_test_api_return_input_version_1")); -} diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index e1b2bbd271d44..fc4cf926f01da 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-std = { version = "2.0.0-rc5", path = "../std", default-feature = false} -#sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} +sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } tracing = { version = "0.1.13", optional = true, default-features = false } @@ -38,7 +38,7 @@ std = [ "codec/std", "codec/derive", "sp-std/std", -# "sp-runtime-interface/std", + "sp-runtime-interface/std", "sp-externalities", "log", ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index c7f788aadc223..2dac5a557d153 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,10 +30,11 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -pub mod interface; pub mod types; pub use types::*; +pub mod interface; + #[macro_export] #[cfg(not(feature = "std"))] mod wasm_tracing; @@ -45,7 +46,6 @@ pub use tracing; #[cfg(not(feature = "std"))] pub use types::WasmLevel as Level; - #[cfg(feature = "std")] use std::sync::atomic::{AtomicBool, Ordering}; #[cfg(feature = "std")] @@ -135,17 +135,4 @@ pub fn set_tracing_subscriber(subscriber: Box) #[cfg(feature = "std")] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { SUBSCRIBER_INSTANCE.get() -} - -#[cfg(feature = "std")] -impl From for tracing::Level { - fn from(w: WasmLevel) -> Self { - match w { - WasmLevel::ERROR => tracing::Level::ERROR, - WasmLevel::WARN => tracing::Level::WARN, - WasmLevel::INFO => tracing::Level::INFO, - WasmLevel::DEBUG => tracing::Level::DEBUG, - WasmLevel::TRACE => tracing::Level::TRACE, - } - } } \ No newline at end of file diff --git a/primitives/tracing/src/proxy.rs b/primitives/tracing/src/proxy.rs deleted file mode 100644 index 270f57aaa69f0..0000000000000 --- a/primitives/tracing/src/proxy.rs +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! Proxy to allow entering tracing spans from wasm. -//! -//! Use `enter_span` and `exit_span` to surround the code that you wish to trace -use rental; -use tracing::info_span; - -/// Used to identify a proxied WASM trace -pub const WASM_TRACE_IDENTIFIER: &'static str = "WASM_TRACE"; -/// Used to extract the real `target` from the associated values of the span -pub const WASM_TARGET_KEY: &'static str = "proxied_wasm_target"; -/// Used to extract the real `name` from the associated values of the span -pub const WASM_NAME_KEY: &'static str = "proxied_wasm_name"; - -const MAX_SPANS_LEN: usize = 1000; - -rental! { - pub mod rent_span { - #[rental] - pub struct SpanAndGuard { - span: Box, - guard: tracing::span::Entered<'span>, - } - } -} - -/// Requires a tracing::Subscriber to process span traces, -/// this is available when running with client (and relevant cli params). -pub struct TracingProxy { - next_id: u64, - spans: Vec<(u64, rent_span::SpanAndGuard)>, -} - -impl Drop for TracingProxy { - fn drop(&mut self) { - if !self.spans.is_empty() { - log::debug!( - target: "tracing", - "Dropping TracingProxy with {} un-exited spans, marking as not valid", self.spans.len() - ); - while let Some((_, mut sg)) = self.spans.pop() { - sg.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); - } - } - } -} - -impl TracingProxy { - pub fn new() -> TracingProxy { - TracingProxy { - next_id: 0, - spans: Vec::new(), - } - } -} - -impl TracingProxy { - /// Create and enter a `tracing` Span, returning the span id, - /// which should be passed to `exit_span(id)` to signal that the span should exit. - pub fn enter_span(&mut self, proxied_wasm_target: &str, proxied_wasm_name: &str) -> u64 { - // The identifiers `proxied_wasm_target` and `proxied_wasm_name` must match their associated const, - // WASM_TARGET_KEY and WASM_NAME_KEY. - let span = info_span!(WASM_TRACE_IDENTIFIER, is_valid_trace = true, proxied_wasm_target, proxied_wasm_name); - self.next_id += 1; - let sg = rent_span::SpanAndGuard::new( - Box::new(span), - |span| span.enter(), - ); - self.spans.push((self.next_id, sg)); - if self.spans.len() > MAX_SPANS_LEN { - // This is to prevent unbounded growth of Vec and could mean one of the following: - // 1. Too many nested spans, or MAX_SPANS_LEN is too low. - // 2. Not correctly exiting spans due to misconfiguration / misuse - log::warn!( - target: "tracing", - "TracingProxy MAX_SPANS_LEN exceeded, removing oldest span." - ); - let mut sg = self.spans.remove(0).1; - sg.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); - } - self.next_id - } - - /// Exit a span by dropping it along with it's associated guard. - pub fn exit_span(&mut self, id: u64) { - if self.spans.last().map(|l| id > l.0).unwrap_or(true) { - log::warn!(target: "tracing", "Span id not found in TracingProxy: {}", id); - return; - } - let mut last_span = self.spans.pop().expect("Just checked that there is an element to pop; qed"); - while id < last_span.0 { - log::warn!( - target: "tracing", - "TracingProxy Span ids not equal! id parameter given: {}, last span: {}", - id, - last_span.0, - ); - last_span.1.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); }); - if let Some(s) = self.spans.pop() { - last_span = s; - } else { - log::warn!(target: "tracing", "Span id not found in TracingProxy {}", id); - return; - } - } - } -} - - -#[cfg(test)] -mod tests { - use super::*; - - fn create_spans(proxy: &mut TracingProxy, qty: usize) -> Vec { - let mut spans = Vec::new(); - for n in 0..qty { - spans.push(proxy.enter_span("target", &format!("{}", n))); - } - spans - } - - #[test] - fn max_spans_len_respected() { - let mut proxy = TracingProxy::new(); - let _spans = create_spans(&mut proxy, MAX_SPANS_LEN + 10); - assert_eq!(proxy.spans.len(), MAX_SPANS_LEN); - // ensure oldest spans removed - assert_eq!(proxy.spans[0].0, 11); - } - - #[test] - fn handles_span_exit_scenarios() { - let mut proxy = TracingProxy::new(); - let _spans = create_spans(&mut proxy, 10); - assert_eq!(proxy.spans.len(), 10); - // exit span normally - proxy.exit_span(10); - assert_eq!(proxy.spans.len(), 9); - // skip and exit outer span without exiting inner, id: 8 instead of 9 - proxy.exit_span(8); - // should have also removed the inner span that was lost - assert_eq!(proxy.spans.len(), 7); - // try to exit span not held - proxy.exit_span(9); - assert_eq!(proxy.spans.len(), 7); - // exit all spans - proxy.exit_span(1); - assert_eq!(proxy.spans.len(), 0); - } -} diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 4d2a4fe4c6064..3a8c73857d94f 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -15,16 +15,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg_attr(not(feature = "std"), no_std)] +// #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] use sp_std::{ - vec::Vec + vec::Vec }; -// use sp_runtime_interface::pass_by::PassByCodec; +use sp_runtime_interface::pass_by::PassByCodec; use codec::{Encode, Decode}; - -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub enum WasmLevel { ERROR, WARN, @@ -33,7 +33,7 @@ pub enum WasmLevel { TRACE } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub enum WasmFieldValue { I64(i64), U64(u64), @@ -46,31 +46,44 @@ pub enum WasmFieldValue { pub type WasmFields = Vec>; pub type WasmValues = Vec<(Vec, WasmFieldValue)>; -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub struct WasmMetadata { - pub name: Vec, - pub target: Vec, - pub level: WasmLevel, - pub file: Vec, - pub line: u32, + pub name: Vec, + pub target: Vec, + pub level: WasmLevel, + pub file: Vec, + pub line: u32, pub module_path: Vec, - pub is_span: bool, - pub fields: WasmFields, + pub is_span: bool, + pub fields: WasmFields, } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub struct WasmAttributes { pub parent_id: Option, pub fields: WasmValues, pub metadata: WasmMetadata, } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub struct WasmEvent { - pub parent: Option, - pub metadata: WasmMetadata, + pub parent: Option, + pub metadata: WasmMetadata, pub fields: WasmValues, } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, PassByCodec)] pub struct WasmRecord; + +#[cfg(feature = "std")] +impl From for tracing::Level { + fn from(w: WasmLevel) -> Self { + match w { + WasmLevel::ERROR => tracing::Level::ERROR, + WasmLevel::WARN => tracing::Level::WARN, + WasmLevel::INFO => tracing::Level::INFO, + WasmLevel::DEBUG => tracing::Level::DEBUG, + WasmLevel::TRACE => tracing::Level::TRACE, + } + } +} From 60430e102d951ad87aac641adb0604703b639b79 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 29 Jul 2020 16:10:10 +0100 Subject: [PATCH 024/113] increment, it compiles --- Cargo.lock | 2 - client/executor/runtime-test/src/lib.rs | 16 +- client/executor/src/integration_tests/mod.rs | 188 +++++++++---------- client/tracing/src/lib.rs | 1 - primitives/io/src/lib.rs | 51 +---- primitives/tracing/Cargo.toml | 11 +- primitives/tracing/src/interface.rs | 94 ++++------ primitives/tracing/src/lib.rs | 2 - 8 files changed, 143 insertions(+), 222 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 189bc2ee14ec4..4ec8c56d10f3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8232,11 +8232,9 @@ dependencies = [ "log", "once_cell", "parity-scale-codec", - "sp-externalities", "sp-runtime-interface", "sp-std", "tracing", - "tracing-core", ] [[package]] diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index a80ee1d6ba40f..c80fdabf249ac 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -17,7 +17,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}, wasm_tracing, + crypto::{ed25519_verify, sr25519_verify}, }; #[cfg(not(feature = "std"))] use sp_runtime::{print, traits::{BlakeTwo256, Hash}}; @@ -253,13 +253,13 @@ 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 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 { diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 5276884e92319..546b037aa556a 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -659,98 +659,98 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) { #[test_case(WasmExecutionMethod::Interpreted)] fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { - - use std::sync::{Arc, Mutex}; - use sc_tracing::SpanDatum; - - struct TestTraceHandler(Arc>>); - - impl sc_tracing::TraceHandler for TestTraceHandler { - fn handle_span(&self, sd: SpanDatum) { - self.0.lock().unwrap().push(sd); - } - } - - 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; - assert_eq!(span_datum.target, "integration_test_span_target"); - assert_eq!(span_datum.name, "integration_test_span_name"); - assert_eq!(values.bool_values.get("wasm").unwrap(), &true); - assert_eq!(values.bool_values.get("is_valid_trace").unwrap(), &true); + // + // use std::sync::{Arc, Mutex}; + // use sc_tracing::SpanDatum; + // + // struct TestTraceHandler(Arc>>); + // + // impl sc_tracing::TraceHandler for TestTraceHandler { + // fn handle_span(&self, sd: SpanDatum) { + // self.0.lock().unwrap().push(sd); + // } + // } + // + // 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; + // assert_eq!(span_datum.target, "integration_test_span_target"); + // assert_eq!(span_datum.name, "integration_test_span_name"); + // assert_eq!(values.bool_values.get("wasm").unwrap(), &true); + // assert_eq!(values.bool_values.get("is_valid_trace").unwrap(), &true); } diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 27ee3666ea8f5..006a6ed4ed64b 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -56,7 +56,6 @@ use sp_tracing::types::{ use sp_tracing::interface::TracingSubscriber; const ZERO_DURATION: Duration = Duration::from_nanos(0); -const PROXY_TARGET: &'static str = "sp_tracing::proxy"; const UNABLE_TO_DECODE: &'static str = "Unable to decode"; /// Responsible for assigning ids to new spans, which are not re-used. diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 32dd87d97aa92..ddb23b8421bcc 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -997,55 +997,6 @@ pub trait Logging { } } -// #[cfg(feature = "std")] -// sp_externalities::decl_extension! { -// /// Extension to allow running traces in wasm via Proxy -// pub struct TracingProxyExt(sp_tracing::proxy::TracingProxy); -// } - -/// Interface that provides functions for profiling the runtime. -#[runtime_interface] -pub trait WasmTracing { - /// To create and enter a `tracing` span, using `sp_tracing::proxy` - /// Returns 0 value to indicate that no further traces should be attempted - fn enter_span(&mut self, target: &str, name: &str) -> u64 { - // if sp_tracing::wasm_tracing_enabled() { - // match self.extension::() { - // Some(proxy) => return proxy.enter_span(target, name), - // None => { - // if self.register_extension(TracingProxyExt(sp_tracing::proxy::TracingProxy::new())).is_ok() { - // if let Some(proxy) = self.extension::() { - // return proxy.enter_span(target, name); - // } - // } else { - // log::warn!( - // target: "tracing", - // "Unable to register extension: TracingProxyExt" - // ); - // } - // } - // } - // } - // log::debug!( - // target: "tracing", - // "Notify to runtime that tracing is disabled." - // ); - 0 - } - - /// Exit a `tracing` span, using `sp_tracing::proxy` - fn exit_span(&mut self, id: u64) { - // if let Some(proxy) = self.extension::() { - // proxy.exit_span(id) - // } else { - // log::warn!( - // target: "tracing", - // "Unable to load extension: TracingProxyExt" - // ); - // } - } -} - /// Wasm-only interface that provides functions for interacting with the sandbox. #[runtime_interface(wasm_only)] pub trait Sandbox { @@ -1192,7 +1143,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - wasm_tracing::HostFunctions, + sp_tracing::interface::wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index fc4cf926f01da..61538da459df6 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -12,12 +12,10 @@ description = "Instrumentation primitives and macros for Substrate." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -sp-std = { version = "2.0.0-rc5", path = "../std", default-feature = false} -sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-feature = false} +sp-std = { version = "2.0.0-rc5", path = "../std", default-features = false} +sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-features = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} -sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } tracing = { version = "0.1.13", optional = true, default-features = false } -tracing-core = { version = "0.1.11", optional = true, default-features = false } log = { version = "0.4.8", optional = true } once_cell = { version = "1.4.0", optional = true } @@ -25,20 +23,15 @@ once_cell = { version = "1.4.0", optional = true } default = [ "std" ] with-tracing = [ "tracing", - "tracing-core", "codec/derive", "codec/full", - "sp-externalities", "once_cell", ] std = [ "with-tracing", "tracing/std", - "tracing-core/std", "codec/std", - "codec/derive", "sp-std/std", "sp-runtime-interface/std", - "sp-externalities", "log", ] diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs index 737b4f4f0fe09..bc3ef37397427 100644 --- a/primitives/tracing/src/interface.rs +++ b/primitives/tracing/src/interface.rs @@ -14,22 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -// #![cfg_attr(not(feature = "std"), no_std)] -// //! Proxy to allow entering tracing spans from wasm. -// use core::{ -// default::Default, -// fmt::Debug, -// }; - -// use codec::{Encode, Decode}; -use crate::{ +use crate::types::{ WasmMetadata, WasmAttributes, WasmRecord, WasmEvent }; -// -// #[cfg(feature = "std")] -// use sp_externalities::{ExternalitiesExt, Externalities}; -// use sp_runtime_interface::runtime_interface; +use sp_runtime_interface::runtime_interface; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: WasmMetadata) -> bool; @@ -39,46 +28,39 @@ pub trait TracingSubscriber: Send + Sync { fn enter(&self, span: u64); fn exit(&self, span: u64); } -// -// #[cfg(feature="std")] -// sp_externalities::decl_extension! { -// /// The keystore extension to register/retrieve from the externalities. -// pub struct WasmTracer(Box); -// } -// -// -// /// Interface that provides tracing functions -// // #[runtime_interface(wasm_only, no_tracing)] -// #[runtime_interface] -// pub trait WasmTracing { -// fn enabled(&mut self, metadata: WasmMetadata) -> bool { -// self.extension::().map(|t|{ -// t.0.enabled(metadata) -// }).unwrap_or(false) -// } -// fn new_span(&mut self, span: WasmAttributes) -> u64 { -// self.extension::().map(|t|{ -// t.0.new_span(span) -// }).unwrap_or(0) -// } -// fn record(&mut self, span: u64, values: WasmRecord) { -// self.extension::().map(|t|{ -// t.0.record(span, values) -// }); -// } -// fn event(&mut self, event: WasmEvent) { -// self.extension::().map(|t|{ -// t.0.event(event) -// }); -// } -// fn enter(&mut self, span: u64) { -// self.extension::().map(|t|{ -// t.0.enter(span) -// }); -// } -// fn exit(&mut self, span: u64) { -// self.extension::().map(|t|{ -// t.0.exit(span) -// }); -// } -// } \ No newline at end of file + +/// Interface that provides tracing functions +// #[runtime_interface(wasm_only, no_tracing)] +#[runtime_interface] +pub trait WasmTracing { + fn enabled(&mut self, metadata: WasmMetadata) -> bool { + crate::get_tracing_subscriber().map(|t|{ + t.enabled(metadata) + }).unwrap_or(false) + } + fn new_span(&mut self, span: WasmAttributes) -> u64 { + crate::get_tracing_subscriber().map(|t|{ + t.new_span(span) + }).unwrap_or(0) + } + fn record(&mut self, span: u64, values: WasmRecord) { + crate::get_tracing_subscriber().map(|t|{ + t.record(span, values) + }); + } + fn event(&mut self, event: WasmEvent) { + crate::get_tracing_subscriber().map(|t|{ + t.event(event) + }); + } + fn enter(&mut self, span: u64) { + crate::get_tracing_subscriber().map(|t|{ + t.enter(span) + }); + } + fn exit(&mut self, span: u64) { + crate::get_tracing_subscriber().map(|t|{ + t.exit(span) + }); + } +} \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 2dac5a557d153..7fed9a99885f8 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -31,8 +31,6 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod types; -pub use types::*; - pub mod interface; #[macro_export] From 20a44795ee61f129b72a8f502394c169e85383d8 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Wed, 29 Jul 2020 19:01:01 +0100 Subject: [PATCH 025/113] attained original functionality with new mechanism --- frame/support/src/dispatch.rs | 14 ++-- frame/support/src/lib.rs | 2 + frame/support/src/wasm_tracing.rs | 108 ++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 frame/support/src/wasm_tracing.rs diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 2d9e61323b838..9604790de4c69 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1238,7 +1238,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return { - $crate::sp_tracing::enter_span!("on_initialize"); + $crate::enter_span!("on_initialize"); { $( $impl )* } } } @@ -1254,7 +1254,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize($param: $param_ty) -> $return { - $crate::sp_tracing::enter_span!("on_initialize"); + $crate::enter_span!("on_initialize"); { $( $impl )* } } } @@ -1280,7 +1280,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_runtime_upgrade() -> $return { - $crate::sp_tracing::enter_span!("on_runtime_upgrade"); + $crate::enter_span!("on_runtime_upgrade"); { $( $impl )* } } } @@ -1335,7 +1335,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { - $crate::sp_tracing::enter_span!("on_finalize"); + $crate::enter_span!("on_finalize"); { $( $impl )* } } } @@ -1351,7 +1351,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize($param: $param_ty) { - $crate::sp_tracing::enter_span!("on_finalize"); + $crate::enter_span!("on_finalize"); { $( $impl )* } } } @@ -1420,7 +1420,7 @@ macro_rules! decl_module { $vis fn $name( $origin: $origin_ty $(, $param: $param_ty )* ) -> $crate::dispatch::DispatchResult { - $crate::sp_tracing::enter_span!(stringify!($name)); + $crate::enter_span!(stringify!($name)); { $( $impl )* } Ok(()) } @@ -1439,7 +1439,7 @@ macro_rules! decl_module { ) => { $(#[doc = $doc_attr])* $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { - $crate::sp_tracing::enter_span!(stringify!($name)); + $crate::enter_span!(stringify!($name)); $( $impl )* } }; diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index bb8aacd1a4886..47850635d146d 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -66,6 +66,8 @@ pub mod inherent; pub mod unsigned; #[macro_use] pub mod error; +#[macro_use] +pub mod wasm_tracing; pub mod traits; pub mod weights; diff --git a/frame/support/src/wasm_tracing.rs b/frame/support/src/wasm_tracing.rs new file mode 100644 index 0000000000000..1ca1a0aef1a97 --- /dev/null +++ b/frame/support/src/wasm_tracing.rs @@ -0,0 +1,108 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! # To allow tracing in WASM execution environment +//! +//! Facilitated by `sp_io::wasm_tracing` + +// static mut has potential for data race conditions. +// For current use-case this is not an issue, must only be used in wasm +#[cfg(not(feature = "std"))] +static mut WASM_TRACING_ENABLED: bool = true; + +/// Indicates whether to run traces in wasm +#[cfg(not(feature = "std"))] +pub fn wasm_tracing_enabled() -> bool { + unsafe { WASM_TRACING_ENABLED } +} + +/// Disable wasm traces +#[cfg(not(feature = "std"))] +pub fn disable_wasm_tracing() { + unsafe { WASM_TRACING_ENABLED = false } +} + +/// This holds a tracing span id and is to signal on drop that a tracing span has exited. +/// It must be bound to a named variable eg. `_span_guard`. +#[cfg(not(feature = "std"))] +pub struct TracingSpanGuard(Option); + +#[cfg(not(feature = "std"))] +impl TracingSpanGuard { + pub fn new(span: Option) -> Self { + Self(span) + } +} + +#[cfg(not(feature = "std"))] +impl Drop for TracingSpanGuard { + fn drop(&mut self) { + if let Some(id) = self.0.take() { + crate::sp_tracing::interface::wasm_tracing::exit(id); + } + } +} + +/// Enters a tracing span, via [`sp_tracing::proxy`] measuring execution time +/// until exit from the current scope. +/// +/// It's also possible to directly call the functions `enter_span` and `exit_span` +/// in `sp_io::wasm_tracing` if more fine-grained control of span duration is required. +/// +/// # Example +/// +/// ``` +/// frame_support::enter_span!("fn_name"); +/// ``` +#[macro_export] +macro_rules! enter_span { + ( $name:expr ) => { + #[cfg(not(feature = "std"))] + let __span_id__ = if $crate::wasm_tracing::wasm_tracing_enabled() { + use $crate::sp_std::prelude::*; + let metadata = $crate::sp_tracing::types::WasmMetadata { + name: $name.bytes().collect::>(), + target: module_path!().bytes().collect::>(), + level: $crate::sp_tracing::types::WasmLevel::INFO, + file: file!().bytes().collect::>(), + line: line!(), + module_path: module_path!().bytes().collect::>(), + is_span: true, + fields: Vec::new(), + }; + let attrs = $crate::sp_tracing::types::WasmAttributes{ + parent_id: None, + fields: Vec::new(), + metadata, + }; + let id = $crate::sp_tracing::interface::wasm_tracing::new_span( + attrs + ); + if id == 0 { + $crate::wasm_tracing::disable_wasm_tracing(); + $crate::wasm_tracing::TracingSpanGuard::new(None) + } else { + $crate::sp_tracing::interface::wasm_tracing::enter(id); + $crate::wasm_tracing::TracingSpanGuard::new(Some(id)) + } + } else { + $crate::wasm_tracing::TracingSpanGuard::new(None) + }; + #[cfg(feature = "std")] + $crate::sp_tracing::enter_span!($name); + } +} + From 3fb87a0c079545f080727d495c739f6643d736a3 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 30 Jul 2020 11:33:10 +0100 Subject: [PATCH 026/113] implement remaining TracingSubscriber functions --- client/tracing/src/lib.rs | 49 ++++++++++++++++++++--------- primitives/tracing/src/interface.rs | 6 ++-- primitives/tracing/src/types.rs | 24 +++++++++++--- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 006a6ed4ed64b..f7a277e50afc4 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -51,7 +51,6 @@ use sp_tracing::types::{ WasmMetadata, WasmAttributes, WasmEvent, - WasmRecord, }; use sp_tracing::interface::TracingSubscriber; @@ -94,7 +93,7 @@ pub trait TraceHandler: Send + Sync { /// Represents a tracing event, complete with values #[derive(Debug)] pub struct TraceEvent { - pub name: &'static str, + pub name: String, pub target: String, pub level: Level, pub values: Values, @@ -150,6 +149,13 @@ impl Values { self.u64_values.is_empty() && self.string_values.is_empty() } + + pub fn extend(&mut self, other: Values) { + self.bool_values.extend(other.bool_values.into_iter()); + self.i64_values.extend(other.i64_values.into_iter()); + self.u64_values.extend(other.u64_values.into_iter()); + self.string_values.extend(other.string_values.into_iter()); + } } impl Visit for Values { @@ -317,8 +323,15 @@ impl From for Values { impl TracingSubscriber for ProfilingSubscriber { fn enabled(&self, metadata: WasmMetadata) -> bool { - // TODO move levels into static and implement - true + let level = metadata.level(); + let target = metadata.target(); + if self.check_target(target, &level) { + log::debug!(target: "tracing", "Enabled target: {}, level: {}", target, level); + true + } else { + log::debug!(target: "tracing", "Disabled target: {}, level: {}", target, level); + false + } } fn new_span(&self, attrs: WasmAttributes) -> u64 { @@ -339,12 +352,24 @@ impl TracingSubscriber for ProfilingSubscriber { id } - fn record(&self, _span: u64, _values: WasmRecord) { - // TODO + fn record(&self, span: u64, values: WasmValues) { + let mut span_data = self.span_data.lock(); + if let Some(mut s) = span_data.get_mut(&Id::from_u64(span)) { + let new_values: Values = values.into(); + s.values.extend(new_values); + } } - fn event(&self, _event: WasmEvent) { - // TODO + fn event(&self, event: WasmEvent) { + let mut values = event.fields.into(); + let trace_event = TraceEvent { + name: event.metadata.name().to_owned(), + target: event.metadata.target().to_owned(), + level: event.metadata.level(), + values, + parent_id: event.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), + }; + self.trace_handler.handle_event(trace_event); } fn enter(&self, span: u64) { @@ -383,12 +408,6 @@ impl Subscriber for ProfilingSubscriber { let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed)); 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 id - // } - // } let span_datum = SpanDatum { id: id.clone(), parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), @@ -417,7 +436,7 @@ impl Subscriber for ProfilingSubscriber { let mut values = Values::default(); event.record(&mut values); let trace_event = TraceEvent { - name: event.metadata().name(), + name: event.metadata().name().to_owned(), target: event.metadata().target().to_owned(), level: event.metadata().level().clone(), values, diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs index bc3ef37397427..fb84228ea89ca 100644 --- a/primitives/tracing/src/interface.rs +++ b/primitives/tracing/src/interface.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . use crate::types::{ - WasmMetadata, WasmAttributes, WasmRecord, WasmEvent + WasmMetadata, WasmAttributes, WasmValues, WasmEvent }; use sp_runtime_interface::runtime_interface; @@ -23,7 +23,7 @@ use sp_runtime_interface::runtime_interface; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; - fn record(&self, span: u64, values: WasmRecord); + fn record(&self, span: u64, values: WasmValues); fn event(&self, event: WasmEvent); fn enter(&self, span: u64); fn exit(&self, span: u64); @@ -43,7 +43,7 @@ pub trait WasmTracing { t.new_span(span) }).unwrap_or(0) } - fn record(&mut self, span: u64, values: WasmRecord) { + fn record(&mut self, span: u64, values: WasmValues) { crate::get_tracing_subscriber().map(|t|{ t.record(span, values) }); diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 3a8c73857d94f..d6ea884a62017 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -24,7 +24,7 @@ use sp_std::{ use sp_runtime_interface::pass_by::PassByCodec; use codec::{Encode, Decode}; -#[derive(Encode, Decode, PassByCodec)] +#[derive(Clone, Encode, Decode, PassByCodec)] pub enum WasmLevel { ERROR, WARN, @@ -67,13 +67,14 @@ pub struct WasmAttributes { #[derive(Encode, Decode, PassByCodec)] pub struct WasmEvent { - pub parent: Option, + pub parent_id: Option, pub metadata: WasmMetadata, pub fields: WasmValues, } -#[derive(Encode, Decode, PassByCodec)] -pub struct WasmRecord; +// TODO - Do we need this when we have WasmValues ? +// #[derive(Encode, Decode, PassByCodec)] +// pub struct WasmRecord; #[cfg(feature = "std")] impl From for tracing::Level { @@ -87,3 +88,18 @@ impl From for tracing::Level { } } } + +#[cfg(feature = "std")] +impl WasmMetadata { + pub fn target(&self) -> &str { + std::str::from_utf8(&self.target).unwrap() + } + + pub fn name(&self) -> &str { + std::str::from_utf8(&self.name).unwrap() + } + + pub fn level(&self) -> tracing::Level { + self.level.clone().into() + } +} From eb6730a343559ffbad1e4bd4249c1fcf7bb91756 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 30 Jul 2020 15:07:06 +0100 Subject: [PATCH 027/113] remove spans from decl_module --- frame/support/src/dispatch.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 9604790de4c69..6461273e5b0ee 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1238,7 +1238,6 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return { - $crate::enter_span!("on_initialize"); { $( $impl )* } } } @@ -1254,7 +1253,6 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize($param: $param_ty) -> $return { - $crate::enter_span!("on_initialize"); { $( $impl )* } } } @@ -1280,7 +1278,6 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_runtime_upgrade() -> $return { - $crate::enter_span!("on_runtime_upgrade"); { $( $impl )* } } } @@ -1335,7 +1332,6 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { - $crate::enter_span!("on_finalize"); { $( $impl )* } } } @@ -1351,7 +1347,6 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize($param: $param_ty) { - $crate::enter_span!("on_finalize"); { $( $impl )* } } } @@ -1420,7 +1415,6 @@ macro_rules! decl_module { $vis fn $name( $origin: $origin_ty $(, $param: $param_ty )* ) -> $crate::dispatch::DispatchResult { - $crate::enter_span!(stringify!($name)); { $( $impl )* } Ok(()) } @@ -1439,7 +1433,6 @@ macro_rules! decl_module { ) => { $(#[doc = $doc_attr])* $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { - $crate::enter_span!(stringify!($name)); $( $impl )* } }; From 155919558fa600a0225aa0bcd82c14836d7bcba5 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Thu, 30 Jul 2020 17:28:23 +0100 Subject: [PATCH 028/113] add handling for encoded values --- client/tracing/src/lib.rs | 19 +++++++++++++++---- frame/support/src/wasm_tracing.rs | 6 +++--- primitives/tracing/src/types.rs | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index f7a277e50afc4..db1006b231685 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -134,6 +134,8 @@ pub struct Values { pub u64_values: FxHashMap, /// HashMap of `String` values pub string_values: FxHashMap, + /// HashMap of `String` values + pub encoded_values: FxHashMap>, } impl Values { @@ -147,14 +149,17 @@ impl Values { self.bool_values.is_empty() && self.i64_values.is_empty() && self.u64_values.is_empty() && - self.string_values.is_empty() + self.string_values.is_empty() && + self.encoded_values.is_empty() } + /// Extend self with other pub fn extend(&mut self, other: Values) { self.bool_values.extend(other.bool_values.into_iter()); self.i64_values.extend(other.i64_values.into_iter()); self.u64_values.extend(other.u64_values.into_iter()); self.string_values.extend(other.string_values.into_iter()); + self.encoded_values.extend(other.encoded_values.into_iter()); } } @@ -208,7 +213,13 @@ impl fmt::Display for Values { let i64_iter = self.i64_values.iter().map(|(k, v)| format!("{}={}", k, v)); let u64_iter = self.u64_values.iter().map(|(k, v)| format!("{}={}", k, v)); let string_iter = self.string_values.iter().map(|(k, v)| format!("{}=\"{}\"", k, v)); - let values = bool_iter.chain(i64_iter).chain(u64_iter).chain(string_iter).collect::>().join(", "); + let encoded_iter = self.encoded_values.iter().map(|(k, v)| format!("{}={:?}", k, v)); + let values = bool_iter + .chain(i64_iter) + .chain(u64_iter) + .chain(string_iter) + .chain(encoded_iter) + .collect::>().join(", "); write!(f, "{}", values) } } @@ -311,8 +322,8 @@ impl From for Values { let s = String::from_utf8(v).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()); values.string_values.insert(key, s); } - WasmFieldValue::Encoded(_v) => { - // TODO + WasmFieldValue::Encoded(v) => { + values.encoded_values.insert(key, v); } } } diff --git a/frame/support/src/wasm_tracing.rs b/frame/support/src/wasm_tracing.rs index 1ca1a0aef1a97..73e4fa65a8181 100644 --- a/frame/support/src/wasm_tracing.rs +++ b/frame/support/src/wasm_tracing.rs @@ -69,7 +69,7 @@ impl Drop for TracingSpanGuard { /// ``` #[macro_export] macro_rules! enter_span { - ( $name:expr ) => { + ( $name:expr, $values:expr ) => { #[cfg(not(feature = "std"))] let __span_id__ = if $crate::wasm_tracing::wasm_tracing_enabled() { use $crate::sp_std::prelude::*; @@ -85,14 +85,14 @@ macro_rules! enter_span { }; let attrs = $crate::sp_tracing::types::WasmAttributes{ parent_id: None, - fields: Vec::new(), + fields: $values, metadata, }; let id = $crate::sp_tracing::interface::wasm_tracing::new_span( attrs ); if id == 0 { - $crate::wasm_tracing::disable_wasm_tracing(); + // $crate::wasm_tracing::disable_wasm_tracing(); $crate::wasm_tracing::TracingSpanGuard::new(None) } else { $crate::sp_tracing::interface::wasm_tracing::enter(id); diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index d6ea884a62017..46ab3d6521f81 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -33,7 +33,7 @@ pub enum WasmLevel { TRACE } -#[derive(Encode, Decode, PassByCodec)] +#[derive(Encode, Decode, PassByCodec, Debug)] pub enum WasmFieldValue { I64(i64), U64(u64), From bd2d5607c3ef96df0f903035b19c6812783d1f97 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 11:03:51 +0200 Subject: [PATCH 029/113] Revert "replace with global tracing" This reverts commit 8824a60deea54d9b437407a21c8ceaf6a1902ee5. --- Cargo.lock | 1 + primitives/runtime-interface/Cargo.toml | 2 ++ primitives/runtime-interface/proc-macro/src/lib.rs | 4 +--- .../src/runtime_interface/bare_function_interface.rs | 9 +++++---- .../src/runtime_interface/host_function_interface.rs | 1 + .../proc-macro/src/runtime_interface/mod.rs | 6 +----- primitives/runtime-interface/src/lib.rs | 3 +++ 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 696622241d3df..9be64dc651546 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8017,6 +8017,7 @@ dependencies = [ "sp-runtime-interface-test-wasm", "sp-state-machine", "sp-std", + "sp-tracing", "sp-wasm-interface", "static_assertions", "trybuild", diff --git a/primitives/runtime-interface/Cargo.toml b/primitives/runtime-interface/Cargo.toml index 70b892495ea5f..16d5a14e889b1 100644 --- a/primitives/runtime-interface/Cargo.toml +++ b/primitives/runtime-interface/Cargo.toml @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-wasm-interface = { version = "2.0.0-rc5", path = "../wasm-interface", default-features = false } sp-std = { version = "2.0.0-rc5", default-features = false, path = "../std" } +sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../tracing" } sp-runtime-interface-proc-macro = { version = "2.0.0-rc5", path = "proc-macro" } sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../externalities" } codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false } @@ -34,6 +35,7 @@ default = [ "std" ] std = [ "sp-wasm-interface/std", "sp-std/std", + "sp-tracing/std", "codec/std", "sp-externalities", "primitive-types/std", diff --git a/primitives/runtime-interface/proc-macro/src/lib.rs b/primitives/runtime-interface/proc-macro/src/lib.rs index 49f42f82408f7..2f5b9de1c14e7 100644 --- a/primitives/runtime-interface/proc-macro/src/lib.rs +++ b/primitives/runtime-interface/proc-macro/src/lib.rs @@ -39,10 +39,8 @@ pub fn runtime_interface( ) -> proc_macro::TokenStream { let trait_def = parse_macro_input!(input as ItemTrait); let wasm_only = parse_macro_input!(attrs as Option); - // FIXME: actual parse for this - let no_tracing : Option<()> = None; //parse_macro_input!(tracing_attrs as Option); - runtime_interface::runtime_interface_impl(trait_def, wasm_only.is_some(), no_tracing.is_none()) + runtime_interface::runtime_interface_impl(trait_def, wasm_only.is_some()) .unwrap_or_else(|e| e.to_compile_error()) .into() } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index a3dbcf6f25d3d..6760e9656113a 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -62,10 +62,10 @@ pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result = runtime_interface.all_versions().try_fold(token_stream?, |mut t, (version, method)| - { - t.extend(function_std_impl(trait_name, method, version, is_wasm_only)?); - Ok(t) - }); + { + t.extend(function_std_impl(trait_name, method, version, is_wasm_only)?); + Ok(t) + }); result } @@ -174,6 +174,7 @@ fn function_std_impl( #[cfg(feature = "std")] #( #attrs )* fn #function_name( #( #args, )* ) #return_value { + #crate_::sp_tracing::enter_span!(#function_name_str); #call_to_trait } } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 7a4dbc5773a28..721eed649c25d 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -227,6 +227,7 @@ fn generate_host_function_implementation( __function_context__: &mut dyn #crate_::sp_wasm_interface::FunctionContext, args: &mut dyn Iterator, ) -> std::result::Result, String> { + #crate_::sp_tracing::enter_span!(#name); #( #wasm_to_ffi_values )* #( #ffi_to_host_values )* #host_function_call diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs index d962db8af021f..c9b6edf68fd5a 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs @@ -33,17 +33,13 @@ mod trait_decl_impl; pub mod keywords { // Custom keyword `wasm_only` that can be given as attribute to [`runtime_interface`]. syn::custom_keyword!(wasm_only); - // Custom keyword `no_tracing` that can be given as attribute to [`runtime_interface`]. - syn::custom_keyword!(no_tracing); } /// Implementation of the `runtime_interface` attribute. /// /// It expects the trait definition the attribute was put above and if this should be an wasm only /// interface. -pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool, with_tracing: bool) - -> Result -{ +pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool) -> Result { let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only)?; let crate_include = generate_runtime_interface_include(); let mod_name = Ident::new(&trait_def.ident.to_string().to_snake_case(), Span::call_site()); diff --git a/primitives/runtime-interface/src/lib.rs b/primitives/runtime-interface/src/lib.rs index 423a4b1ae9a64..562f94b278efc 100644 --- a/primitives/runtime-interface/src/lib.rs +++ b/primitives/runtime-interface/src/lib.rs @@ -110,6 +110,9 @@ extern crate self as sp_runtime_interface; #[cfg(feature = "std")] pub use sp_wasm_interface; +#[doc(hidden)] +pub use sp_tracing; + #[doc(hidden)] pub use sp_std; From ca46e023537e965cda8312e1f22acd8590f47bee Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 12:06:40 +0200 Subject: [PATCH 030/113] Wasm Side Tracing --- Cargo.lock | 1 - primitives/io/src/lib.rs | 76 +++++++++++++++++++++++++- primitives/tracing/Cargo.toml | 8 +-- primitives/tracing/src/interface.rs | 66 ---------------------- primitives/tracing/src/lib.rs | 50 ++++++++++++----- primitives/tracing/src/types.rs | 14 ++--- primitives/tracing/src/wasm_tracing.rs | 38 ++++++------- 7 files changed, 138 insertions(+), 115 deletions(-) delete mode 100644 primitives/tracing/src/interface.rs diff --git a/Cargo.lock b/Cargo.lock index 9be64dc651546..4eb59d64e7eaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8183,7 +8183,6 @@ dependencies = [ "log", "once_cell", "parity-scale-codec", - "sp-runtime-interface", "sp-std", "tracing", ] diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index ddb23b8421bcc..948941485c9b3 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -52,6 +52,7 @@ use sp_core::{ use sp_trie::{TrieConfiguration, trie_types::Layout}; use sp_runtime_interface::{runtime_interface, Pointer}; +use sp_runtime_interface::pass_by::PassBy; use codec::{Encode, Decode}; @@ -997,6 +998,79 @@ pub trait Logging { } } +#[derive(Encode, Decode)] +pub struct Crossing(T); +impl PassBy for Crossing { + type PassBy = sp_runtime_interface::pass_by::Codec; +} + +/// Interface that provides tracing functions +// #[runtime_interface(wasm_only, no_tracing)] +#[runtime_interface] +pub trait WasmTracing { + fn enabled(&mut self, metadata: Crossing) -> bool { + todo! {} + } + fn new_span(&mut self, span: Crossing) -> u64 { + + todo! {} + // crate::get_tracing_subscriber().map(|t|{ + // t.new_span(span) + // }).unwrap_or(0) + } + fn record(&mut self, span: u64, values: Crossing) { + + todo! {} + // crate::get_tracing_subscriber().map(|t|{ + // t.record(span, values) + // }); + } + fn event(&mut self, event: Crossing) { + + todo! {} + // crate::get_tracing_subscriber().map(|t|{ + // t.event(event) + // }); + } + fn enter(&mut self, span: u64) { + + todo! {} + // crate::get_tracing_subscriber().map(|t|{ + // t.enter(span) + // }); + } + fn exit(&mut self, span: u64) { + + todo! {} + // crate::get_tracing_subscriber().map(|t|{ + // t.exit(span) + // }); + } +} + + +pub struct PassingTracingSubsciber; +impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { + fn enabled(&self, metadata: sp_tracing::WasmMetadata) -> bool { + wasm_tracing::enabled(Crossing(metadata)) + } + fn new_span(&self, attrs: sp_tracing::WasmAttributes) -> u64 { + wasm_tracing::new_span(Crossing(attrs)) + } + fn record(&self, span: u64, values: sp_tracing::WasmValues) { + wasm_tracing::record(span, Crossing(values)) + } + fn event(&self, event: sp_tracing::WasmEvent) { + wasm_tracing::event(Crossing(event)) + } + fn enter(&self, span: u64) { + wasm_tracing::enter(span) + } + fn exit(&self, span: u64) { + wasm_tracing::enter(span) + } +} + /// Wasm-only interface that provides functions for interacting with the sandbox. #[runtime_interface(wasm_only)] pub trait Sandbox { @@ -1143,7 +1217,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - sp_tracing::interface::wasm_tracing::HostFunctions, + wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 61538da459df6..279e56340d570 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -13,16 +13,14 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-std = { version = "2.0.0-rc5", path = "../std", default-features = false} -sp-runtime-interface = { version = "2.0.0-rc5", path = "../runtime-interface", default-features = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} -tracing = { version = "0.1.13", optional = true, default-features = false } +tracing = { version = "0.1.13", default-features = false } log = { version = "0.4.8", optional = true } -once_cell = { version = "1.4.0", optional = true } +once_cell = { version = "1.4.0", optional = true, default-features = true } [features] default = [ "std" ] with-tracing = [ - "tracing", "codec/derive", "codec/full", "once_cell", @@ -32,6 +30,6 @@ std = [ "tracing/std", "codec/std", "sp-std/std", - "sp-runtime-interface/std", + "once_cell/std", "log", ] diff --git a/primitives/tracing/src/interface.rs b/primitives/tracing/src/interface.rs deleted file mode 100644 index fb84228ea89ca..0000000000000 --- a/primitives/tracing/src/interface.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use crate::types::{ - WasmMetadata, WasmAttributes, WasmValues, WasmEvent -}; - -use sp_runtime_interface::runtime_interface; - -pub trait TracingSubscriber: Send + Sync { - fn enabled(&self, metadata: WasmMetadata) -> bool; - fn new_span(&self, attrs: WasmAttributes) -> u64; - fn record(&self, span: u64, values: WasmValues); - fn event(&self, event: WasmEvent); - fn enter(&self, span: u64); - fn exit(&self, span: u64); -} - -/// Interface that provides tracing functions -// #[runtime_interface(wasm_only, no_tracing)] -#[runtime_interface] -pub trait WasmTracing { - fn enabled(&mut self, metadata: WasmMetadata) -> bool { - crate::get_tracing_subscriber().map(|t|{ - t.enabled(metadata) - }).unwrap_or(false) - } - fn new_span(&mut self, span: WasmAttributes) -> u64 { - crate::get_tracing_subscriber().map(|t|{ - t.new_span(span) - }).unwrap_or(0) - } - fn record(&mut self, span: u64, values: WasmValues) { - crate::get_tracing_subscriber().map(|t|{ - t.record(span, values) - }); - } - fn event(&mut self, event: WasmEvent) { - crate::get_tracing_subscriber().map(|t|{ - t.event(event) - }); - } - fn enter(&mut self, span: u64) { - crate::get_tracing_subscriber().map(|t|{ - t.enter(span) - }); - } - fn exit(&mut self, span: u64) { - crate::get_tracing_subscriber().map(|t|{ - t.exit(span) - }); - } -} \ No newline at end of file diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 7fed9a99885f8..205f2f31dfd0b 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -31,31 +31,42 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod types; -pub mod interface; #[macro_export] #[cfg(not(feature = "std"))] mod wasm_tracing; #[macro_export] -#[cfg(feature = "std")] -pub use tracing; +use tracing; -#[cfg(not(feature = "std"))] pub use types::WasmLevel as Level; -#[cfg(feature = "std")] -use std::sync::atomic::{AtomicBool, Ordering}; -#[cfg(feature = "std")] +use sp_std::boxed::Box; +use core::sync::atomic::{AtomicBool, Ordering}; +#[cfg(any(feature = "std", feature = "with-tracing"))] use once_cell::sync::OnceCell; /// Flag to signal whether to run wasm tracing #[cfg(feature = "std")] static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); + +pub use crate::types::{ + WasmMetadata, WasmAttributes, WasmValues, WasmEvent +}; + +pub trait TracingSubscriber: Send + Sync { + fn enabled(&self, metadata: WasmMetadata) -> bool; + fn new_span(&self, attrs: WasmAttributes) -> u64; + fn record(&self, span: u64, values: WasmValues); + fn event(&self, event: WasmEvent); + fn enter(&self, span: u64); + fn exit(&self, span: u64); +} + /// Instance of the native subscriber in use -#[cfg(feature = "std")] -static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); +#[cfg(any(feature = "std", feature = "with-tracing"))] +static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); /// Runs given code within a tracing span, measuring it's execution time. /// @@ -96,7 +107,7 @@ macro_rules! tracing_span { macro_rules! enter_span { ( $name:expr ) => { let __tracing_span__ = $crate::if_tracing!( - $crate::tracing::span!($crate::tracing::Level::TRACE, $name) + $crate::tracing_span!($crate::Level::TRACE, $name) ); let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); } @@ -125,12 +136,23 @@ pub fn set_wasm_tracing(b: bool) { WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) } -#[cfg(feature = "std")] -pub fn set_tracing_subscriber(subscriber: Box) { +#[cfg(any(feature = "std", feature = "with-tracing"))] +pub fn set_tracing_subscriber(subscriber: Box) { let _ = SUBSCRIBER_INSTANCE.set(subscriber); } -#[cfg(feature = "std")] -pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { +#[cfg(any(feature = "std", feature = "with-tracing"))] +pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { SUBSCRIBER_INSTANCE.get() +} + + +#[cfg(not(any(feature = "std", feature = "with-tracing")))] +pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { + None +} + +#[cfg(not(any(feature = "std", feature = "with-tracing")))] +pub fn set_tracing_subscriber(subscriber: Box) { + unreachable!() } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 46ab3d6521f81..4a5fc40b40cd3 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -17,14 +17,12 @@ // #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] use sp_std::{ vec::Vec }; -use sp_runtime_interface::pass_by::PassByCodec; use codec::{Encode, Decode}; -#[derive(Clone, Encode, Decode, PassByCodec)] +#[derive(Clone, Encode, Decode)] pub enum WasmLevel { ERROR, WARN, @@ -33,7 +31,7 @@ pub enum WasmLevel { TRACE } -#[derive(Encode, Decode, PassByCodec, Debug)] +#[derive(Encode, Decode, Debug)] pub enum WasmFieldValue { I64(i64), U64(u64), @@ -46,7 +44,7 @@ pub enum WasmFieldValue { pub type WasmFields = Vec>; pub type WasmValues = Vec<(Vec, WasmFieldValue)>; -#[derive(Encode, Decode, PassByCodec)] +#[derive(Encode, Decode)] pub struct WasmMetadata { pub name: Vec, pub target: Vec, @@ -58,14 +56,14 @@ pub struct WasmMetadata { pub fields: WasmFields, } -#[derive(Encode, Decode, PassByCodec)] +#[derive(Encode, Decode)] pub struct WasmAttributes { pub parent_id: Option, pub fields: WasmValues, pub metadata: WasmMetadata, } -#[derive(Encode, Decode, PassByCodec)] +#[derive(Encode, Decode)] pub struct WasmEvent { pub parent_id: Option, pub metadata: WasmMetadata, @@ -73,7 +71,7 @@ pub struct WasmEvent { } // TODO - Do we need this when we have WasmValues ? -// #[derive(Encode, Decode, PassByCodec)] +// #[derive(Encode, Decode)] // pub struct WasmRecord; #[cfg(feature = "std")] diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index bd7627b872cf2..45368d26c813d 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -70,7 +70,6 @@ mod inner { module_path, concat, format_args, file, line, }; use crate::{WasmMetadata}; - use crate::interface::wasm_tracing; // just a simplistic holder for span and entered spans // that exits on drop @@ -80,7 +79,7 @@ mod inner { impl Span { pub fn enter(self) -> Entered { if self.0 != 0 { - wasm_tracing::enter(self.0); + crate::get_tracing_subscriber().map(|t| t.enter(self.0)); } Entered(self.0) } @@ -89,7 +88,7 @@ mod inner { impl Entered { pub fn exit(&mut self) { if self.0 != 0 { - wasm_tracing::exit(self.0); + crate::get_tracing_subscriber().map(|t| t.exit(self.0)); } } } @@ -171,11 +170,11 @@ mod inner { fields: $($fields)* }; if $crate::is_enabled!(&metdata) { - wasm_tracing::event(WasmEvent { + $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { parent: $parent, metadata, &$crate::valueset!(meta.fields(), $($fields)*) - }) + })); } } } @@ -216,11 +215,11 @@ mod inner { fields: $($fields)* }; if $crate::is_enabled!(&metdata) { - wasm_tracing::event(WasmEvent { + $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { parent: None, metadata, &$crate::valueset!(meta.fields(), $($fields)*) - }); + })); } } } @@ -380,17 +379,17 @@ mod inner { fields: $($fields)* }; if $crate::is_enabled!(metadata) { - let span_id = wasm_tracing::new_span(WasmAttributes{ + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span(WasmAttributes{ parent: Some($parent), metadata, &$crate::valueset!(meta.fields(), $($fields)*) - }) - $crate::wasm_tracing::Span(span_id) + })).unwrap_or_default(); + $crate::Span(span_id) } else { - $crate::wasm_tracing::Span(0) + $crate::Span(0) } } else { - $crate::wasm_tracing::Span(0) + $crate::Span(0) } } }; @@ -410,17 +409,17 @@ mod inner { fields: $($fields)* }; if $crate::is_enabled!(metadata) { - let span_id = wasm_tracing::new_span(WasmAttributes{ - parent: None, + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span(WasmAttributes{ + parent: Some($parent), metadata, &$crate::valueset!(meta.fields(), $($fields)*) - }) - $crate::wasm_tracing::Span(span_id) + })).unwrap_or_default(); + $crate::Span(span_id) } else { - $crate::wasm_tracing::Span(0) + $crate::Span(0) } } else { - $crate::wasm_tracing::Span(0) + $crate::Span(0) } } }; @@ -1947,8 +1946,7 @@ macro_rules! level_enabled { #[doc(hidden)] macro_rules! is_enabled { ($metadata:expr) => {{ - // FIXME: use the runtime interface to figure this out - true + $crate::get_tracing_subscriber().map(|t| t.enabled($metadata)).unwrap_or_false() }}; } From 36318c1a80f9c4c62bece986ea69eb5a3f4cd9de Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 13:33:30 +0200 Subject: [PATCH 031/113] tracing on wasm --- client/executor/runtime-test/src/lib.rs | 14 +++++++------- frame/support/src/lib.rs | 2 -- primitives/io/src/lib.rs | 3 +-- primitives/tracing/src/lib.rs | 17 +++++++++++------ primitives/tracing/src/types.rs | 2 -- primitives/tracing/src/wasm_tracing.rs | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index c80fdabf249ac..f56030b19b277 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -253,13 +253,13 @@ 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 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 { diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 6c846b7ce7151..f0ffdc90a74e0 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -66,8 +66,6 @@ pub mod inherent; pub mod unsigned; #[macro_use] pub mod error; -#[macro_use] -pub mod wasm_tracing; pub mod traits; pub mod weights; diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 948941485c9b3..08a96bb58652a 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1005,7 +1005,6 @@ impl PassBy for Crossing { } /// Interface that provides tracing functions -// #[runtime_interface(wasm_only, no_tracing)] #[runtime_interface] pub trait WasmTracing { fn enabled(&mut self, metadata: Crossing) -> bool { @@ -1217,7 +1216,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - wasm_tracing::HostFunctions, + // wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 205f2f31dfd0b..6bb8174e6fb2b 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -32,14 +32,17 @@ pub mod types; -#[macro_export] #[cfg(not(feature = "std"))] +#[macro_export] mod wasm_tracing; -#[macro_export] +#[cfg(feature = "std")] use tracing; -pub use types::WasmLevel as Level; +#[cfg(feature = "std")] +pub use tracing::{ + span, event, Level +}; use sp_std::boxed::Box; use core::sync::atomic::{AtomicBool, Ordering}; @@ -52,8 +55,10 @@ static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); pub use crate::types::{ - WasmMetadata, WasmAttributes, WasmValues, WasmEvent + WasmMetadata, WasmAttributes, WasmValues, WasmEvent, WasmLevel, }; +#[cfg(not(feature = "std"))] +pub type Level = WasmLevel; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: WasmMetadata) -> bool; @@ -107,9 +112,9 @@ macro_rules! tracing_span { macro_rules! enter_span { ( $name:expr ) => { let __tracing_span__ = $crate::if_tracing!( - $crate::tracing_span!($crate::Level::TRACE, $name) + $crate::span!($crate::Level::TRACE, $name) ); - let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); + // let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); } } diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 4a5fc40b40cd3..a09db77875e65 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -15,8 +15,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// #![cfg_attr(not(feature = "std"), no_std)] - use sp_std::{ vec::Vec }; diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 45368d26c813d..5a31f79eef8c3 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] use sp_std::{ vec From 5ee63200fb419f818702b0386c440b832aae2356 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 14:58:04 +0200 Subject: [PATCH 032/113] enable tracing wasm on node-runtime --- Cargo.lock | 1 + bin/node/runtime/Cargo.toml | 2 ++ bin/node/runtime/build.rs | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4eb59d64e7eaf..ee4a73d74e953 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3789,6 +3789,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", + "sp-tracing", "sp-transaction-pool", "sp-version", "static_assertions", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 35ed7400459f2..3407bee8f693d 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -36,6 +36,7 @@ sp-keyring = { version = "2.0.0-rc5", optional = true, path = "../../../primitiv sp-session = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/session" } sp-transaction-pool = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/transaction-pool" } sp-version = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/version" } +sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/tracing" } # frame dependencies frame-executive = { version = "2.0.0-rc5", default-features = false, path = "../../../frame/executive" } @@ -88,6 +89,7 @@ sp-io = { version = "2.0.0-rc5", path = "../../../primitives/io" } [features] default = ["std"] +with-tracing = [ "sp-tracing/with-tracing" ] std = [ "sp-authority-discovery/std", "pallet-authority-discovery/std", diff --git a/bin/node/runtime/build.rs b/bin/node/runtime/build.rs index a2f09a460e69d..c45de46dba96f 100644 --- a/bin/node/runtime/build.rs +++ b/bin/node/runtime/build.rs @@ -23,5 +23,14 @@ fn main() { .with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder") .export_heap_base() .import_memory() - .build() + .build(); + + 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(); } From c3198815569f6293de1e87e737735c4e1b52a607 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 14:58:34 +0200 Subject: [PATCH 033/113] export all the macros in std --- primitives/tracing/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 6bb8174e6fb2b..df009aefff164 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -41,6 +41,7 @@ use tracing; #[cfg(feature = "std")] pub use tracing::{ + debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span, span, event, Level }; From b133bcf5b84b6488da302aa1cefd972f54d0882e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 15:48:06 +0200 Subject: [PATCH 034/113] tracing subscriber on wasm-side only --- Cargo.lock | 1 - client/tracing/src/lib.rs | 72 ----------------------------- primitives/io/src/lib.rs | 4 ++ primitives/tracing/Cargo.toml | 3 -- primitives/tracing/src/lib.rs | 85 +++++++++++++++++------------------ 5 files changed, 45 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee4a73d74e953..6ec42b33d86c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8182,7 +8182,6 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", - "once_cell", "parity-scale-codec", "sp-std", "tracing", diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index db1006b231685..ae4cc6dd133d2 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -52,7 +52,6 @@ use sp_tracing::types::{ WasmAttributes, WasmEvent, }; -use sp_tracing::interface::TracingSubscriber; const ZERO_DURATION: Duration = Duration::from_nanos(0); const UNABLE_TO_DECODE: &'static str = "Unable to decode"; @@ -332,77 +331,6 @@ impl From for Values { } } -impl TracingSubscriber for ProfilingSubscriber { - fn enabled(&self, metadata: WasmMetadata) -> bool { - let level = metadata.level(); - let target = metadata.target(); - if self.check_target(target, &level) { - log::debug!(target: "tracing", "Enabled target: {}, level: {}", target, level); - true - } else { - log::debug!(target: "tracing", "Disabled target: {}, level: {}", target, level); - false - } - } - - fn new_span(&self, attrs: WasmAttributes) -> u64 { - let id = self.next_id.fetch_add(1, Ordering::Relaxed); - let values = attrs.fields.into(); - let span_datum = SpanDatum { - id: Id::from_u64(id.clone()), - parent_id: attrs.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), - name: String::from_utf8(attrs.metadata.name).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), - target: String::from_utf8(attrs.metadata.target).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), - level: attrs.metadata.level.into(), - line: attrs.metadata.line, - start_time: Instant::now(), - overall_time: ZERO_DURATION, - values, - }; - self.span_data.lock().insert(span_datum.id.clone(), span_datum); - id - } - - fn record(&self, span: u64, values: WasmValues) { - let mut span_data = self.span_data.lock(); - if let Some(mut s) = span_data.get_mut(&Id::from_u64(span)) { - let new_values: Values = values.into(); - s.values.extend(new_values); - } - } - - fn event(&self, event: WasmEvent) { - let mut values = event.fields.into(); - let trace_event = TraceEvent { - name: event.metadata.name().to_owned(), - target: event.metadata.target().to_owned(), - level: event.metadata.level(), - values, - parent_id: event.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), - }; - self.trace_handler.handle_event(trace_event); - } - - fn enter(&self, span: u64) { - let id = Id::from_u64(span); - self.current_span.enter(id.clone()); - let mut span_data = self.span_data.lock(); - let start_time = Instant::now(); - if let Some(mut s) = span_data.get_mut(&id) { - s.start_time = start_time; - } - } - - fn exit(&self, span: u64) { - self.current_span.exit(); - let end_time = Instant::now(); - let mut span_data = self.span_data.lock(); - if let Some(mut s) = span_data.remove(&Id::from_u64(span)) { - s.overall_time = end_time - s.start_time + s.overall_time; - self.trace_handler.handle_span(s); - } - } -} impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 08a96bb58652a..f9f920f6f330e 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1048,7 +1048,11 @@ pub trait WasmTracing { } +#[cfg(no_std)] +/// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` +/// and pushes the information accross the runtime interface to the host pub struct PassingTracingSubsciber; +#[cfg(no_std)] impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn enabled(&self, metadata: sp_tracing::WasmMetadata) -> bool { wasm_tracing::enabled(Crossing(metadata)) diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 279e56340d570..4659b7d98b484 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -16,20 +16,17 @@ sp-std = { version = "2.0.0-rc5", path = "../std", default-features = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} tracing = { version = "0.1.13", default-features = false } log = { version = "0.4.8", optional = true } -once_cell = { version = "1.4.0", optional = true, default-features = true } [features] default = [ "std" ] with-tracing = [ "codec/derive", "codec/full", - "once_cell", ] std = [ "with-tracing", "tracing/std", "codec/std", "sp-std/std", - "once_cell/std", "log", ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index df009aefff164..92ac6adf94ddb 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -28,18 +28,20 @@ //! Additionally, we have a const: `WASM_TRACE_IDENTIFIER`, which holds a span name used //! to signal that the 'actual' span name and target should be retrieved instead from //! the associated Fields mentioned above. + #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(once_cell))] -pub mod types; +mod types; -#[cfg(not(feature = "std"))] +#[cfg(no_std)] #[macro_export] mod wasm_tracing; -#[cfg(feature = "std")] +#[cfg(not(no_std))] use tracing; -#[cfg(feature = "std")] +#[cfg(not(no_std))] pub use tracing::{ debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span, span, event, Level @@ -47,20 +49,17 @@ pub use tracing::{ use sp_std::boxed::Box; use core::sync::atomic::{AtomicBool, Ordering}; -#[cfg(any(feature = "std", feature = "with-tracing"))] -use once_cell::sync::OnceCell; - -/// Flag to signal whether to run wasm tracing -#[cfg(feature = "std")] -static WASM_TRACING_ENABLED: AtomicBool = AtomicBool::new(false); +#[cfg(all(no_std, feature = "with-tracing"))] +use core::lazy::OnceCell; pub use crate::types::{ WasmMetadata, WasmAttributes, WasmValues, WasmEvent, WasmLevel, }; -#[cfg(not(feature = "std"))] +#[cfg(no_std)] pub type Level = WasmLevel; +#[cfg(no_std)] pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; @@ -71,7 +70,7 @@ pub trait TracingSubscriber: Send + Sync { } /// Instance of the native subscriber in use -#[cfg(any(feature = "std", feature = "with-tracing"))] +#[cfg(all(no_std, feature = "with-tracing"))] static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); /// Runs given code within a tracing span, measuring it's execution time. @@ -87,6 +86,7 @@ static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new /// // some other complex code /// } /// ``` +#[cfg(any(not(no_std), not(feature = "with-tracing")))] #[macro_export] macro_rules! tracing_span { ( @@ -100,6 +100,26 @@ macro_rules! tracing_span { } } +#[cfg(all(no_std, not(feature = "with-tracing")))] +#[macro_export] +macro_rules! tracing_span { + ( + $name:expr; + $( $code:tt )* + ) => { + { + $( $code )* + } + } +} + + +#[cfg(all(no_std, not(feature = "with-tracing")))] +#[macro_export] +macro_rules! enter_span { + ( $name:expr ) => { } // no-op +} + /// Enter a span. /// /// The span will be valid, until the scope is left. @@ -109,56 +129,33 @@ macro_rules! tracing_span { /// ``` /// sp_tracing::enter_span!("test-span"); /// ``` +#[cfg(any(not(no_std), not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { ( $name:expr ) => { - let __tracing_span__ = $crate::if_tracing!( - $crate::span!($crate::Level::TRACE, $name) - ); - // let __tracing_guard__ = $crate::if_tracing!(__tracing_span__.enter()); + // FIXME: this could be clashing, make the local variable based on name to prevent that + let __tracing_span__ = $crate::span!($crate::Level::TRACE, $name); + let __tracing_guard__ = __tracing_span__.enter(); } } -/// Generates the given code if the tracing dependency is enabled. -#[macro_export] -#[cfg(feature = "std")] -macro_rules! if_tracing { - ( $if:expr ) => {{ $if }} -} - -#[macro_export] -#[cfg(not(feature = "std"))] -macro_rules! if_tracing { - ( $if:expr ) => {{}} -} - -#[cfg(feature = "std")] -pub fn wasm_tracing_enabled() -> bool { - WASM_TRACING_ENABLED.load(Ordering::Relaxed) -} - -#[cfg(feature = "std")] -pub fn set_wasm_tracing(b: bool) { - WASM_TRACING_ENABLED.store(b, Ordering::Relaxed) -} - -#[cfg(any(feature = "std", feature = "with-tracing"))] +#[cfg(all(no_std, feature = "with-tracing"))] pub fn set_tracing_subscriber(subscriber: Box) { let _ = SUBSCRIBER_INSTANCE.set(subscriber); } -#[cfg(any(feature = "std", feature = "with-tracing"))] +#[cfg(all(no_std, feature = "with-tracing"))] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { SUBSCRIBER_INSTANCE.get() } -#[cfg(not(any(feature = "std", feature = "with-tracing")))] +#[cfg(any(not(no_std), not(feature = "with-tracing")))] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { None } -#[cfg(not(any(feature = "std", feature = "with-tracing")))] -pub fn set_tracing_subscriber(subscriber: Box) { +#[cfg(any(not(no_std), not(feature = "with-tracing")))] +pub fn set_tracing_subscriber(_subscriber: Box) { unreachable!() } \ No newline at end of file From 8f541437f76b256346d0189ec2fa382fa7d29d8e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 11 Aug 2020 19:40:33 +0200 Subject: [PATCH 035/113] pass spans and events over and record them --- Cargo.lock | 15 ++-- primitives/io/Cargo.toml | 4 + primitives/io/src/lib.rs | 130 ++++++++++++++++++++------- primitives/tracing/Cargo.toml | 4 +- primitives/tracing/src/lib.rs | 4 +- primitives/tracing/src/types.rs | 153 +++++++++++++++++++++++++++----- 6 files changed, 247 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ec42b33d86c1..97331797c0892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7907,6 +7907,8 @@ dependencies = [ "sp-tracing", "sp-trie", "sp-wasm-interface", + "tracing", + "tracing-core", ] [[package]] @@ -8185,6 +8187,7 @@ dependencies = [ "parity-scale-codec", "sp-std", "tracing", + "tracing-core", ] [[package]] @@ -9145,9 +9148,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" +checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" dependencies = [ "cfg-if", "tracing-attributes", @@ -9156,9 +9159,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" +checksum = "1fe233f4227389ab7df5b32649239da7ebe0b281824b4e84b342d04d3fd8c25e" dependencies = [ "proc-macro2", "quote", @@ -9167,9 +9170,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545" dependencies = [ "lazy_static", ] diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 04ee4efd97a24..2d130c6671aef 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -28,6 +28,8 @@ sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../traci log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } +tracing = { version = "0.1.18", optional = true } +tracing-core = { version = "0.1.13", optional = true } [features] default = ["std"] @@ -42,6 +44,8 @@ std = [ "sp-runtime-interface/std", "sp-externalities", "sp-wasm-interface/std", + "tracing", + "tracing-core", "log", "futures", "parking_lot", diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index f9f920f6f330e..dafbc32b84a86 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -32,6 +32,9 @@ use sp_std::vec::Vec; #[cfg(feature = "std")] use sp_std::ops::Deref; +#[cfg(feature = "std")] +use tracing; + #[cfg(feature = "std")] use sp_core::{ crypto::Pair, @@ -1008,46 +1011,114 @@ impl PassBy for Crossing { #[runtime_interface] pub trait WasmTracing { fn enabled(&mut self, metadata: Crossing) -> bool { - todo! {} + let metadata : &tracing_core::metadata::Metadata<'static> = (&metadata.0).into(); + tracing::dispatcher::get_default(|d| { + d.enabled(metadata) + }) } fn new_span(&mut self, span: Crossing) -> u64 { - - todo! {} - // crate::get_tracing_subscriber().map(|t|{ - // t.new_span(span) - // }).unwrap_or(0) - } - fn record(&mut self, span: u64, values: Crossing) { - - todo! {} - // crate::get_tracing_subscriber().map(|t|{ - // t.record(span, values) - // }); + let span : tracing::Span = span.0.into(); + match span.id() { + Some(id) => tracing::dispatcher::get_default(|d| { + // inform dispatch that we'll keep the ID around + d.clone_span(&id).into_u64() + }), + _ => { + 0 + } + } } + fn event(&mut self, event: Crossing) { - - todo! {} - // crate::get_tracing_subscriber().map(|t|{ - // t.event(event) - // }); + event.0.emit(); } - fn enter(&mut self, span: u64) { - todo! {} - // crate::get_tracing_subscriber().map(|t|{ - // t.enter(span) - // }); + fn enter(&mut self, span: u64) { + tracing::dispatcher::get_default(|d| { + d.enter(&tracing_core::span::Id::from_u64(span)) + }); } fn exit(&mut self, span: u64) { - - todo! {} - // crate::get_tracing_subscriber().map(|t|{ - // t.exit(span) - // }); + tracing::dispatcher::get_default(|d| { + d.exit(&tracing_core::span::Id::from_u64(span)) + }); } } +// impl TracingSubscriber for ProfilingSubscriber { +// fn enabled(&self, metadata: WasmMetadata) -> bool { +// let level = metadata.level(); +// let target = metadata.target(); +// if self.check_target(target, &level) { +// log::debug!(target: "tracing", "Enabled target: {}, level: {}", target, level); +// true +// } else { +// log::debug!(target: "tracing", "Disabled target: {}, level: {}", target, level); +// false +// } +// } + +// fn new_span(&self, attrs: WasmAttributes) -> u64 { +// let id = self.next_id.fetch_add(1, Ordering::Relaxed); +// let values = attrs.fields.into(); +// let span_datum = SpanDatum { +// id: Id::from_u64(id.clone()), +// parent_id: attrs.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), +// name: String::from_utf8(attrs.metadata.name).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), +// target: String::from_utf8(attrs.metadata.target).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), +// level: attrs.metadata.level.into(), +// line: attrs.metadata.line, +// start_time: Instant::now(), +// overall_time: ZERO_DURATION, +// values, +// }; +// self.span_data.lock().insert(span_datum.id.clone(), span_datum); +// id +// } + +// fn record(&self, span: u64, values: WasmValues) { +// let mut span_data = self.span_data.lock(); +// if let Some(mut s) = span_data.get_mut(&Id::from_u64(span)) { +// let new_values: Values = values.into(); +// s.values.extend(new_values); +// } +// } + +// fn event(&self, event: WasmEvent) { +// let mut values = event.fields.into(); +// let trace_event = TraceEvent { +// name: event.metadata.name().to_owned(), +// target: event.metadata.target().to_owned(), +// level: event.metadata.level(), +// values, +// parent_id: event.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), +// }; +// self.trace_handler.handle_event(trace_event); +// } + +// fn enter(&self, span: u64) { +// let id = Id::from_u64(span); +// self.current_span.enter(id.clone()); +// let mut span_data = self.span_data.lock(); +// let start_time = Instant::now(); +// if let Some(mut s) = span_data.get_mut(&id) { +// s.start_time = start_time; +// } +// } + +// fn exit(&self, span: u64) { +// self.current_span.exit(); +// let end_time = Instant::now(); +// let mut span_data = self.span_data.lock(); +// if let Some(mut s) = span_data.remove(&Id::from_u64(span)) { +// s.overall_time = end_time - s.start_time + s.overall_time; +// self.trace_handler.handle_span(s); +// } +// } +// } + + #[cfg(no_std)] /// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` /// and pushes the information accross the runtime interface to the host @@ -1060,9 +1131,6 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn new_span(&self, attrs: sp_tracing::WasmAttributes) -> u64 { wasm_tracing::new_span(Crossing(attrs)) } - fn record(&self, span: u64, values: sp_tracing::WasmValues) { - wasm_tracing::record(span, Crossing(values)) - } fn event(&self, event: sp_tracing::WasmEvent) { wasm_tracing::event(Crossing(event)) } diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 4659b7d98b484..d6a6e14f34783 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -14,7 +14,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-std = { version = "2.0.0-rc5", path = "../std", default-features = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} -tracing = { version = "0.1.13", default-features = false } +tracing = { version = "0.1.18", default-features = false } +tracing-core = { version = "0.1.13", optional = true } log = { version = "0.4.8", optional = true } [features] @@ -26,6 +27,7 @@ with-tracing = [ std = [ "with-tracing", "tracing/std", + "tracing-core", "codec/std", "sp-std/std", "log", diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 92ac6adf94ddb..d2cfcc12a9e86 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -150,12 +150,12 @@ pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { } -#[cfg(any(not(no_std), not(feature = "with-tracing")))] +#[cfg(all(no_std, not(feature = "with-tracing")))] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { None } -#[cfg(any(not(no_std), not(feature = "with-tracing")))] +#[cfg(all(no_std, not(feature = "with-tracing")))] pub fn set_tracing_subscriber(_subscriber: Box) { unreachable!() } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index a09db77875e65..30f449b795fd2 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -15,12 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +use core::fmt::Debug; use sp_std::{ vec::Vec }; use codec::{Encode, Decode}; -#[derive(Clone, Encode, Decode)] +#[derive(Clone, Encode, Decode, Debug)] pub enum WasmLevel { ERROR, WARN, @@ -40,9 +41,11 @@ pub enum WasmFieldValue { } pub type WasmFields = Vec>; -pub type WasmValues = Vec<(Vec, WasmFieldValue)>; -#[derive(Encode, Decode)] +#[derive(Encode, Decode, Debug)] +pub struct WasmValues(Vec<(Vec, WasmFieldValue)>); + +#[derive(Encode, Decode, Debug)] pub struct WasmMetadata { pub name: Vec, pub target: Vec, @@ -54,14 +57,14 @@ pub struct WasmMetadata { pub fields: WasmFields, } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, Debug)] pub struct WasmAttributes { pub parent_id: Option, pub fields: WasmValues, pub metadata: WasmMetadata, } -#[derive(Encode, Decode)] +#[derive(Encode, Decode, Debug)] pub struct WasmEvent { pub parent_id: Option, pub metadata: WasmMetadata, @@ -72,30 +75,134 @@ pub struct WasmEvent { // #[derive(Encode, Decode)] // pub struct WasmRecord; + #[cfg(feature = "std")] -impl From for tracing::Level { - fn from(w: WasmLevel) -> Self { - match w { - WasmLevel::ERROR => tracing::Level::ERROR, - WasmLevel::WARN => tracing::Level::WARN, - WasmLevel::INFO => tracing::Level::INFO, - WasmLevel::DEBUG => tracing::Level::DEBUG, - WasmLevel::TRACE => tracing::Level::TRACE, - } +mod std_features { + + use tracing_core::callsite; + use tracing; + + pub struct WasmCallsite; + impl callsite::Callsite for WasmCallsite { + fn set_interest(&self, _: tracing_core::Interest) { unimplemented!() } + fn metadata(&self) -> &tracing_core::Metadata { unimplemented!() } } -} + static CALLSITE: WasmCallsite = WasmCallsite; + static WASM_TRACING_NAME: &'static str = "wasm_tracing"; + static GENERIC_FIELDS: &'static [&'static str] = &["target", "name", "file", "line", "module_path", "params"]; -#[cfg(feature = "std")] -impl WasmMetadata { - pub fn target(&self) -> &str { - std::str::from_utf8(&self.target).unwrap() + static SPAN_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::ERROR, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::WARN, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + static SPAN_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::INFO, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::DEBUG, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::TRACE, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static EVENT_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::ERROR, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::WARN, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::INFO, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::DEBUG, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::TRACE, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + impl From<&crate::WasmMetadata> for &'static tracing_core::Metadata<'static> { + fn from(wm: &crate::WasmMetadata) -> &'static tracing_core::Metadata<'static> { + match (&wm.level, wm.is_span) { + (&crate::WasmLevel::ERROR, true) => &SPAN_ERROR_METADATA, + (&crate::WasmLevel::WARN, true) => &SPAN_WARN_METADATA, + (&crate::WasmLevel::INFO, true) => &SPAN_INFO_METADATA, + (&crate::WasmLevel::DEBUG, true) => &SPAN_DEBUG_METADATA, + (&crate::WasmLevel::TRACE, true) => &SPAN_TRACE_METADATA, + (&crate::WasmLevel::ERROR, false) => &EVENT_ERROR_METADATA, + (&crate::WasmLevel::WARN, false) => &EVENT_WARN_METADATA, + (&crate::WasmLevel::INFO, false) => &EVENT_INFO_METADATA, + (&crate::WasmLevel::DEBUG, false) => &EVENT_DEBUG_METADATA, + (&crate::WasmLevel::TRACE, false) => &EVENT_TRACE_METADATA, + } + } } - pub fn name(&self) -> &str { - std::str::from_utf8(&self.name).unwrap() + impl From for tracing::Span { + fn from(a: crate::WasmAttributes) -> tracing::Span { + let name = std::str::from_utf8(&a.metadata.name).unwrap_or_default(); + let target = std::str::from_utf8(&a.metadata.target).unwrap_or_default(); + let file = std::str::from_utf8(&a.metadata.file).unwrap_or_default(); + let line = a.metadata.line; + let module_path = std::str::from_utf8(&a.metadata.module_path).unwrap_or_default(); + let params = a.fields; + let metadata : &tracing_core::metadata::Metadata<'static> = (&a.metadata).into(); + + tracing::span::Span::child_of( + a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + &metadata, + &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } + ) + } } - pub fn level(&self) -> tracing::Level { - self.level.clone().into() + impl crate::WasmEvent { + pub fn emit(self: crate::WasmEvent) { + let name = std::str::from_utf8(&self.metadata.name).unwrap_or_default(); + let target = std::str::from_utf8(&self.metadata.target).unwrap_or_default(); + let file = std::str::from_utf8(&self.metadata.file).unwrap_or_default(); + let line = self.metadata.line; + let module_path = std::str::from_utf8(&self.metadata.module_path).unwrap_or_default(); + let params = self.fields; + let metadata : &tracing_core::metadata::Metadata<'static> = (&self.metadata).into(); + + tracing_core::Event::child_of( + self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + &metadata, + &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } + ) + } } } + +#[cfg(feature = "std")] +pub use std_features::*; \ No newline at end of file From 94b16d0b93434da2d2ff0e847c0c06ea356b9674 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 12 Aug 2020 13:01:37 +0200 Subject: [PATCH 036/113] reactivate previous code and cleanup --- client/executor/runtime-test/src/lib.rs | 4 +- client/executor/src/integration_tests/mod.rs | 188 +++++++++---------- primitives/io/src/lib.rs | 76 +------- primitives/runtime-interface/test/Cargo.toml | 1 + primitives/runtime-interface/test/src/lib.rs | 45 ++++- 5 files changed, 141 insertions(+), 173 deletions(-) diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index f56030b19b277..bf80c2aaa7d5b 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -17,7 +17,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}}; @@ -256,7 +256,7 @@ sp_core::wasm_export_functions! { 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) } diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 546b037aa556a..40496d2eabe7a 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -659,98 +659,98 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) { #[test_case(WasmExecutionMethod::Interpreted)] fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { - // - // use std::sync::{Arc, Mutex}; - // use sc_tracing::SpanDatum; - // - // struct TestTraceHandler(Arc>>); - // - // impl sc_tracing::TraceHandler for TestTraceHandler { - // fn handle_span(&self, sd: SpanDatum) { - // self.0.lock().unwrap().push(sd); - // } - // } - // - // 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; - // assert_eq!(span_datum.target, "integration_test_span_target"); - // assert_eq!(span_datum.name, "integration_test_span_name"); - // assert_eq!(values.bool_values.get("wasm").unwrap(), &true); - // assert_eq!(values.bool_values.get("is_valid_trace").unwrap(), &true); + + use std::sync::{Arc, Mutex}; + use sc_tracing::SpanDatum; + + struct TestTraceHandler(Arc>>); + + impl sc_tracing::TraceHandler for TestTraceHandler { + fn handle_span(&self, sd: SpanDatum) { + self.0.lock().unwrap().push(sd); + } + } + + 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; + assert_eq!(span_datum.target, "integration_test_span_target"); + assert_eq!(span_datum.name, "integration_test_span_name"); + assert_eq!(values.bool_values.get("wasm").unwrap(), &true); + assert_eq!(values.bool_values.get("is_valid_trace").unwrap(), &true); } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index dafbc32b84a86..69f82ae86a593 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1045,80 +1045,6 @@ pub trait WasmTracing { } } - -// impl TracingSubscriber for ProfilingSubscriber { -// fn enabled(&self, metadata: WasmMetadata) -> bool { -// let level = metadata.level(); -// let target = metadata.target(); -// if self.check_target(target, &level) { -// log::debug!(target: "tracing", "Enabled target: {}, level: {}", target, level); -// true -// } else { -// log::debug!(target: "tracing", "Disabled target: {}, level: {}", target, level); -// false -// } -// } - -// fn new_span(&self, attrs: WasmAttributes) -> u64 { -// let id = self.next_id.fetch_add(1, Ordering::Relaxed); -// let values = attrs.fields.into(); -// let span_datum = SpanDatum { -// id: Id::from_u64(id.clone()), -// parent_id: attrs.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), -// name: String::from_utf8(attrs.metadata.name).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), -// target: String::from_utf8(attrs.metadata.target).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()), -// level: attrs.metadata.level.into(), -// line: attrs.metadata.line, -// start_time: Instant::now(), -// overall_time: ZERO_DURATION, -// values, -// }; -// self.span_data.lock().insert(span_datum.id.clone(), span_datum); -// id -// } - -// fn record(&self, span: u64, values: WasmValues) { -// let mut span_data = self.span_data.lock(); -// if let Some(mut s) = span_data.get_mut(&Id::from_u64(span)) { -// let new_values: Values = values.into(); -// s.values.extend(new_values); -// } -// } - -// fn event(&self, event: WasmEvent) { -// let mut values = event.fields.into(); -// let trace_event = TraceEvent { -// name: event.metadata.name().to_owned(), -// target: event.metadata.target().to_owned(), -// level: event.metadata.level(), -// values, -// parent_id: event.parent_id.map(|id| Id::from_u64(id)).or_else(|| self.current_span.id()), -// }; -// self.trace_handler.handle_event(trace_event); -// } - -// fn enter(&self, span: u64) { -// let id = Id::from_u64(span); -// self.current_span.enter(id.clone()); -// let mut span_data = self.span_data.lock(); -// let start_time = Instant::now(); -// if let Some(mut s) = span_data.get_mut(&id) { -// s.start_time = start_time; -// } -// } - -// fn exit(&self, span: u64) { -// self.current_span.exit(); -// let end_time = Instant::now(); -// let mut span_data = self.span_data.lock(); -// if let Some(mut s) = span_data.remove(&Id::from_u64(span)) { -// s.overall_time = end_time - s.start_time + s.overall_time; -// self.trace_handler.handle_span(s); -// } -// } -// } - - #[cfg(no_std)] /// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` /// and pushes the information accross the runtime interface to the host @@ -1288,7 +1214,7 @@ pub type SubstrateHostFunctions = ( storage::HostFunctions, default_child_storage::HostFunctions, misc::HostFunctions, - // wasm_tracing::HostFunctions, + wasm_tracing::HostFunctions, offchain::HostFunctions, crypto::HostFunctions, hashing::HostFunctions, diff --git a/primitives/runtime-interface/test/Cargo.toml b/primitives/runtime-interface/test/Cargo.toml index af4490a0d7c32..5e2ea5a62349b 100644 --- a/primitives/runtime-interface/test/Cargo.toml +++ b/primitives/runtime-interface/test/Cargo.toml @@ -20,3 +20,4 @@ sp-state-machine = { version = "0.8.0-rc5", path = "../../../primitives/state-ma sp-runtime = { version = "2.0.0-rc5", path = "../../runtime" } sp-core = { version = "2.0.0-rc5", path = "../../core" } sp-io = { version = "2.0.0-rc5", path = "../../io" } +tracing = "0.1.13" diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index 619ffd17a171c..a56ad6339301f 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -18,8 +18,6 @@ //! Integration tests for runtime interface primitives #![cfg(test)] -#![cfg(test)] - use sp_runtime_interface::*; use sp_runtime_interface_test_wasm::{wasm_binary_unwrap, test_api::HostFunctions}; @@ -155,3 +153,46 @@ fn test_versionining_with_new_host_works() { ); } +#[test] +fn test_tracing() { + use tracing::span::Id as SpanId; + + #[derive(Clone)] + struct TracingSubscriber(Arc>); + + #[derive(Default)] + struct Inner { + spans: HashSet<&'static str>, + } + + impl tracing::subscriber::Subscriber for TracingSubscriber { + fn enabled(&self, _: &tracing::Metadata) -> bool { true } + + fn new_span(&self, span: &tracing::span::Attributes) -> tracing::Id { + let mut inner = self.0.lock().unwrap(); + let id = SpanId::from_u64((inner.spans.len() + 1) as _); + inner.spans.insert(span.metadata().name()); + id + } + + fn record(&self, _: &SpanId, _: &tracing::span::Record) {} + + fn record_follows_from(&self, _: &SpanId, _: &SpanId) {} + + fn event(&self, _: &tracing::Event) {} + + fn enter(&self, _: &SpanId) {} + + fn exit(&self, _: &SpanId) {} + } + + let subscriber = TracingSubscriber(Default::default()); + let _guard = tracing::subscriber::set_default(subscriber.clone()); + + // Call some method to generate a trace + call_wasm_method::(&wasm_binary_unwrap()[..], "test_return_data"); + + let inner = subscriber.0.lock().unwrap(); + assert!(inner.spans.contains("return_input_version_1")); + assert!(inner.spans.contains("ext_test_api_return_input_version_1")); +} \ No newline at end of file From 6b2754b75a4a5327bb0814a77c582e3153f67330 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 12 Aug 2020 13:03:56 +0200 Subject: [PATCH 037/113] further cleaning up --- client/executor/runtime-test/src/lib.rs | 2 +- client/executor/src/integration_tests/mod.rs | 36 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index bf80c2aaa7d5b..a80ee1d6ba40f 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -17,7 +17,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}, wasm_tracing + crypto::{ed25519_verify, sr25519_verify}, wasm_tracing, }; #[cfg(not(feature = "std"))] use sp_runtime::{print, traits::{BlakeTwo256, Hash}}; diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 40496d2eabe7a..55acd0bcbc24c 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -659,40 +659,40 @@ fn parallel_execution(wasm_method: WasmExecutionMethod) { #[test_case(WasmExecutionMethod::Interpreted)] fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { - + use std::sync::{Arc, Mutex}; use sc_tracing::SpanDatum; - + struct TestTraceHandler(Arc>>); - + impl sc_tracing::TraceHandler for TestTraceHandler { fn handle_span(&self, sd: SpanDatum) { self.0.lock().unwrap().push(sd); } } - + 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 @@ -709,7 +709,7 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { 0u64.encode(), span_id ); - + call_in_wasm( "test_exit_span", &span_id.encode(), @@ -719,34 +719,34 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { // 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; assert_eq!(span_datum.target, "integration_test_span_target"); From dad8480e76390935f14d308757ed345332f2e1bb Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 12 Aug 2020 14:32:00 +0200 Subject: [PATCH 038/113] extend the span macros, activate through executive --- Cargo.lock | 2 +- bin/node/runtime/Cargo.toml | 3 +- client/service/src/builder.rs | 1 - client/transaction-pool/src/api.rs | 21 ++-- frame/executive/Cargo.toml | 3 + frame/executive/src/lib.rs | 56 +++++---- frame/support/src/wasm_tracing.rs | 108 ------------------ primitives/io/Cargo.toml | 5 + primitives/io/src/lib.rs | 10 ++ .../bare_function_interface.rs | 2 +- .../host_function_interface.rs | 2 +- primitives/tracing/src/lib.rs | 50 +++++--- 12 files changed, 102 insertions(+), 161 deletions(-) delete mode 100644 frame/support/src/wasm_tracing.rs diff --git a/Cargo.lock b/Cargo.lock index 97331797c0892..618afe6f90dc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3789,7 +3789,6 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", - "sp-tracing", "sp-transaction-pool", "sp-version", "static_assertions", @@ -8049,6 +8048,7 @@ dependencies = [ "sp-runtime-interface-test-wasm", "sp-runtime-interface-test-wasm-deprecated", "sp-state-machine", + "tracing", ] [[package]] diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 3407bee8f693d..4166d10cf1b6a 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -36,7 +36,6 @@ sp-keyring = { version = "2.0.0-rc5", optional = true, path = "../../../primitiv sp-session = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/session" } sp-transaction-pool = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/transaction-pool" } sp-version = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/version" } -sp-tracing = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/tracing" } # frame dependencies frame-executive = { version = "2.0.0-rc5", default-features = false, path = "../../../frame/executive" } @@ -89,7 +88,7 @@ sp-io = { version = "2.0.0-rc5", path = "../../../primitives/io" } [features] default = ["std"] -with-tracing = [ "sp-tracing/with-tracing" ] +with-tracing = [ "frame-executive/with-tracing" ] std = [ "sp-authority-discovery/std", "pallet-authority-discovery/std", diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 6bebd2b84bfea..eedc4582299d3 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -565,7 +565,6 @@ pub fn spawn_tasks( let subscriber = sc_tracing::ProfilingSubscriber::new( config.tracing_receiver, tracing_targets ); - sp_tracing::set_tracing_subscriber(Box::new(subscriber.clone())); match tracing::subscriber::set_global_default(subscriber) { Ok(_) => (), Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index c6671fd5bd7f0..6296dcc21c569 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -168,21 +168,24 @@ where Client::Api: TaggedTransactionQueue, sp_api::ApiErrorFor: Send + std::fmt::Display, { - sp_tracing::enter_span!("validate_transaction"); + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "validate_transaction"); let runtime_api = client.runtime_api(); - let has_v2 = sp_tracing::tracing_span! { "check_version"; + let has_v2 = sp_tracing::within_span! { sp_tracing::Level::TRACE, "check_version"; runtime_api .has_api_with::, _>(&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) - }; + 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())) } diff --git a/frame/executive/Cargo.toml b/frame/executive/Cargo.toml index ea123bd6e7fb8..51adffe916bf2 100644 --- a/frame/executive/Cargo.toml +++ b/frame/executive/Cargo.toml @@ -32,6 +32,9 @@ sp-version = { version = "2.0.0-rc5", path = "../../primitives/version" } [features] default = ["std"] +with-tracing = [ + "sp-tracing/with-tracing" +] std = [ "codec/std", "frame-support/std", diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 24dccf8b0b4a4..4f085f512ca37 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -207,6 +207,7 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block"); let digests = Self::extract_pre_digest(&header); Self::initialize_block_impl( header.number(), @@ -270,6 +271,7 @@ where } fn initial_checks(block: &Block) { + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "initial_checks"); let header = block.header(); // Check that `parent_hash` is correct. @@ -288,23 +290,28 @@ where /// Actually execute all transitions for `block`. pub fn execute_block(block: Block) { - Self::initialize_block(block.header()); + sp_io::init_tracing(); + sp_tracing::within_span! { + sp_tracing::info_span!(target: "executive", "execute_block", ?block); + { + Self::initialize_block(block.header()); - // any initial checks - Self::initial_checks(&block); + // any initial checks + Self::initial_checks(&block); - let signature_batching = sp_runtime::SignatureBatching::start(); + let signature_batching = sp_runtime::SignatureBatching::start(); - // execute extrinsics - let (header, extrinsics) = block.deconstruct(); - Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number()); + // execute extrinsics + let (header, extrinsics) = block.deconstruct(); + Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number()); - if !signature_batching.verify() { - panic!("Signature verification failed."); - } + if !signature_batching.verify() { + panic!("Signature verification failed."); + } - // any final checks - Self::final_checks(&header); + // any final checks + Self::final_checks(&header); + } }; } /// Execute given extrinsics and take care of post-extrinsics book-keeping. @@ -320,6 +327,7 @@ where /// Finalize the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalize_block() -> System::Header { + sp_tracing::enter_span!( sp_tracing::Level::TRACE, "finalize_block" ); >::note_finished_extrinsics(); let block_number = >::block_number(); as OnFinalize>::on_finalize(block_number); @@ -335,6 +343,7 @@ where /// This doesn't attempt to validate anything regarding the block, but it builds a list of uxt /// hashes. pub fn apply_extrinsic(uxt: Block::Extrinsic) -> ApplyExtrinsicResult { + sp_io::init_tracing(); let encoded = uxt.encode(); let encoded_len = encoded.len(); Self::apply_extrinsic_with_len(uxt, encoded_len, Some(encoded)) @@ -355,6 +364,7 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "apply_extrinsic"); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; @@ -377,6 +387,7 @@ where } fn final_checks(header: &System::Header) { + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks"); // remove temporaries let new_header = >::finalize(); @@ -406,20 +417,21 @@ where source: TransactionSource, uxt: Block::Extrinsic, ) -> TransactionValidity { - use sp_tracing::tracing_span; - - sp_tracing::enter_span!("validate_transaction"); + use sp_tracing::within_span; - let encoded_len = tracing_span!{ "using_encoded"; uxt.using_encoded(|d| d.len()) }; + within_span!{ sp_tracing::Level::TRACE, "validate_transaction"; { + + let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; - let xt = tracing_span!{ "check"; uxt.check(&Default::default())? }; + let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; - let dispatch_info = tracing_span!{ "dispatch_info"; xt.get_dispatch_info() }; + let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; - tracing_span! { - "validate"; - xt.validate::(source, &dispatch_info, encoded_len) - } + within_span! { + sp_tracing::Level::TRACE, "validate"; + xt.validate::(source, &dispatch_info, encoded_len) + } + } } } /// Start an offchain worker and generate extrinsics. diff --git a/frame/support/src/wasm_tracing.rs b/frame/support/src/wasm_tracing.rs deleted file mode 100644 index 73e4fa65a8181..0000000000000 --- a/frame/support/src/wasm_tracing.rs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! # To allow tracing in WASM execution environment -//! -//! Facilitated by `sp_io::wasm_tracing` - -// static mut has potential for data race conditions. -// For current use-case this is not an issue, must only be used in wasm -#[cfg(not(feature = "std"))] -static mut WASM_TRACING_ENABLED: bool = true; - -/// Indicates whether to run traces in wasm -#[cfg(not(feature = "std"))] -pub fn wasm_tracing_enabled() -> bool { - unsafe { WASM_TRACING_ENABLED } -} - -/// Disable wasm traces -#[cfg(not(feature = "std"))] -pub fn disable_wasm_tracing() { - unsafe { WASM_TRACING_ENABLED = false } -} - -/// This holds a tracing span id and is to signal on drop that a tracing span has exited. -/// It must be bound to a named variable eg. `_span_guard`. -#[cfg(not(feature = "std"))] -pub struct TracingSpanGuard(Option); - -#[cfg(not(feature = "std"))] -impl TracingSpanGuard { - pub fn new(span: Option) -> Self { - Self(span) - } -} - -#[cfg(not(feature = "std"))] -impl Drop for TracingSpanGuard { - fn drop(&mut self) { - if let Some(id) = self.0.take() { - crate::sp_tracing::interface::wasm_tracing::exit(id); - } - } -} - -/// Enters a tracing span, via [`sp_tracing::proxy`] measuring execution time -/// until exit from the current scope. -/// -/// It's also possible to directly call the functions `enter_span` and `exit_span` -/// in `sp_io::wasm_tracing` if more fine-grained control of span duration is required. -/// -/// # Example -/// -/// ``` -/// frame_support::enter_span!("fn_name"); -/// ``` -#[macro_export] -macro_rules! enter_span { - ( $name:expr, $values:expr ) => { - #[cfg(not(feature = "std"))] - let __span_id__ = if $crate::wasm_tracing::wasm_tracing_enabled() { - use $crate::sp_std::prelude::*; - let metadata = $crate::sp_tracing::types::WasmMetadata { - name: $name.bytes().collect::>(), - target: module_path!().bytes().collect::>(), - level: $crate::sp_tracing::types::WasmLevel::INFO, - file: file!().bytes().collect::>(), - line: line!(), - module_path: module_path!().bytes().collect::>(), - is_span: true, - fields: Vec::new(), - }; - let attrs = $crate::sp_tracing::types::WasmAttributes{ - parent_id: None, - fields: $values, - metadata, - }; - let id = $crate::sp_tracing::interface::wasm_tracing::new_span( - attrs - ); - if id == 0 { - // $crate::wasm_tracing::disable_wasm_tracing(); - $crate::wasm_tracing::TracingSpanGuard::new(None) - } else { - $crate::sp_tracing::interface::wasm_tracing::enter(id); - $crate::wasm_tracing::TracingSpanGuard::new(Some(id)) - } - } else { - $crate::wasm_tracing::TracingSpanGuard::new(None) - }; - #[cfg(feature = "std")] - $crate::sp_tracing::enter_span!($name); - } -} - diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 2d130c6671aef..324d1c7b1e2f8 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -44,6 +44,7 @@ std = [ "sp-runtime-interface/std", "sp-externalities", "sp-wasm-interface/std", + "sp-tracing/std", "tracing", "tracing-core", "log", @@ -51,6 +52,10 @@ std = [ "parking_lot", ] +with-tracing = [ + "sp-tracing/with-tracing" +] + # These two features are used for `no_std` builds for the environments which already provides # `#[panic_handler]`, `#[alloc_error_handler]` and `#[global_allocator]`. # diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 69f82ae86a593..755e8978b579a 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1068,6 +1068,16 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { } } +#[cfg(all(no_std, feature="with-tracing"))] +/// Initialize tracing of sp_tracing +pub fn init_tracing() { + sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber())); +} + +#[cfg(not(all(no_std, feature="with-tracing")))] +/// Initialize tracing of sp_tracing – noop +pub fn init_tracing() { } + /// Wasm-only interface that provides functions for interacting with the sandbox. #[runtime_interface(wasm_only)] pub trait Sandbox { diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index 6760e9656113a..29b375dd0509d 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -174,7 +174,7 @@ fn function_std_impl( #[cfg(feature = "std")] #( #attrs )* fn #function_name( #( #args, )* ) #return_value { - #crate_::sp_tracing::enter_span!(#function_name_str); + #crate_::sp_tracing::enter_span!(#crate_::sp_tracing::Level::Trace, #function_name_str); #call_to_trait } } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 721eed649c25d..7b44ae1ef2628 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -227,7 +227,7 @@ fn generate_host_function_implementation( __function_context__: &mut dyn #crate_::sp_wasm_interface::FunctionContext, args: &mut dyn Iterator, ) -> std::result::Result, String> { - #crate_::sp_tracing::enter_span!(#name); + #crate_::sp_tracing::enter_span!(#crate_::sp_tracing::Level::Trace, #name); #( #wasm_to_ffi_values )* #( #ffi_to_host_values )* #host_function_call diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index d2cfcc12a9e86..36b6bf0adf299 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -17,7 +17,7 @@ //! Substrate tracing primitives and macros. //! -//! To trace functions or invidual code in Substrate, this crate provides [`tracing_span`] +//! To trace functions or invidual code in Substrate, this crate provides [`within_span`] //! and [`enter_span`]. See the individual docs for how to use these macros. //! //! Note that to allow traces from wasm execution environment there are @@ -47,8 +47,8 @@ pub use tracing::{ span, event, Level }; +#[cfg(all(no_std, feature = "with-tracing"))] use sp_std::boxed::Box; -use core::sync::atomic::{AtomicBool, Ordering}; #[cfg(all(no_std, feature = "with-tracing"))] use core::lazy::OnceCell; @@ -80,7 +80,7 @@ static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new /// # Example /// /// ``` -/// sp_tracing::tracing_span! { +/// sp_tracing::within_span! { /// "test-span"; /// 1 + 1; /// // some other complex code @@ -88,35 +88,50 @@ static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new /// ``` #[cfg(any(not(no_std), not(feature = "with-tracing")))] #[macro_export] -macro_rules! tracing_span { +macro_rules! within_span { ( - $name:expr; + $span:expr; $( $code:tt )* ) => { { - $crate::enter_span!($name); + $crate::enter_span!($span); $( $code )* } - } + }; + ( + $lvl:expr, + $name:expr; + $( $code:tt )* + ) => { + { + $crate::within_span!($crate::span!($crate::Level::TRACE, $name); $( $code )*) + } + }; } #[cfg(all(no_std, not(feature = "with-tracing")))] #[macro_export] -macro_rules! tracing_span { +macro_rules! within_span { + ( + $span:stmt; + $( $code:tt )* + ) => { + $( $code )* + }; ( + $lvl:expr, $name:expr; $( $code:tt )* ) => { - { - $( $code )* - } - } + $( $code )* + }; } #[cfg(all(no_std, not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { + ( $lvl:expr, $name:expr ) => { }, ( $name:expr ) => { } // no-op } @@ -132,11 +147,14 @@ macro_rules! enter_span { #[cfg(any(not(no_std), not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { - ( $name:expr ) => { + ( $span:expr ) => { // FIXME: this could be clashing, make the local variable based on name to prevent that - let __tracing_span__ = $crate::span!($crate::Level::TRACE, $name); - let __tracing_guard__ = __tracing_span__.enter(); - } + let __within_span__ = $span; + let __tracing_guard__ = __within_span__.enter(); + }; + ( $lvl:expr, $name:expr ) => { + $crate::enter_span!($crate::span!($crate::Level::TRACE, $name)) + }; } #[cfg(all(no_std, feature = "with-tracing"))] From 54d62f7a2d7245ed4fb425300c321a5eb8b5eb20 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 12 Aug 2020 14:38:45 +0200 Subject: [PATCH 039/113] tracking the actual extrinsic, too --- frame/executive/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 4f085f512ca37..76e7354ab5da1 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -364,7 +364,9 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { - sp_tracing::enter_span!(sp_tracing::Level::TRACE, "apply_extrinsic"); + sp_tracing::enter_span!( + sp_tracing::trace_span!(target: "executive", "apply_extrinsic", extrinsic=?uxt) + ); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; From e5e4c50d38a22585fd20eba762a78d736c0c9398 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 12 Aug 2020 14:48:44 +0200 Subject: [PATCH 040/113] style --- primitives/tracing/src/wasm_tracing.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 5a31f79eef8c3..77734a3cba63a 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -69,7 +69,7 @@ mod inner { use core::{ module_path, concat, format_args, file, line, }; - use crate::{WasmMetadata}; + use crate::WasmMetadata; // just a simplistic holder for span and entered spans // that exits on drop @@ -153,7 +153,7 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; + use $crate::{ WasmMetadata, WasmEvent, WasmValue, WasmValueSet }; let metadata = WasmMetadata { name: concat!( "event ", @@ -367,7 +367,7 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; + use $crate::{ WasmMetadata, WasmAttributes, WasmValue, WasmValueSet }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), file: file!().as_bytes().to_vec(), From f368f1f607391eb5ae8e0ba34edc1639d6385b0a Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 13 Aug 2020 17:25:27 +0200 Subject: [PATCH 041/113] fixing tests --- Cargo.lock | 1 + primitives/tracing/Cargo.toml | 2 + primitives/tracing/src/lib.rs | 60 +++++++---- primitives/tracing/src/types.rs | 8 +- primitives/tracing/src/wasm_tracing.rs | 142 ++++++++++++++----------- 5 files changed, 125 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 154cec61145fa..8c8ea39a53195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8181,6 +8181,7 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", + "once_cell", "parity-scale-codec", "sp-std", "tracing", diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index d6a6e14f34783..5f80ead0e01d8 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -17,12 +17,14 @@ codec = { version = "1.3.1", package = "parity-scale-codec", default-features = tracing = { version = "0.1.18", default-features = false } tracing-core = { version = "0.1.13", optional = true } log = { version = "0.4.8", optional = true } +once_cell = { version = "1.4.0", optional = true} [features] default = [ "std" ] with-tracing = [ "codec/derive", "codec/full", + "once_cell", ] std = [ "with-tracing", diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 36b6bf0adf299..6385d39f8b8f1 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,38 +30,40 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(not(feature = "std"), feature(once_cell))] mod types; -#[cfg(no_std)] +#[cfg(not(feature = "std"))] #[macro_export] mod wasm_tracing; -#[cfg(not(no_std))] +#[cfg(not(feature = "std"))] +pub use wasm_tracing::Span; + +#[cfg(feature = "std")] use tracing; -#[cfg(not(no_std))] +#[cfg(feature = "std")] pub use tracing::{ debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span, - span, event, Level + span, event, Level, }; -#[cfg(all(no_std, feature = "with-tracing"))] +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] use sp_std::boxed::Box; -#[cfg(all(no_std, feature = "with-tracing"))] -use core::lazy::OnceCell; +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] +use once_cell::sync::OnceCell; pub use crate::types::{ WasmMetadata, WasmAttributes, WasmValues, WasmEvent, WasmLevel, }; -#[cfg(no_std)] +#[cfg(not(feature = "std"))] pub type Level = WasmLevel; -#[cfg(no_std)] +#[cfg(not(feature = "std"))] pub trait TracingSubscriber: Send + Sync { - fn enabled(&self, metadata: WasmMetadata) -> bool; + fn enabled(&self, metadata: &WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; fn record(&self, span: u64, values: WasmValues); fn event(&self, event: WasmEvent); @@ -70,23 +72,31 @@ pub trait TracingSubscriber: Send + Sync { } /// Instance of the native subscriber in use -#[cfg(all(no_std, feature = "with-tracing"))] +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); /// Runs given code within a tracing span, measuring it's execution time. /// -/// If tracing is not enabled, the code is still executed. +/// If tracing is not enabled, the code is still executed. Pass in level and name before followed +/// by `;` and the code to execute, or use any valid `sp_tracing::Span`. /// /// # Example /// /// ``` /// sp_tracing::within_span! { +/// sp_tracing::Level::TRACE, /// "test-span"; /// 1 + 1; /// // some other complex code /// } +/// +/// sp_tracing::within_span! { +/// sp_tracing::span!(sp_tracing::Level::WARN, "warn-span", you_can_pass="any params"); +/// 1 + 1; +/// // some other complex code +/// } /// ``` -#[cfg(any(not(no_std), not(feature = "with-tracing")))] +#[cfg(any(feature = "std", not(feature = "with-tracing")))] #[macro_export] macro_rules! within_span { ( @@ -109,7 +119,7 @@ macro_rules! within_span { }; } -#[cfg(all(no_std, not(feature = "with-tracing")))] +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] #[macro_export] macro_rules! within_span { ( @@ -128,7 +138,8 @@ macro_rules! within_span { } -#[cfg(all(no_std, not(feature = "with-tracing")))] +/// Enter a span - noop for `no_std` without `with-tracing` +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { ( $lvl:expr, $name:expr ) => { }, @@ -137,14 +148,17 @@ macro_rules! enter_span { /// Enter a span. /// -/// The span will be valid, until the scope is left. +/// The span will be valid, until the scope is left. Use either level and name +/// or pass in any valid `sp_tracing::Span` for extended usage. /// /// # Example /// /// ``` -/// sp_tracing::enter_span!("test-span"); +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); +/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); +/// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); /// ``` -#[cfg(any(not(no_std), not(feature = "with-tracing")))] +#[cfg(any(feature = "std", not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { ( $span:expr ) => { @@ -157,23 +171,23 @@ macro_rules! enter_span { }; } -#[cfg(all(no_std, feature = "with-tracing"))] +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] pub fn set_tracing_subscriber(subscriber: Box) { let _ = SUBSCRIBER_INSTANCE.set(subscriber); } -#[cfg(all(no_std, feature = "with-tracing"))] +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { SUBSCRIBER_INSTANCE.get() } -#[cfg(all(no_std, not(feature = "with-tracing")))] +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { None } -#[cfg(all(no_std, not(feature = "with-tracing")))] +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] pub fn set_tracing_subscriber(_subscriber: Box) { unreachable!() } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 30f449b795fd2..2dcaa60697bbb 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -45,6 +45,12 @@ pub type WasmFields = Vec>; #[derive(Encode, Decode, Debug)] pub struct WasmValues(Vec<(Vec, WasmFieldValue)>); +impl From, WasmFieldValue)>> for WasmValues { + fn from(v: Vec<(Vec, WasmFieldValue)>) -> Self { + WasmValues(v) + } +} + #[derive(Encode, Decode, Debug)] pub struct WasmMetadata { pub name: Vec, @@ -60,8 +66,8 @@ pub struct WasmMetadata { #[derive(Encode, Decode, Debug)] pub struct WasmAttributes { pub parent_id: Option, - pub fields: WasmValues, pub metadata: WasmMetadata, + pub fields: WasmValues, } #[derive(Encode, Decode, Debug)] diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 77734a3cba63a..fdc8e08bd594e 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -22,6 +22,9 @@ use sp_std::{ #[cfg(not(feature = "with-tracing"))] mod inner { + // we are no-op + pub type Span = (); + #[doc(hidden)] #[macro_export] macro_rules! __tracing_mk_span { @@ -29,7 +32,6 @@ mod inner { (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; } - /// Constructs a new `Event` – noop #[macro_export] macro_rules! event { @@ -69,7 +71,6 @@ mod inner { use core::{ module_path, concat, format_args, file, line, }; - use crate::WasmMetadata; // just a simplistic holder for span and entered spans // that exits on drop @@ -77,12 +78,22 @@ mod inner { pub struct Entered(u64); // 0 means no item impl Span { - pub fn enter(self) -> Entered { + pub fn new(v: u64) -> Self { + Span(v) + } + pub fn none() -> Self { + Span::new(0) + } + pub fn enter(&self) -> Entered { if self.0 != 0 { crate::get_tracing_subscriber().map(|t| t.enter(self.0)); } Entered(self.0) } + pub fn in_scope T, T>(&self, f: F) -> T { + let _enter = self.enter(); + f() + } } impl Entered { @@ -113,7 +124,7 @@ mod inner { /// # Examples /// /// ```rust - /// use tracing::{event, Level}; + /// use sp_tracing::{event, Level}; /// /// # fn main() { /// let data = (42, "forty-two"); @@ -141,8 +152,8 @@ mod inner { // /// For example, the following does not compile: // /// ```rust,compile_fail // /// # #[macro_use] - // /// # extern crate tracing; - // /// # use tracing::Level; + // /// # extern crate sp_tracing; + // /// # use sp_tracing::Level; // /// # fn main() { // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") // /// #} @@ -153,7 +164,7 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmEvent, WasmValue, WasmValueSet }; + use $crate::{ WasmMetadata, WasmEvent, WasmValues }; let metadata = WasmMetadata { name: concat!( "event ", @@ -164,16 +175,16 @@ mod inner { file: file!().as_bytes().to_vec(), line: line!(), is_span: false, - target: $target, + target: $target.into(), level: $lvl, - module_path: module_path().as_bytes().to_vec(), - fields: $($fields)* + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] }; - if $crate::is_enabled!(&metdata) { + if $crate::is_enabled!(&metadata) { $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { - parent: $parent, + parent_id: Some($parent.0), metadata, - &$crate::valueset!(meta.fields(), $($fields)*) + fields: vec![].into() })); } } @@ -198,7 +209,7 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmEvent, WasmValue, WasmValueSet}; + use $crate::{WasmMetadata, WasmEvent, WasmValues}; let metadata = WasmMetadata { name: concat!( "event ", @@ -209,16 +220,16 @@ mod inner { file: file!().as_bytes().to_vec(), line: line!(), is_span: false, - target: $target, + target: $target.into(), level: $lvl, - module_path: module_path().as_bytes().to_vec(), - fields: $($fields)* + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] }; - if $crate::is_enabled!(&metdata) { + if $crate::is_enabled!(&metadata) { $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { - parent: None, + parent_id: None, metadata, - &$crate::valueset!(meta.fields(), $($fields)*) + fields: vec![].into() })); } } @@ -367,29 +378,31 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmAttributes, WasmValue, WasmValueSet }; + use $crate::{ WasmMetadata, WasmAttributes, WasmValues }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), file: file!().as_bytes().to_vec(), line: line!(), is_span: true, - target: $target, + target: $target.into(), level: $lvl, - module_path: module_path().as_bytes().to_vec(), - fields: $($fields)* + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] }; if $crate::is_enabled!(metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span(WasmAttributes{ - parent: Some($parent), - metadata, - &$crate::valueset!(meta.fields(), $($fields)*) - })).unwrap_or_default(); - $crate::Span(span_id) + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + WasmAttributes { + parent_id: Some($parent.0), + metadata, + fields: vec![].into() + }) + ).unwrap_or_default(); + $crate::Span::new(span_id) } else { - $crate::Span(0) + $crate::Span::none() } } else { - $crate::Span(0) + $crate::Span::none() } } }; @@ -397,29 +410,31 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmAttributes, WasmValue, WasmValueSet}; + use $crate::{WasmMetadata, WasmAttributes, WasmValues}; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), file: file!().as_bytes().to_vec(), line: line!(), is_span: true, - target: $target, + target: $target.into(), level: $lvl, - module_path: module_path().as_bytes().to_vec(), - fields: $($fields)* + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] }; if $crate::is_enabled!(metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span(WasmAttributes{ - parent: Some($parent), - metadata, - &$crate::valueset!(meta.fields(), $($fields)*) - })).unwrap_or_default(); - $crate::Span(span_id) + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + WasmAttributes { + parent_id: None, + metadata, + fields: vec![].into() + }) + ).unwrap_or_default(); + $crate::Span::new(span_id) } else { - $crate::Span(0) + $crate::Span::none() } } else { - $crate::Span(0) + $crate::Span::none() } } }; @@ -439,7 +454,7 @@ pub use inner::*; /// /// Creating a new span: /// ``` -/// # use tracing::{span, Level}; +/// # use sp_tracing::{span, Level}; /// # fn main() { /// let span = span!(Level::TRACE, "my span"); /// let _enter = span.enter(); @@ -520,8 +535,8 @@ macro_rules! span { /// /// # Examples /// -/// ```rust -/// # use tracing::{trace_span, span, Level}; +/// ``` +/// # use sp_tracing::{trace_span, span, Level}; /// # fn main() { /// trace_span!("my_span"); /// // is equivalent to: @@ -529,8 +544,8 @@ macro_rules! span { /// # } /// ``` /// -/// ```rust -/// # use tracing::{trace_span, span, Level}; +/// ``` +/// # use sp_tracing::{trace_span, span, Level}; /// # fn main() { /// let span = trace_span!("my span"); /// span.in_scope(|| { @@ -602,7 +617,7 @@ macro_rules! trace_span { /// # Examples /// /// ```rust -/// # use tracing::{debug_span, span, Level}; +/// # use sp_tracing::{debug_span, span, Level}; /// # fn main() { /// debug_span!("my_span"); /// // is equivalent to: @@ -611,7 +626,7 @@ macro_rules! trace_span { /// ``` /// /// ```rust -/// # use tracing::debug_span; +/// # use sp_tracing::debug_span; /// # fn main() { /// let span = debug_span!("my span"); /// span.in_scope(|| { @@ -683,7 +698,7 @@ macro_rules! debug_span { /// # Examples /// /// ```rust -/// # use tracing::{span, info_span, Level}; +/// # use sp_tracing::{span, info_span, Level}; /// # fn main() { /// info_span!("my_span"); /// // is equivalent to: @@ -692,7 +707,7 @@ macro_rules! debug_span { /// ``` /// /// ```rust -/// # use tracing::info_span; +/// # use sp_tracing::info_span; /// # fn main() { /// let span = info_span!("my span"); /// span.in_scope(|| { @@ -764,7 +779,7 @@ macro_rules! info_span { /// # Examples /// /// ```rust -/// # use tracing::{warn_span, span, Level}; +/// # use sp_tracing::{warn_span, span, Level}; /// # fn main() { /// warn_span!("my_span"); /// // is equivalent to: @@ -773,7 +788,7 @@ macro_rules! info_span { /// ``` /// /// ```rust -/// use tracing::warn_span; +/// use sp_tracing::warn_span; /// # fn main() { /// let span = warn_span!("my span"); /// span.in_scope(|| { @@ -844,7 +859,7 @@ macro_rules! warn_span { /// # Examples /// /// ```rust -/// # use tracing::{span, error_span, Level}; +/// # use sp_tracing::{span, error_span, Level}; /// # fn main() { /// error_span!("my_span"); /// // is equivalent to: @@ -853,7 +868,7 @@ macro_rules! warn_span { /// ``` /// /// ```rust -/// # use tracing::error_span; +/// # use sp_tracing::error_span; /// # fn main() { /// let span = error_span!("my span"); /// span.in_scope(|| { @@ -921,7 +936,7 @@ macro_rules! error_span { /// # Examples /// /// ```rust -/// use tracing::trace; +/// use sp_tracing::trace; /// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } /// # impl Position { /// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; @@ -1121,7 +1136,7 @@ macro_rules! trace { /// # Examples /// /// ```rust -/// use tracing::debug; +/// use sp_tracing::debug; /// # fn main() { /// # #[derive(Debug)] struct Position { x: f32, y: f32 } /// @@ -1322,14 +1337,13 @@ macro_rules! debug { /// # Examples /// /// ```rust -/// use tracing::info; +/// use sp_tracing::info; /// # // this is so the test will still work in no-std mode /// # #[derive(Debug)] /// # pub struct Ipv4Addr; /// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } /// # fn main() { /// # struct Connection { port: u32, speed: f32 } -/// use tracing::field; /// /// let addr = Ipv4Addr::new(127, 0, 0, 1); /// let conn = Connection { port: 40, speed: 3.20 }; @@ -1534,7 +1548,7 @@ macro_rules! info { /// # Examples /// /// ```rust -/// use tracing::warn; +/// use sp_tracing::warn; /// # fn main() { /// /// let warn_description = "Invalid Input"; @@ -1739,7 +1753,7 @@ macro_rules! warn { /// # Examples /// /// ```rust -/// use tracing::error; +/// use sp_tracing::error; /// # fn main() { /// /// let (err_info, port) = ("No connection", 22); @@ -1946,7 +1960,7 @@ macro_rules! level_enabled { #[doc(hidden)] macro_rules! is_enabled { ($metadata:expr) => {{ - $crate::get_tracing_subscriber().map(|t| t.enabled($metadata)).unwrap_or_false() + $crate::get_tracing_subscriber().map(|t| t.enabled(&$metadata)).unwrap_or(false) }}; } From ed6770bce63930ddcd76b81f81343c0b1e384d2e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 13 Aug 2020 17:26:22 +0200 Subject: [PATCH 042/113] spaces -> tabs --- primitives/tracing/src/wasm_tracing.rs | 3414 ++++++++++++------------ 1 file changed, 1707 insertions(+), 1707 deletions(-) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index fdc8e08bd594e..6d3e4bdda1b14 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -17,428 +17,428 @@ #![no_std] use sp_std::{ - vec + vec }; #[cfg(not(feature = "with-tracing"))] mod inner { - // we are no-op - pub type Span = (); + // we are no-op + pub type Span = (); - #[doc(hidden)] - #[macro_export] - macro_rules! __tracing_mk_span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; - } + #[doc(hidden)] + #[macro_export] + macro_rules! __tracing_mk_span { + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; + } - /// Constructs a new `Event` – noop - #[macro_export] - macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> { {} }; + /// Constructs a new `Event` – noop + #[macro_export] + macro_rules! event { + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> { {} }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => { {} }; - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> {{}}; - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; - ($lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, ?$($k:ident).+) => { {} }; - ($lvl:expr, %$($k:ident).+) => { {} }; - ($lvl:expr, $($k:ident).+) => { {} }; - ( $lvl:expr, $($arg:tt)+ ) => { {} }; - } + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => { {} }; + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> {{}}; + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; + ($lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; + ($lvl:expr, ?$($k:ident).+) => { {} }; + ($lvl:expr, %$($k:ident).+) => { {} }; + ($lvl:expr, $($k:ident).+) => { {} }; + ( $lvl:expr, $($arg:tt)+ ) => { {} }; + } } #[cfg(feature = "with-tracing")] mod inner { - use core::{ - module_path, concat, format_args, file, line, - }; + use core::{ + module_path, concat, format_args, file, line, + }; - // just a simplistic holder for span and entered spans - // that exits on drop - pub struct Span(u64); // 0 means no item - pub struct Entered(u64); // 0 means no item + // just a simplistic holder for span and entered spans + // that exits on drop + pub struct Span(u64); // 0 means no item + pub struct Entered(u64); // 0 means no item - impl Span { - pub fn new(v: u64) -> Self { - Span(v) - } - pub fn none() -> Self { - Span::new(0) - } - pub fn enter(&self) -> Entered { - if self.0 != 0 { - crate::get_tracing_subscriber().map(|t| t.enter(self.0)); - } - Entered(self.0) - } - pub fn in_scope T, T>(&self, f: F) -> T { - let _enter = self.enter(); - f() - } - } + impl Span { + pub fn new(v: u64) -> Self { + Span(v) + } + pub fn none() -> Self { + Span::new(0) + } + pub fn enter(&self) -> Entered { + if self.0 != 0 { + crate::get_tracing_subscriber().map(|t| t.enter(self.0)); + } + Entered(self.0) + } + pub fn in_scope T, T>(&self, f: F) -> T { + let _enter = self.enter(); + f() + } + } - impl Entered { - pub fn exit(&mut self) { - if self.0 != 0 { - crate::get_tracing_subscriber().map(|t| t.exit(self.0)); - } - } - } + impl Entered { + pub fn exit(&mut self) { + if self.0 != 0 { + crate::get_tracing_subscriber().map(|t| t.exit(self.0)); + } + } + } - impl Drop for Entered { - fn drop(&mut self) { - self.exit(); - } - } + impl Drop for Entered { + fn drop(&mut self) { + self.exit(); + } + } - /// Constructs a new `Event`. - /// - /// The event macro is invoked with a `Level` and up to 32 key-value fields. - /// Optionally, a format string and arguments may follow the fields; this will - /// be used to construct an implicit field named "message". - /// - /// See [the top-level documentation][lib] for details on the syntax accepted by - /// this macro. - /// - /// [lib]: index.html#using-the-macros - /// - /// # Examples - /// - /// ```rust - /// use sp_tracing::{event, Level}; - /// - /// # fn main() { - /// let data = (42, "forty-two"); - /// let private_data = "private"; - /// let error = "a bad error"; - /// - /// event!(Level::ERROR, %error, "Received error"); - /// event!( - /// target: "app_events", - /// Level::WARN, - /// private_data, - /// ?data, - /// "App warning: {}", - /// error - /// ); - /// event!(Level::INFO, the_answer = data.0); - /// # } - /// ``` - /// - // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As - // /// events are recorded immediately when the macro is invoked, there is no - // /// opportunity for fields to be recorded later. A trailing comma on the final - // /// field is valid. - // /// - // /// For example, the following does not compile: - // /// ```rust,compile_fail - // /// # #[macro_use] - // /// # extern crate sp_tracing; - // /// # use sp_tracing::Level; - // /// # fn main() { - // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") - // /// #} - // /// ``` - #[macro_export] - macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmEvent, WasmValues }; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: vec![] - }; - if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { - parent_id: Some($parent.0), - metadata, - fields: vec![].into() - })); - } - } - } - }); + /// Constructs a new `Event`. + /// + /// The event macro is invoked with a `Level` and up to 32 key-value fields. + /// Optionally, a format string and arguments may follow the fields; this will + /// be used to construct an implicit field named "message". + /// + /// See [the top-level documentation][lib] for details on the syntax accepted by + /// this macro. + /// + /// [lib]: index.html#using-the-macros + /// + /// # Examples + /// + /// ```rust + /// use sp_tracing::{event, Level}; + /// + /// # fn main() { + /// let data = (42, "forty-two"); + /// let private_data = "private"; + /// let error = "a bad error"; + /// + /// event!(Level::ERROR, %error, "Received error"); + /// event!( + /// target: "app_events", + /// Level::WARN, + /// private_data, + /// ?data, + /// "App warning: {}", + /// error + /// ); + /// event!(Level::INFO, the_answer = data.0); + /// # } + /// ``` + /// + // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As + // /// events are recorded immediately when the macro is invoked, there is no + // /// opportunity for fields to be recorded later. A trailing comma on the final + // /// field is valid. + // /// + // /// For example, the following does not compile: + // /// ```rust,compile_fail + // /// # #[macro_use] + // /// # extern crate sp_tracing; + // /// # use sp_tracing::Level; + // /// # fn main() { + // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") + // /// #} + // /// ``` + #[macro_export] + macro_rules! event { + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{ WasmMetadata, WasmEvent, WasmValues }; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] + }; + if $crate::is_enabled!(&metadata) { + $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { + parent_id: Some($parent.0), + metadata, + fields: vec![].into() + })); + } + } + } + }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::event!( - target: $target, - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - }); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( - $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) - ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmEvent, WasmValues}; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: vec![] - }; - if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { - parent_id: None, - metadata, - fields: vec![].into() - })); - } - } - } - }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ - $crate::event!( - target: $target, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - }); - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $lvl, { $($arg)+ }) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - parent: $parent, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { $($k).+ = $($field)*} - ) - ); - ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { $($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { ?$($k).+, $($field)*} - ) - ); - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { %$($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+) => ( - $crate::event!($lvl, ?$($k).+,) - ); - ($lvl:expr, %$($k:ident).+) => ( - $crate::event!($lvl, %$($k).+,) - ); - ($lvl:expr, $($k:ident).+) => ( - $crate::event!($lvl, $($k).+,) - ); - ( $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) - ); - } + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::event!( + target: $target, + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( + $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) + ); + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmEvent, WasmValues}; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] + }; + if $crate::is_enabled!(&metadata) { + $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { + parent_id: None, + metadata, + fields: vec![].into() + })); + } + } + } + }); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + $crate::event!( + target: $target, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + }); + (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( + $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) + ); + (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $lvl, { $($arg)+ }) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + parent: $parent, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $lvl, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $lvl, + { message = format_args!($($arg)+), $($fields)* } + ) + ); + ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { $($k).+ = $($field)*} + ) + ); + ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { $($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { ?$($k).+, $($field)*} + ) + ); + ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $lvl, + { %$($k).+, $($field)*} + ) + ); + ($lvl:expr, ?$($k:ident).+) => ( + $crate::event!($lvl, ?$($k).+,) + ); + ($lvl:expr, %$($k:ident).+) => ( + $crate::event!($lvl, %$($k).+,) + ); + ($lvl:expr, $($k:ident).+) => ( + $crate::event!($lvl, $($k).+,) + ); + ( $lvl:expr, $($arg:tt)+ ) => ( + $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) + ); + } - #[doc(hidden)] - #[macro_export] - macro_rules! __tracing_mk_span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmAttributes, WasmValues }; - let metadata = WasmMetadata { - name: $name.as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: true, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: vec![] - }; - if $crate::is_enabled!(metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( - WasmAttributes { - parent_id: Some($parent.0), - metadata, - fields: vec![].into() - }) - ).unwrap_or_default(); - $crate::Span::new(span_id) - } else { - $crate::Span::none() - } - } else { - $crate::Span::none() - } - } - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmAttributes, WasmValues}; - let metadata = WasmMetadata { - name: $name.as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: true, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: vec![] - }; - if $crate::is_enabled!(metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( - WasmAttributes { - parent_id: None, - metadata, - fields: vec![].into() - }) - ).unwrap_or_default(); - $crate::Span::new(span_id) - } else { - $crate::Span::none() - } - } else { - $crate::Span::none() - } - } - }; - } + #[doc(hidden)] + #[macro_export] + macro_rules! __tracing_mk_span { + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{ WasmMetadata, WasmAttributes, WasmValues }; + let metadata = WasmMetadata { + name: $name.as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: true, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] + }; + if $crate::is_enabled!(metadata) { + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + WasmAttributes { + parent_id: Some($parent.0), + metadata, + fields: vec![].into() + }) + ).unwrap_or_default(); + $crate::Span::new(span_id) + } else { + $crate::Span::none() + } + } else { + $crate::Span::none() + } + } + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + { + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{WasmMetadata, WasmAttributes, WasmValues}; + let metadata = WasmMetadata { + name: $name.as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: true, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: vec![] + }; + if $crate::is_enabled!(metadata) { + let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + WasmAttributes { + parent_id: None, + metadata, + fields: vec![].into() + }) + ).unwrap_or_default(); + $crate::Span::new(span_id) + } else { + $crate::Span::none() + } + } else { + $crate::Span::none() + } + } + }; + } } pub use inner::*; @@ -463,61 +463,61 @@ pub use inner::*; /// ``` #[macro_export] macro_rules! span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, parent: $parent, $lvl, $name,) - }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::__tracing_mk_span!(target: $target, parent: $parent, $lvl, $name, $($fields)*) - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::__tracing_mk_span!(target: $target, $lvl, $name, $($fields)*) - }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, parent: $parent, $lvl, $name,) - }; - (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $lvl, - $name, - $($fields)* - ) - }; - (parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $lvl, - $name, - ) - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: $target, - $lvl, - $name, - $($fields)* - ) - }; - (target: $target:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, $lvl, $name,) - }; - ($lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: module_path!(), - $lvl, - $name, - $($fields)* - ) - }; - ($lvl:expr, $name:expr) => { - $crate::span!( - target: module_path!(), - $lvl, - $name, - ) - }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, parent: $parent, $lvl, $name,) + }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::__tracing_mk_span!(target: $target, parent: $parent, $lvl, $name, $($fields)*) + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::__tracing_mk_span!(target: $target, $lvl, $name, $($fields)*) + }; + (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, parent: $parent, $lvl, $name,) + }; + (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $lvl, + $name, + $($fields)* + ) + }; + (parent: $parent:expr, $lvl:expr, $name:expr) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $lvl, + $name, + ) + }; + (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: $target, + $lvl, + $name, + $($fields)* + ) + }; + (target: $target:expr, $lvl:expr, $name:expr) => { + $crate::span!(target: $target, $lvl, $name,) + }; + ($lvl:expr, $name:expr, $($fields:tt)*) => { + $crate::span!( + target: module_path!(), + $lvl, + $name, + $($fields)* + ) + }; + ($lvl:expr, $name:expr) => { + $crate::span!( + target: module_path!(), + $lvl, + $name, + ) + }; } /// Constructs a span at the trace level. @@ -555,50 +555,50 @@ macro_rules! span { /// ``` #[macro_export] macro_rules! trace_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::trace_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::trace_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::trace_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - ($name:expr) => { $crate::trace_span!($name,) }; + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::trace_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::trace_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::trace_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::TRACE, + $name, + $($field)* + ) + }; + ($name:expr) => { $crate::trace_span!($name,) }; } /// Constructs a span at the debug level. @@ -636,50 +636,50 @@ macro_rules! trace_span { /// ``` #[macro_export] macro_rules! debug_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::debug_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::debug_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::debug_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::debug_span!($name,)}; + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::debug_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::debug_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::debug_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::DEBUG, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::debug_span!($name,)}; } /// Constructs a span at the info level. @@ -717,50 +717,50 @@ macro_rules! debug_span { /// ``` #[macro_export] macro_rules! info_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::info_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::info_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::info_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::INFO, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::info_span!($name,)}; + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::info_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::info_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::INFO, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::info_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::INFO, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::info_span!($name,)}; } /// Constructs a span at the warn level. @@ -798,50 +798,50 @@ macro_rules! info_span { /// ``` #[macro_export] macro_rules! warn_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::warn_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::warn_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::warn_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::WARN, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::warn_span!($name,)}; + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::warn_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::warn_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::WARN, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::warn_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::WARN, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::warn_span!($name,)}; } /// Constructs a span at the error level. /// @@ -878,50 +878,50 @@ macro_rules! warn_span { /// ``` #[macro_export] macro_rules! error_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::error_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::error_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::error_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::error_span!($name,)}; + (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + parent: $parent, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (target: $target:expr, parent: $parent:expr, $name:expr) => { + $crate::error_span!(target: $target, parent: $parent, $name,) + }; + (parent: $parent:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (parent: $parent:expr, $name:expr) => { + $crate::error_span!(parent: $parent, $name,) + }; + (target: $target:expr, $name:expr, $($field:tt)*) => { + $crate::span!( + target: $target, + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + (target: $target:expr, $name:expr) => { + $crate::error_span!(target: $target, $name,) + }; + ($name:expr, $($field:tt)*) => { + $crate::span!( + target: module_path!(), + $crate::Level::ERROR, + $name, + $($field)* + ) + }; + ($name:expr) => {$crate::error_span!($name,)}; } /// Constructs an event at the trace level. @@ -961,167 +961,167 @@ macro_rules! error_span { /// ``` #[macro_export] macro_rules! trace { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - {}, - $($arg)+ - ) - ); + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::TRACE, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + {}, + $($arg)+ + ) + ); } /// Constructs an event at the debug level. @@ -1148,181 +1148,181 @@ macro_rules! trace { /// ``` #[macro_export] macro_rules! debug { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - {}, - $($arg)+ - ) - ); + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::DEBUG, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::DEBUG, + {}, + $($arg)+ + ) + ); } /// Constructs an event at the info level. @@ -1359,181 +1359,181 @@ macro_rules! debug { /// ``` #[macro_export] macro_rules! info { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - {}, - $($arg)+ - ) - ); + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::INFO, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::INFO, + {}, + $($arg)+ + ) + ); } /// Constructs an event at the warn level. @@ -1564,181 +1564,181 @@ macro_rules! info { /// ``` #[macro_export] macro_rules! warn { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - {}, - $($arg)+ - ) - ); + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::WARN, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::WARN, + {}, + $($arg)+ + ) + ); } /// Constructs an event at the error level. @@ -1765,181 +1765,181 @@ macro_rules! warn { /// ``` #[macro_export] macro_rules! error { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - {}, - $($arg)+ - ) - ); + (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) + ); + (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($field)+ }, + $($arg)+ + ) + ); + (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { ?$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { %$($k).+ = $($field)*} + ) + ); + (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { $($k).+, $($field)*} + ) + ); + (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { ?$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + { %$($k).+, $($field)*} + ) + ); + (parent: $parent:expr, $($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + parent: $parent, + $crate::Level::ERROR, + {}, + $($arg)+ + ) + ); + (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) + ); + (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) + ); + (target: $target:expr, $($arg:tt)+ ) => ( + $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) + ); + ({ $($field:tt)+ }, $($arg:tt)+ ) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($field)+ }, + $($arg)+ + ) + ); + ($($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+ = $($field)*} + ) + ); + (?$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+ = $($field)*} + ) + ); + (%$($k:ident).+ = $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::TRACE, + { %$($k).+ = $($field)*} + ) + ); + ($($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+, $($field)*} + ) + ); + (?$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+, $($field)*} + ) + ); + (%$($k:ident).+, $($field:tt)*) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { %$($k).+, $($field)*} + ) + ); + (?$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { ?$($k).+ } + ) + ); + (%$($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { %$($k).+ } + ) + ); + ($($k:ident).+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + { $($k).+ } + ) + ); + ($($arg:tt)+) => ( + $crate::event!( + target: module_path!(), + $crate::Level::ERROR, + {}, + $($arg)+ + ) + ); } @@ -1947,205 +1947,205 @@ macro_rules! error { // TODO: determine if this ought to be public API? #[doc(hidden)] macro_rules! level_enabled { - ($lvl:expr) => { - // FIXME: use the runtime interface to figure this out - true - // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL - - }; + ($lvl:expr) => { + // FIXME: use the runtime interface to figure this out + true + // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL + + }; } #[macro_export] // TODO: determine if this ought to be public API? #[doc(hidden)] macro_rules! is_enabled { - ($metadata:expr) => {{ - $crate::get_tracing_subscriber().map(|t| t.enabled(&$metadata)).unwrap_or(false) - }}; + ($metadata:expr) => {{ + $crate::get_tracing_subscriber().map(|t| t.enabled(&$metadata)).unwrap_or(false) + }}; } #[doc(hidden)] #[macro_export] macro_rules! valueset { - // === base case === - (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { - vec![ $($val),* ] - }; + // === base case === + (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { + vec![ $($val),* ] + }; - // === recursive case (more tts) === + // === recursive case (more tts) === - // TODO(#1138): determine a new syntax for uninitialized span fields, and - // re-enable this. - // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { - // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) - // }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&$val as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&$val as &Value)) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, - $next, - ) - }; - // Remainder is unparseable, but exists --- must be format args! - (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { - $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, ) - }; + // TODO(#1138): determine a new syntax for uninitialized span fields, and + // re-enable this. + // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { + // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) + // }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$val as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + $next, + $($rest)* + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$val as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + $next, + ) + }; + (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { + $crate::valueset!( + @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + $next, + ) + }; + // Remainder is unparseable, but exists --- must be format args! + (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { + $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, ) + }; - // === entry === - ($fields:expr, $($kvs:tt)+) => { - { - #[allow(unused_imports)] - use $crate::field::{debug, display, Value}; - let mut iter = $fields.iter(); - $fields.value_set($crate::valueset!( - @ { }, - iter.next().expect("FieldSet corrupted (this is a bug)"), - $($kvs)+ - )) - } - }; - ($fields:expr,) => { - { - $fields.value_set(&[]) - } - }; + // === entry === + ($fields:expr, $($kvs:tt)+) => { + { + #[allow(unused_imports)] + use $crate::field::{debug, display, Value}; + let mut iter = $fields.iter(); + $fields.value_set($crate::valueset!( + @ { }, + iter.next().expect("FieldSet corrupted (this is a bug)"), + $($kvs)+ + )) + } + }; + ($fields:expr,) => { + { + $fields.value_set(&[]) + } + }; } #[doc(hidden)] #[macro_export] macro_rules! fieldset { - // == base case == - (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { - vec![ $($out),* ] - }; + // == base case == + (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { + vec![ $($out),* ] + }; - // == recursive cases (more tts) == - (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - // TODO(#1138): determine a new syntax for uninitialized span fields, and - // re-enable this. - // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { - // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - // }; - (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; + // == recursive cases (more tts) == + (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + // TODO(#1138): determine a new syntax for uninitialized span fields, and + // re-enable this. + // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { + // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + // }; + (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; + (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { + $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) + }; - // Remainder is unparseable, but exists --- must be format args! - (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { - $crate::fieldset!(@ { "message", $($out),*, }) - }; + // Remainder is unparseable, but exists --- must be format args! + (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { + $crate::fieldset!(@ { "message", $($out),*, }) + }; - // == entry == - ($($args:tt)*) => { - $crate::fieldset!(@ { } $($args)*,) - }; + // == entry == + ($($args:tt)*) => { + $crate::fieldset!(@ { } $($args)*,) + }; } #[doc(hidden)] #[macro_export] macro_rules! __tracing_stringify { - ($s:expr) => { - stringify!($s) - }; + ($s:expr) => { + stringify!($s) + }; } #[doc(hidden)] #[macro_export] macro_rules! if_log_enabled { - ($e:expr;) => { - $crate::if_log_enabled! { $e } - }; - ($if_log:block) => { - $crate::if_log_enabled! { $if_log else {} } - }; - ($if_log:block else $else_block:block) => { - $else_block - }; + ($e:expr;) => { + $crate::if_log_enabled! { $e } + }; + ($if_log:block) => { + $crate::if_log_enabled! { $if_log else {} } + }; + ($if_log:block else $else_block:block) => { + $else_block + }; } \ No newline at end of file From f26f1472766653b7dde738c8e3c3d6fb7c26c3b5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 14 Aug 2020 13:01:55 +0200 Subject: [PATCH 043/113] attempting to reactivate params --- primitives/tracing/src/lib.rs | 4 +- primitives/tracing/src/types.rs | 141 +++++++++++++++++++++++-- primitives/tracing/src/wasm_tracing.rs | 72 +++++++------ 3 files changed, 172 insertions(+), 45 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 6385d39f8b8f1..a942c49b410ef 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -56,7 +56,7 @@ use sp_std::boxed::Box; use once_cell::sync::OnceCell; pub use crate::types::{ - WasmMetadata, WasmAttributes, WasmValues, WasmEvent, WasmLevel, + WasmMetadata, WasmAttributes, WasmValuesSet, WasmValue, WasmFields, WasmEvent, WasmLevel, WasmFieldName }; #[cfg(not(feature = "std"))] pub type Level = WasmLevel; @@ -65,7 +65,7 @@ pub type Level = WasmLevel; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: &WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; - fn record(&self, span: u64, values: WasmValues); + fn record(&self, span: u64, values: WasmValuesSet); fn event(&self, event: WasmEvent); fn enter(&self, span: u64); fn exit(&self, span: u64); diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 2dcaa60697bbb..4ddb70255cca3 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -30,27 +30,146 @@ pub enum WasmLevel { TRACE } -#[derive(Encode, Decode, Debug)] -pub enum WasmFieldValue { +#[derive(Encode, Decode, Clone, Debug)] +pub enum WasmValue { + U8(u8), + U32(u32), + I32(i32), I64(i64), U64(u64), Bool(bool), Str(Vec), - Debug(Vec), + Display(Vec), Encoded(Vec), } -pub type WasmFields = Vec>; +impl From for WasmValue { + fn from(u: u8) -> WasmValue { + WasmValue::U8(u) + } +} + +impl From<&str> for WasmValue { + fn from(inp: &str) -> WasmValue { + WasmValue::Str(inp.as_bytes().to_vec()) + } +} + + +impl From<&&str> for WasmValue { + fn from(inp: &&str) -> WasmValue { + WasmValue::Str((*inp).as_bytes().to_vec()) + } +} + +impl From for WasmValue { + fn from(inp: bool) -> WasmValue { + WasmValue::Bool(inp) + } +} + +impl From<&core::fmt::Arguments<'_>> for WasmValue { + fn from(inp: &core::fmt::Arguments<'_>) -> WasmValue { + todo!{} + } +} + +impl From for WasmValue { + fn from(u: u32) -> WasmValue { + WasmValue::U32(u) + } +} + +impl From for WasmValue { + fn from(u: i32) -> WasmValue { + WasmValue::I32(u) + } +} + +impl From for WasmValue { + fn from(u: u64) -> WasmValue { + WasmValue::U64(u) + } +} + +impl From for WasmValue { + fn from(u: i64) -> WasmValue { + WasmValue::I64(u) + } +} + +#[derive(Encode, Decode, Clone, Debug)] +pub struct WasmFieldName(Vec); + + +impl From> for WasmFieldName { + fn from(v: Vec) -> Self { + WasmFieldName(v) + } +} + +impl From<&str> for WasmFieldName { + fn from(v: &str) -> Self { + WasmFieldName(v.as_bytes().to_vec()) + } +} + + +#[derive(Encode, Decode, Clone, Debug)] +pub struct WasmFields(Vec); + +impl WasmFields { + pub fn iter(&self) -> core::slice::Iter<'_, WasmFieldName> { + self.0.iter() + } +} + +impl From> for WasmFields { + fn from(v: Vec) -> WasmFields { + WasmFields(v.into()) + } +} + +impl From> for WasmFields { + fn from(v: Vec<&str>) -> WasmFields { + WasmFields(v.into_iter().map(|v| v.into()).collect()) + } +} + +impl WasmFields { + pub fn empty() -> Self { + WasmFields(Vec::with_capacity(0)) + } +} #[derive(Encode, Decode, Debug)] -pub struct WasmValues(Vec<(Vec, WasmFieldValue)>); +pub struct WasmValuesSet(Vec<(WasmFieldName, Option)>); + +impl From)>> for WasmValuesSet { + fn from(v: Vec<(WasmFieldName, Option)>) -> Self { + WasmValuesSet(v) + } +} +impl From)>> for WasmValuesSet { + fn from(v: Vec<(&WasmFieldName, Option)>) -> Self { + // FIXME: remove this clone! + WasmValuesSet(v.into_iter().map(|(k, v)| ((*k).clone(), v)).collect()) + } +} -impl From, WasmFieldValue)>> for WasmValues { - fn from(v: Vec<(Vec, WasmFieldValue)>) -> Self { - WasmValues(v) +impl From)>> for WasmValuesSet { + fn from(v: Vec<(&&str, Option)>) -> Self { + WasmValuesSet(v.into_iter().map(|(k, v)| ((*k).into(), v)).collect()) } } +impl WasmValuesSet { + pub fn empty() -> Self { + WasmValuesSet(Vec::with_capacity(0)) + } +} + + #[derive(Encode, Decode, Debug)] pub struct WasmMetadata { pub name: Vec, @@ -67,17 +186,17 @@ pub struct WasmMetadata { pub struct WasmAttributes { pub parent_id: Option, pub metadata: WasmMetadata, - pub fields: WasmValues, + pub fields: WasmValuesSet, } #[derive(Encode, Decode, Debug)] pub struct WasmEvent { pub parent_id: Option, pub metadata: WasmMetadata, - pub fields: WasmValues, + pub fields: WasmValuesSet, } -// TODO - Do we need this when we have WasmValues ? +// TODO - Do we need this when we have WasmValuesSet ? // #[derive(Encode, Decode)] // pub struct WasmRecord; diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 6d3e4bdda1b14..e9750fe48af13 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -164,7 +164,9 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmEvent, WasmValues }; + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; let metadata = WasmMetadata { name: concat!( "event ", @@ -178,13 +180,13 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: vec![] + fields: $crate::fieldset!($($fields)*), }; if $crate::is_enabled!(&metadata) { $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { parent_id: Some($parent.0), + fields: $crate::valueset!(metadata.fields, $($fields)*), metadata, - fields: vec![].into() })); } } @@ -209,7 +211,9 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmEvent, WasmValues}; + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; let metadata = WasmMetadata { name: concat!( "event ", @@ -223,13 +227,13 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: vec![] + fields: $crate::fieldset!($($fields)*) }; if $crate::is_enabled!(&metadata) { $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { parent_id: None, metadata, - fields: vec![].into() + fields: $crate::valueset!(metadata.fields, $($fields)*) })); } } @@ -378,7 +382,9 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{ WasmMetadata, WasmAttributes, WasmValues }; + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), file: file!().as_bytes().to_vec(), @@ -387,14 +393,14 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: vec![] + fields: $crate::fieldset!($($fields)*) }; if $crate::is_enabled!(metadata) { let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( WasmAttributes { parent_id: Some($parent.0), metadata, - fields: vec![].into() + fields: $crate::valueset!(metadata.fields, $($fields)*) }) ).unwrap_or_default(); $crate::Span::new(span_id) @@ -410,7 +416,9 @@ mod inner { { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] - use $crate::{WasmMetadata, WasmAttributes, WasmValues}; + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), file: file!().as_bytes().to_vec(), @@ -419,14 +427,14 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: vec![] + fields: $crate::fieldset!($($fields)*) }; if $crate::is_enabled!(metadata) { let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( WasmAttributes { parent_id: None, metadata, - fields: vec![].into() + fields: $crate::valueset!(metadata.fields, $($fields)*) }) ).unwrap_or_default(); $crate::Span::new(span_id) @@ -1970,7 +1978,7 @@ macro_rules! valueset { // === base case === (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { - vec![ $($val),* ] + WasmValuesSet::from(vec![ $($val),* ]) }; // === recursive case (more tts) === @@ -1982,103 +1990,103 @@ macro_rules! valueset { // }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$val)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&display(&$val)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&$val as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&$val))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&$($k).+ as))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$($k).+) ))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&display(&$($k).+)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$val) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$val)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$val) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&display(&$val)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&$val as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&$val))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&$($k).+ as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&$($k).+))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$($k).+)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, (&$next, Some(&display(&$($k).+) as &Value)) }, + @ { $($out),*, ($next, Some(WasmValue::from(&display(&$($k).+))))}, $next, ) }; // Remainder is unparseable, but exists --- must be format args! (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { - $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &Value)), $($out),* }, $next, ) + $crate::valueset!(@ { ($next, Some(WasmValue::from(&format_args!($($rest)+)))), $($out),* }, $next, ) }; // === entry === ($fields:expr, $($kvs:tt)+) => { { #[allow(unused_imports)] - use $crate::field::{debug, display, Value}; + use $crate::{WasmValuesSet, WasmValue}; let mut iter = $fields.iter(); - $fields.value_set($crate::valueset!( + $crate::valueset!( @ { }, - iter.next().expect("FieldSet corrupted (this is a bug)"), + iter.next().expect("Fields must be defined"), $($kvs)+ - )) + ) } }; ($fields:expr,) => { { - $fields.value_set(&[]) + WasmValuesSet::empty() } }; } @@ -2088,7 +2096,7 @@ macro_rules! valueset { macro_rules! fieldset { // == base case == (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { - vec![ $($out),* ] + WasmFields::from(vec![ $($out),* ]) }; // == recursive cases (more tts) == From 44c92e8e80fa57eb9fb1be3c2414d39683d42524 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 14 Aug 2020 14:28:56 +0200 Subject: [PATCH 044/113] activate our tests in CI --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82368843d11de..39043257aac3d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -335,6 +335,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: From 0ee102ab5e1771348397b18276ac1f3335fc6597 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 14 Aug 2020 15:35:48 +0200 Subject: [PATCH 045/113] some passing --- primitives/tracing/src/types.rs | 36 ++++++++++++++++---- primitives/tracing/src/wasm_tracing.rs | 46 +++++++++++++------------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 4ddb70255cca3..be46a23e99eaf 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -17,7 +17,7 @@ use core::fmt::Debug; use sp_std::{ - vec::Vec + vec::Vec, }; use codec::{Encode, Decode}; @@ -33,13 +33,14 @@ pub enum WasmLevel { #[derive(Encode, Decode, Clone, Debug)] pub enum WasmValue { U8(u8), + I8(i8), U32(u32), I32(i32), I64(i64), U64(u64), Bool(bool), Str(Vec), - Display(Vec), + Formatted(Vec), Encoded(Vec), } @@ -49,13 +50,18 @@ impl From for WasmValue { } } +impl From<&i8> for WasmValue { + fn from(inp: &i8) -> WasmValue { + WasmValue::I8(inp.clone()) + } +} + impl From<&str> for WasmValue { fn from(inp: &str) -> WasmValue { WasmValue::Str(inp.as_bytes().to_vec()) } } - impl From<&&str> for WasmValue { fn from(inp: &&str) -> WasmValue { WasmValue::Str((*inp).as_bytes().to_vec()) @@ -68,15 +74,25 @@ impl From for WasmValue { } } +struct DebugWriter(Vec); +impl core::fmt::Write for DebugWriter { + fn write_str(&mut self, s: &str) -> core::result::Result<(), core::fmt::Error> { + self.0.extend_from_slice(s.as_bytes()); + Ok(()) + } +} + impl From<&core::fmt::Arguments<'_>> for WasmValue { fn from(inp: &core::fmt::Arguments<'_>) -> WasmValue { - todo!{} + let mut buf = DebugWriter(Vec::new()); + core::fmt::write(&mut buf, *inp).expect("Writing of arguments doesn't fail"); + WasmValue::Formatted(buf.0) } } -impl From for WasmValue { - fn from(u: u32) -> WasmValue { - WasmValue::U32(u) +impl From for WasmValue { + fn from(u: i8) -> WasmValue { + WasmValue::I8(u) } } @@ -86,6 +102,12 @@ impl From for WasmValue { } } +impl From for WasmValue { + fn from(u: u32) -> WasmValue { + WasmValue::U32(u) + } +} + impl From for WasmValue { fn from(u: u64) -> WasmValue { WasmValue::U64(u) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index e9750fe48af13..a8e509d2e8c21 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -180,12 +180,12 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!($($fields)*), + fields: $crate::fieldset!( $($fields)* ), }; if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { + $crate::get_tracing_subscriber().map(move |t| t.event(WasmEvent { parent_id: Some($parent.0), - fields: $crate::valueset!(metadata.fields, $($fields)*), + fields: $crate::valueset!(&metadata.fields, $($fields)*), metadata, })); } @@ -227,13 +227,13 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!($($fields)*) + fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event(WasmEvent { + $crate::get_tracing_subscriber().map(move |t| t.event(WasmEvent { parent_id: None, + fields: $crate::valueset!(&metadata.fields, $($fields)*), metadata, - fields: $crate::valueset!(metadata.fields, $($fields)*) })); } } @@ -393,14 +393,14 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!($($fields)*) + fields: $crate::fieldset!( $($fields)* ) }; - if $crate::is_enabled!(metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + if $crate::is_enabled!(&metadata) { + let span_id = $crate::get_tracing_subscriber().map(move |t| t.new_span( WasmAttributes { parent_id: Some($parent.0), + fields: $crate::valueset!(&metadata.fields, $($fields)*), metadata, - fields: $crate::valueset!(metadata.fields, $($fields)*) }) ).unwrap_or_default(); $crate::Span::new(span_id) @@ -427,14 +427,14 @@ mod inner { target: $target.into(), level: $lvl, module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!($($fields)*) + fields: $crate::fieldset!( $($fields)* ) }; - if $crate::is_enabled!(metadata) { + if $crate::is_enabled!(&metadata) { let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( WasmAttributes { parent_id: None, metadata, - fields: $crate::valueset!(metadata.fields, $($fields)*) + fields: $crate::valueset!(&metadata.fields, $($fields)*) }) ).unwrap_or_default(); $crate::Span::new(span_id) @@ -1586,7 +1586,7 @@ macro_rules! warn { ); (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) - ); + );struct (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1990,14 +1990,14 @@ macro_rules! valueset { // }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$val)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&display(&$val)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, $next, $($rest)* ) @@ -2018,27 +2018,27 @@ macro_rules! valueset { }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$($k).+) ))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+) ))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&display(&$($k).+)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$($k).+)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$val)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&display(&$val)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, $next, ) }; @@ -2056,13 +2056,13 @@ macro_rules! valueset { }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&debug(&$($k).+)))) }, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&display(&$($k).+))))}, + @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+))))}, $next, ) }; @@ -2096,7 +2096,7 @@ macro_rules! valueset { macro_rules! fieldset { // == base case == (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { - WasmFields::from(vec![ $($out),* ]) + WasmFields::from(vec![ $($out),* ] as Vec<&str>) }; // == recursive cases (more tts) == From da0d131f97f0f0e3279c10ba90e3098cb0eca0b2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 14 Aug 2020 16:35:29 +0200 Subject: [PATCH 046/113] tests passing --- primitives/tracing/src/lib.rs | 4 +- primitives/tracing/src/types.rs | 18 ++- primitives/tracing/src/wasm_tracing.rs | 159 ++++++++++++------------- 3 files changed, 94 insertions(+), 87 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index a942c49b410ef..7780c82234889 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -65,8 +65,8 @@ pub type Level = WasmLevel; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: &WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; - fn record(&self, span: u64, values: WasmValuesSet); - fn event(&self, event: WasmEvent); + fn record(&self, span: u64, values: &WasmValuesSet); + fn event(&self, parent_id: Option, metadata: &WasmMetadata, values: &WasmValuesSet); fn enter(&self, span: u64); fn exit(&self, span: u64); } diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index be46a23e99eaf..f0e172d69ad99 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -102,12 +102,24 @@ impl From for WasmValue { } } +impl From<&i32> for WasmValue { + fn from(u: &i32) -> WasmValue { + WasmValue::I32(*u) + } +} + impl From for WasmValue { fn from(u: u32) -> WasmValue { WasmValue::U32(u) } } +impl From<&u32> for WasmValue { + fn from(u: &u32) -> WasmValue { + WasmValue::U32(*u) + } +} + impl From for WasmValue { fn from(u: u64) -> WasmValue { WasmValue::U64(u) @@ -172,10 +184,10 @@ impl From)>> for WasmValuesSet { WasmValuesSet(v) } } -impl From)>> for WasmValuesSet { - fn from(v: Vec<(&WasmFieldName, Option)>) -> Self { +impl From)>> for WasmValuesSet { + fn from(v: Vec<(&&WasmFieldName, Option)>) -> Self { // FIXME: remove this clone! - WasmValuesSet(v.into_iter().map(|(k, v)| ((*k).clone(), v)).collect()) + WasmValuesSet(v.into_iter().map(|(k, v)| ((**k).clone(), v)).collect()) } } diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index a8e509d2e8c21..8993840d2e999 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -160,92 +160,88 @@ mod inner { // /// ``` #[macro_export] macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ), - }; - if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(move |t| t.event(WasmEvent { - parent_id: Some($parent.0), - fields: $crate::valueset!(&metadata.fields, $($fields)*), - metadata, - })); - } + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ( + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: $crate::fieldset!( $($fields)* ), + }; + if $crate::is_enabled!(&metadata) { + $crate::get_tracing_subscriber().map(|t| t.event( + Some($parent.0), + &metadata, + &$crate::valueset!(&metadata.fields, $($fields)*), + )); } } - }); + ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( $crate::event!( target: $target, parent: $parent, $lvl, { message = format_args!($($arg)+), $($fields)* } ) - }); + ); (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) ); (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ) - }; - if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(move |t| t.event(WasmEvent { - parent_id: None, - fields: $crate::valueset!(&metadata.fields, $($fields)*), - metadata, - })); - } + (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ( + if $crate::level_enabled!($lvl) { + #[allow(unused_imports)] + use $crate::{ + WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + }; + let metadata = WasmMetadata { + name: concat!( + "event ", + file!(), + ":", + line!() + ).as_bytes().to_vec(), + file: file!().as_bytes().to_vec(), + line: line!(), + is_span: false, + target: $target.into(), + level: $lvl, + module_path: module_path!().as_bytes().to_vec(), + fields: $crate::fieldset!( $($fields)* ) + }; + if $crate::is_enabled!(&metadata) { + $crate::get_tracing_subscriber().map(|t| t.event( + None, + &metadata, + &$crate::valueset!(&metadata.fields, $($fields)*), + )); } } - }); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ({ + ); + (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( $crate::event!( target: $target, $lvl, { message = format_args!($($arg)+), $($fields)* } ) - }); + ); (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) ); @@ -1586,7 +1582,7 @@ macro_rules! warn { ); (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) - );struct + ); (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( $crate::event!( target: module_path!(), @@ -1990,85 +1986,85 @@ macro_rules! valueset { // }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&$val))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&$val))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&$($k).+ as))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&$($k).+))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+) ))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+) ))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$($k).+)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$($k).+)))) }, $next, $($rest)* ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&$val))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&$val))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&$($k).+))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&$($k).+))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, $next, ) }; (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { $crate::valueset!( - @ { $($out),*, ($next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+))))}, + @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, $next, ) }; // Remainder is unparseable, but exists --- must be format args! (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { - $crate::valueset!(@ { ($next, Some(WasmValue::from(&format_args!($($rest)+)))), $($out),* }, $next, ) + $crate::valueset!(@ { (&$next, Some(WasmValue::from(&format_args!($($rest)+)))), $($out),* }, $next, ) }; // === entry === @@ -2084,11 +2080,10 @@ macro_rules! valueset { ) } }; - ($fields:expr,) => { - { + ($fields:expr,) => ( WasmValuesSet::empty() - } - }; + + ); } #[doc(hidden)] From fe05f0406f2c6c93d2bb1e95eafc55b58ac634f6 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 14 Aug 2020 16:50:51 +0200 Subject: [PATCH 047/113] with core lazy --- Cargo.lock | 1 - primitives/arithmetic/src/biguint.rs | 2 +- primitives/io/src/lib.rs | 20 ++++++++++++++------ primitives/npos-elections/src/reduce.rs | 1 + primitives/tracing/Cargo.toml | 2 -- primitives/tracing/src/lib.rs | 3 ++- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c8ea39a53195..154cec61145fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8181,7 +8181,6 @@ name = "sp-tracing" version = "2.0.0-rc5" dependencies = [ "log", - "once_cell", "parity-scale-codec", "sp-std", "tracing", diff --git a/primitives/arithmetic/src/biguint.rs b/primitives/arithmetic/src/biguint.rs index 41e2c759a5967..1fed54f598eec 100644 --- a/primitives/arithmetic/src/biguint.rs +++ b/primitives/arithmetic/src/biguint.rs @@ -18,7 +18,7 @@ //! Infinite precision unsigned integer for substrate runtime. use num_traits::Zero; -use sp_std::{cmp::Ordering, ops, prelude::*, cell::RefCell, convert::TryFrom}; +use sp_std::{cmp::Ordering, ops, prelude::*, vec, cell::RefCell, convert::TryFrom}; // A sensible value for this would be half of the dword size of the host machine. Since the // runtime is compiled to 32bit webassembly, using 32 and 64 for single and double respectively diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 755e8978b579a..95e26189220c1 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1045,20 +1045,28 @@ pub trait WasmTracing { } } -#[cfg(no_std)] +#[cfg(not(feature="std"))] /// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` /// and pushes the information accross the runtime interface to the host pub struct PassingTracingSubsciber; -#[cfg(no_std)] +#[cfg(not(feature="std"))] impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { - fn enabled(&self, metadata: sp_tracing::WasmMetadata) -> bool { - wasm_tracing::enabled(Crossing(metadata)) + fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { + wasm_tracing::enabled(Crossing(*metadata)) } fn new_span(&self, attrs: sp_tracing::WasmAttributes) -> u64 { wasm_tracing::new_span(Crossing(attrs)) } - fn event(&self, event: sp_tracing::WasmEvent) { - wasm_tracing::event(Crossing(event)) + fn event(&self, + parent_id: Option, + metadata: &sp_tracing::WasmMetadata, + values: &sp_tracing::WasmValueSet + ) { + wasm_tracing::event(Crossing(WasmEvent { + parent_id, + metadata: metadata.clone(), + values: values.clone() + })) } fn enter(&self, span: u64) { wasm_tracing::enter(span) diff --git a/primitives/npos-elections/src/reduce.rs b/primitives/npos-elections/src/reduce.rs index 6d458a5fffb38..17d7dd1290f7d 100644 --- a/primitives/npos-elections/src/reduce.rs +++ b/primitives/npos-elections/src/reduce.rs @@ -52,6 +52,7 @@ use crate::{ExtendedBalance, IdentifierT, StakedAssignment}; use sp_arithmetic::traits::{Bounded, Zero}; use sp_std::{ collections::btree_map::{BTreeMap, Entry::*}, + vec, prelude::*, }; diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 5f80ead0e01d8..d6a6e14f34783 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -17,14 +17,12 @@ codec = { version = "1.3.1", package = "parity-scale-codec", default-features = tracing = { version = "0.1.18", default-features = false } tracing-core = { version = "0.1.13", optional = true } log = { version = "0.4.8", optional = true } -once_cell = { version = "1.4.0", optional = true} [features] default = [ "std" ] with-tracing = [ "codec/derive", "codec/full", - "once_cell", ] std = [ "with-tracing", diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 7780c82234889..fe7a1cfbdbd56 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,6 +30,7 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(once_cell))] mod types; @@ -53,7 +54,7 @@ pub use tracing::{ use sp_std::boxed::Box; #[cfg(all(not(feature = "std"), feature = "with-tracing"))] -use once_cell::sync::OnceCell; +use core::lazy::OnceCell; pub use crate::types::{ WasmMetadata, WasmAttributes, WasmValuesSet, WasmValue, WasmFields, WasmEvent, WasmLevel, WasmFieldName From 8ef3f6acc9b6ed156ef495d6365be5f7dac05cf8 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 18 Aug 2020 16:58:10 +0200 Subject: [PATCH 048/113] global tracer for wasm side with pass over --- primitives/io/src/lib.rs | 33 ++++++--- primitives/tracing/src/lib.rs | 93 ++++++++++++++++---------- primitives/tracing/src/types.rs | 8 +-- primitives/tracing/src/wasm_tracing.rs | 14 ++-- 4 files changed, 90 insertions(+), 58 deletions(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 95e26189220c1..88f4687933254 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1002,22 +1002,32 @@ pub trait Logging { } #[derive(Encode, Decode)] +/// Crossing is a helper wrapping any Encode-Decodeable type +/// for transferring over the wasm barrier. pub struct Crossing(T); + impl PassBy for Crossing { type PassBy = sp_runtime_interface::pass_by::Codec; } +impl Crossing { + pub fn into_inner(self) -> T { + self.0 + } +} + + /// Interface that provides tracing functions #[runtime_interface] pub trait WasmTracing { fn enabled(&mut self, metadata: Crossing) -> bool { - let metadata : &tracing_core::metadata::Metadata<'static> = (&metadata.0).into(); + let metadata : &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); tracing::dispatcher::get_default(|d| { d.enabled(metadata) }) } fn new_span(&mut self, span: Crossing) -> u64 { - let span : tracing::Span = span.0.into(); + let span : tracing::Span = span.into_inner().into(); match span.id() { Some(id) => tracing::dispatcher::get_default(|d| { // inform dispatch that we'll keep the ID around @@ -1030,7 +1040,7 @@ pub trait WasmTracing { } fn event(&mut self, event: Crossing) { - event.0.emit(); + event.into_inner().emit(); } fn enter(&mut self, span: u64) { @@ -1052,7 +1062,7 @@ pub struct PassingTracingSubsciber; #[cfg(not(feature="std"))] impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { - wasm_tracing::enabled(Crossing(*metadata)) + wasm_tracing::enabled(Crossing(metadata.clone())) } fn new_span(&self, attrs: sp_tracing::WasmAttributes) -> u64 { wasm_tracing::new_span(Crossing(attrs)) @@ -1060,12 +1070,12 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn event(&self, parent_id: Option, metadata: &sp_tracing::WasmMetadata, - values: &sp_tracing::WasmValueSet + values: &sp_tracing::WasmValuesSet ) { - wasm_tracing::event(Crossing(WasmEvent { + wasm_tracing::event(Crossing(sp_tracing::WasmEvent { parent_id, metadata: metadata.clone(), - values: values.clone() + fields: values.clone() })) } fn enter(&self, span: u64) { @@ -1076,14 +1086,15 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { } } -#[cfg(all(no_std, feature="with-tracing"))] +#[cfg(all(not(feature="std"), feature="with-tracing"))] /// Initialize tracing of sp_tracing pub fn init_tracing() { - sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber())); + use sp_std::boxed::Box; + sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber {} )); } -#[cfg(not(all(no_std, feature="with-tracing")))] -/// Initialize tracing of sp_tracing – noop +#[cfg(not(all(not(feature="std"), feature="with-tracing")))] +/// Initialize tracing of sp_tracing not necessary – noop pub fn init_tracing() { } /// Wasm-only interface that provides functions for interacting with the sandbox. diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index fe7a1cfbdbd56..8dc71c4a5b109 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,7 +30,7 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(not(feature = "std"), feature(once_cell))] +#![cfg_attr(not(feature = "std"), feature(const_fn))] mod types; @@ -50,12 +50,6 @@ pub use tracing::{ span, event, Level, }; -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -use sp_std::boxed::Box; - -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -use core::lazy::OnceCell; - pub use crate::types::{ WasmMetadata, WasmAttributes, WasmValuesSet, WasmValue, WasmFields, WasmEvent, WasmLevel, WasmFieldName }; @@ -66,15 +60,63 @@ pub type Level = WasmLevel; pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: &WasmMetadata) -> bool; fn new_span(&self, attrs: WasmAttributes) -> u64; - fn record(&self, span: u64, values: &WasmValuesSet); fn event(&self, parent_id: Option, metadata: &WasmMetadata, values: &WasmValuesSet); fn enter(&self, span: u64); fn exit(&self, span: u64); } -/// Instance of the native subscriber in use + +#[cfg(all(not(feature = "std"), feature = "with-tracing"))] +mod global_subscription { + // Having a global subscription for WASM + use crate::TracingSubscriber; + use sp_std::{ + boxed::Box, + cell::UnsafeCell, + }; + + static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder::new(); + + struct SubscriptionHolder { + inner: UnsafeCell>> + } + + impl SubscriptionHolder { + const fn new() -> SubscriptionHolder { + SubscriptionHolder { inner: UnsafeCell::new(None) } + } + } + + unsafe impl core::marker::Sync for SubscriptionHolder {} + + /// NOTE: + /// theoretically this can panic when the subscriber instance is currently borrowed, + /// however this is guaranteed to not happen by us running in a threadless env + /// and never handing out the borrow + pub fn set_tracing_subscriber(subscriber: Box) + { + unsafe { + // Safety: Safe due to `inner`'s invariant + *SUBSCRIBER_INSTANCE.inner.get() = Some(subscriber) + } + } + + #[cfg(all(not(feature = "std"), feature = "with-tracing"))] + pub fn with_tracing_subscriber(f: F) -> Option + where F: FnOnce(&Box) -> R + { + unsafe { + // Safety: Safe due to `inner`'s invariant + match SUBSCRIBER_INSTANCE.inner.get().as_ref() { + Some(o) => o.as_ref().map(f), + _ => None + } + } + } +} + #[cfg(all(not(feature = "std"), feature = "with-tracing"))] -static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new(); +pub use global_subscription::{set_tracing_subscriber, with_tracing_subscriber}; /// Runs given code within a tracing span, measuring it's execution time. /// @@ -92,12 +134,12 @@ static SUBSCRIBER_INSTANCE: OnceCell> = OnceCell::new /// } /// /// sp_tracing::within_span! { -/// sp_tracing::span!(sp_tracing::Level::WARN, "warn-span", you_can_pass="any params"); +/// sp_tracing::span!(sp_tracing::Level::WARN, "warn-span", yo/u_can_pass="any params"); /// 1 + 1; /// // some other complex code /// } /// ``` -#[cfg(any(feature = "std", not(feature = "with-tracing")))] +#[cfg(any(feature = "std", feature = "with-tracing"))] #[macro_export] macro_rules! within_span { ( @@ -143,8 +185,8 @@ macro_rules! within_span { #[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] #[macro_export] macro_rules! enter_span { - ( $lvl:expr, $name:expr ) => { }, - ( $name:expr ) => { } // no-op + ( $lvl:expr, $name:expr ) => ( ); + ( $name:expr ) => ( ) // no-op } /// Enter a span. @@ -159,7 +201,7 @@ macro_rules! enter_span { /// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); /// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); /// ``` -#[cfg(any(feature = "std", not(feature = "with-tracing")))] +#[cfg(any(feature = "std", feature = "with-tracing"))] #[macro_export] macro_rules! enter_span { ( $span:expr ) => { @@ -170,25 +212,4 @@ macro_rules! enter_span { ( $lvl:expr, $name:expr ) => { $crate::enter_span!($crate::span!($crate::Level::TRACE, $name)) }; -} - -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -pub fn set_tracing_subscriber(subscriber: Box) { - let _ = SUBSCRIBER_INSTANCE.set(subscriber); -} - -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { - SUBSCRIBER_INSTANCE.get() -} - - -#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] -pub fn get_tracing_subscriber<'a>() -> Option<&'a Box> { - None -} - -#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] -pub fn set_tracing_subscriber(_subscriber: Box) { - unreachable!() } \ No newline at end of file diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index f0e172d69ad99..cd3bffde978ba 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -176,7 +176,7 @@ impl WasmFields { } } -#[derive(Encode, Decode, Debug)] +#[derive(Encode, Decode, Clone, Debug)] pub struct WasmValuesSet(Vec<(WasmFieldName, Option)>); impl From)>> for WasmValuesSet { @@ -204,7 +204,7 @@ impl WasmValuesSet { } -#[derive(Encode, Decode, Debug)] +#[derive(Encode, Decode, Clone, Debug)] pub struct WasmMetadata { pub name: Vec, pub target: Vec, @@ -216,14 +216,14 @@ pub struct WasmMetadata { pub fields: WasmFields, } -#[derive(Encode, Decode, Debug)] +#[derive(Encode, Decode, Clone, Debug)] pub struct WasmAttributes { pub parent_id: Option, pub metadata: WasmMetadata, pub fields: WasmValuesSet, } -#[derive(Encode, Decode, Debug)] +#[derive(Encode, Decode, Clone, Debug)] pub struct WasmEvent { pub parent_id: Option, pub metadata: WasmMetadata, diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 8993840d2e999..c1a710a6be4aa 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -86,7 +86,7 @@ mod inner { } pub fn enter(&self) -> Entered { if self.0 != 0 { - crate::get_tracing_subscriber().map(|t| t.enter(self.0)); + crate::with_tracing_subscriber(|t| t.enter(self.0)); } Entered(self.0) } @@ -99,7 +99,7 @@ mod inner { impl Entered { pub fn exit(&mut self) { if self.0 != 0 { - crate::get_tracing_subscriber().map(|t| t.exit(self.0)); + crate::with_tracing_subscriber(|t| t.exit(self.0)); } } } @@ -182,7 +182,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ), }; if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event( + $crate::with_tracing_subscriber(|t| t.event( Some($parent.0), &metadata, &$crate::valueset!(&metadata.fields, $($fields)*), @@ -227,7 +227,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - $crate::get_tracing_subscriber().map(|t| t.event( + $crate::with_tracing_subscriber(|t| t.event( None, &metadata, &$crate::valueset!(&metadata.fields, $($fields)*), @@ -392,7 +392,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - let span_id = $crate::get_tracing_subscriber().map(move |t| t.new_span( + let span_id = $crate::with_tracing_subscriber(move |t| t.new_span( WasmAttributes { parent_id: Some($parent.0), fields: $crate::valueset!(&metadata.fields, $($fields)*), @@ -426,7 +426,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - let span_id = $crate::get_tracing_subscriber().map(|t| t.new_span( + let span_id = $crate::with_tracing_subscriber(|t| t.new_span( WasmAttributes { parent_id: None, metadata, @@ -1964,7 +1964,7 @@ macro_rules! level_enabled { #[doc(hidden)] macro_rules! is_enabled { ($metadata:expr) => {{ - $crate::get_tracing_subscriber().map(|t| t.enabled(&$metadata)).unwrap_or(false) + $crate::with_tracing_subscriber(|t| t.enabled(&$metadata)).unwrap_or(false) }}; } From 7ec178477e7890ad9978d0533784e1f8124e1445 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 18 Aug 2020 17:20:39 +0200 Subject: [PATCH 049/113] fixing metadata referencing --- primitives/io/src/lib.rs | 3 ++- primitives/tracing/src/lib.rs | 4 ++-- primitives/tracing/src/wasm_tracing.rs | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 88f4687933254..f82e7b7189904 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1011,12 +1011,13 @@ impl PassBy for Crossing { } impl Crossing { + + /// Convert into the inner type pub fn into_inner(self) -> T { self.0 } } - /// Interface that provides tracing functions #[runtime_interface] pub trait WasmTracing { diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 8dc71c4a5b109..41ae8ed806232 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -134,7 +134,7 @@ pub use global_subscription::{set_tracing_subscriber, with_tracing_subscriber}; /// } /// /// sp_tracing::within_span! { -/// sp_tracing::span!(sp_tracing::Level::WARN, "warn-span", yo/u_can_pass="any params"); +/// sp_tracing::span!(sp_tracing::Level::WARN, "warn-span", you_can_pass="any params"); /// 1 + 1; /// // some other complex code /// } @@ -198,7 +198,7 @@ macro_rules! enter_span { /// /// ``` /// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); -/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); +/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); /// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); /// ``` #[cfg(any(feature = "std", feature = "with-tracing"))] diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index c1a710a6be4aa..f55ab735be27d 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -392,11 +392,11 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - let span_id = $crate::with_tracing_subscriber(move |t| t.new_span( + let span_id = $crate::with_tracing_subscriber(|t| t.new_span( WasmAttributes { parent_id: Some($parent.0), fields: $crate::valueset!(&metadata.fields, $($fields)*), - metadata, + metadata: metadata.clone(), }) ).unwrap_or_default(); $crate::Span::new(span_id) @@ -429,7 +429,7 @@ mod inner { let span_id = $crate::with_tracing_subscriber(|t| t.new_span( WasmAttributes { parent_id: None, - metadata, + metadata: metadata.clone(), fields: $crate::valueset!(&metadata.fields, $($fields)*) }) ).unwrap_or_default(); From 6f4ecb9cc5436ca25385fb1b22d518db0146a9bd Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 19 Aug 2020 11:12:59 +0200 Subject: [PATCH 050/113] remove const_fn feature requirement --- primitives/tracing/src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 41ae8ed806232..bbefe62054178 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -30,7 +30,6 @@ //! the associated Fields mentioned above. #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(not(feature = "std"), feature(const_fn))] mod types; @@ -75,17 +74,11 @@ mod global_subscription { cell::UnsafeCell, }; - static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder::new(); - struct SubscriptionHolder { inner: UnsafeCell>> } - impl SubscriptionHolder { - const fn new() -> SubscriptionHolder { - SubscriptionHolder { inner: UnsafeCell::new(None) } - } - } + static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder { inner: UnsafeCell::new(None) }; unsafe impl core::marker::Sync for SubscriptionHolder {} From f29ce39119d900be8a431dae76217c3eaa2d93d2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 20 Aug 2020 10:33:00 +0200 Subject: [PATCH 051/113] reenable dispatch traces --- frame/support/src/dispatch.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 52812b196ad45..0544d5b40281d 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1274,6 +1274,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); { $( $impl )* } } } @@ -1289,6 +1290,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize($param: $param_ty) -> $return { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); { $( $impl )* } } } @@ -1314,6 +1316,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_runtime_upgrade() -> $return { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade")); { $( $impl )* } } } @@ -1368,6 +1371,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); { $( $impl )* } } } @@ -1383,6 +1387,7 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize($param: $param_ty) { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); { $( $impl )* } } } @@ -1451,6 +1456,7 @@ macro_rules! decl_module { $vis fn $name( $origin: $origin_ty $(, $param: $param_ty )* ) -> $crate::dispatch::DispatchResult { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); { $( $impl )* } Ok(()) } @@ -1469,6 +1475,7 @@ macro_rules! decl_module { ) => { $(#[$fn_attr])* $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); $( $impl )* } }; From a1e8284fec5bc90758f7c8515be84700bf6e65f7 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 20 Aug 2020 11:06:40 +0200 Subject: [PATCH 052/113] reset client tracing --- client/tracing/src/lib.rs | 92 ++++++--------------------------------- 1 file changed, 13 insertions(+), 79 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 3db289219c43f..c8aeab1fdafd0 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -26,7 +26,6 @@ use rustc_hash::FxHashMap; use std::fmt; -use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{Duration, Instant}; @@ -43,28 +42,9 @@ use tracing::{ use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; -use sp_tracing::types::{ - WasmLevel, - WasmFieldValue, - WasmFields, - WasmValues, - WasmMetadata, - WasmAttributes, - WasmEvent, -}; +use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); -const UNABLE_TO_DECODE: &'static str = "Unable to decode"; - -/// Responsible for assigning ids to new spans, which are not re-used. -#[derive(Clone)] -pub struct ProfilingSubscriber { - next_id: Arc, - targets: Arc>>, - trace_handler: Arc, - span_data: Arc>>, - current_span: Arc, -} /// Responsible for assigning ids to new spans, which are not re-used. pub struct ProfilingSubscriber { @@ -142,8 +122,6 @@ pub struct Values { pub u64_values: FxHashMap, /// HashMap of `String` values pub string_values: FxHashMap, - /// HashMap of `String` values - pub encoded_values: FxHashMap>, } impl Values { @@ -157,17 +135,7 @@ impl Values { self.bool_values.is_empty() && self.i64_values.is_empty() && self.u64_values.is_empty() && - self.string_values.is_empty() && - self.encoded_values.is_empty() - } - - /// Extend self with other - pub fn extend(&mut self, other: Values) { - self.bool_values.extend(other.bool_values.into_iter()); - self.i64_values.extend(other.i64_values.into_iter()); - self.u64_values.extend(other.u64_values.into_iter()); - self.string_values.extend(other.string_values.into_iter()); - self.encoded_values.extend(other.encoded_values.into_iter()); + self.string_values.is_empty() } } @@ -221,13 +189,7 @@ impl fmt::Display for Values { let i64_iter = self.i64_values.iter().map(|(k, v)| format!("{}={}", k, v)); let u64_iter = self.u64_values.iter().map(|(k, v)| format!("{}={}", k, v)); let string_iter = self.string_values.iter().map(|(k, v)| format!("{}=\"{}\"", k, v)); - let encoded_iter = self.encoded_values.iter().map(|(k, v)| format!("{}={:?}", k, v)); - let values = bool_iter - .chain(i64_iter) - .chain(u64_iter) - .chain(string_iter) - .chain(encoded_iter) - .collect::>().join(", "); + let values = bool_iter.chain(i64_iter).chain(u64_iter).chain(string_iter).collect::>().join(", "); write!(f, "{}", values) } } @@ -260,9 +222,9 @@ impl ProfilingSubscriber { /// wasm_tracing indicates whether to enable wasm traces pub fn new(receiver: TracingReceiver, targets: &str) -> ProfilingSubscriber { match receiver { - TracingReceiver::Log => Self::new_with_handler(Arc::new(LogTraceHandler), targets), + TracingReceiver::Log => Self::new_with_handler(Box::new(LogTraceHandler), targets), TracingReceiver::Telemetry => Self::new_with_handler( - Arc::new(TelemetryTraceHandler), + Box::new(TelemetryTraceHandler), targets, ), } @@ -273,13 +235,13 @@ impl ProfilingSubscriber { /// either with a level, eg: "pallet=trace" /// or without: "pallet" in which case the level defaults to `trace`. /// wasm_tracing indicates whether to enable wasm traces - pub fn new_with_handler(trace_handler: Arc, targets: &str) - -> ProfilingSubscriber + pub fn new_with_handler(trace_handler: Box, targets: &str) + -> ProfilingSubscriber { let targets: Vec<_> = targets.split(',').map(|s| parse_target(s)).collect(); ProfilingSubscriber { - next_id: Arc::new(AtomicU64::new(1)), - targets: Arc::new(Mutex::new(targets)), + next_id: AtomicU64::new(1), + targets, trace_handler, span_data: Mutex::new(FxHashMap::default()), current_span: Default::default() @@ -287,7 +249,7 @@ impl ProfilingSubscriber { } fn check_target(&self, target: &str, level: &Level) -> bool { - for t in &*self.targets.lock() { + for t in &self.targets { if target.starts_with(t.0.as_str()) && level <= &t.1 { return true; } @@ -313,37 +275,9 @@ fn parse_target(s: &str) -> (String, Level) { } } -impl From for Values { - fn from(fields: WasmValues) -> Self { - let mut values = Values::default(); - for (k, v) in fields { - if let Ok(key) = String::from_utf8(k) { - match v { - WasmFieldValue::Bool(v) => { values.bool_values.insert(key, v); } - WasmFieldValue::I64(v) => { values.i64_values.insert(key, v); }, - WasmFieldValue::U64(v) => { values.u64_values.insert(key, v); }, - WasmFieldValue::Str(v) => { - let s = String::from_utf8(v).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()); - values.string_values.insert(key, s); - } - WasmFieldValue::Debug(v) => { - let s = String::from_utf8(v).unwrap_or_else(|_| UNABLE_TO_DECODE.to_owned()); - values.string_values.insert(key, s); - } - WasmFieldValue::Encoded(v) => { - values.encoded_values.insert(key, v); - } - } - } - } - values - } -} - - impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if self.check_target(metadata.target(), metadata.level()) { + if metadata.target() == WASM_TRACE_IDENTIFIER || self.check_target(metadata.target(), metadata.level()) { log::debug!(target: "tracing", "Enabled target: {}, level: {}", metadata.target(), metadata.level()); true } else { @@ -418,7 +352,7 @@ impl Subscriber for ProfilingSubscriber { } fn try_close(&self, span: Id) -> bool { - if let Some(span_datum) = { + let span_datum = { let mut span_data = self.span_data.lock(); span_data.remove(&span) }; @@ -548,7 +482,7 @@ mod tests { }; let test_subscriber = ProfilingSubscriber::new_with_handler( Box::new(handler), - "test_target", + "test_target" ); (test_subscriber, spans, events) } From f4c90766f436fe5a2b1fd342cda2b7df93e54494 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 20 Aug 2020 11:06:49 +0200 Subject: [PATCH 053/113] further cleaning up --- client/executor/runtime-test/src/lib.rs | 4 ++-- client/transaction-pool/src/api.rs | 2 +- primitives/tracing/src/lib.rs | 7 +++++++ primitives/tracing/src/types.rs | 26 +++++++++++++------------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index a80ee1d6ba40f..3b00061e2af66 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -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::new_span("integration_test_span_target", "integration_test_span_name") } fn test_exit_span(span_id: u64) { - wasm_tracing::exit_span(span_id) + wasm_tracing::exit(span_id) } fn returns_mutable_static() -> u64 { diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index 6296dcc21c569..712a7e156abce 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -184,7 +184,7 @@ where } else { #[allow(deprecated)] // old validate_transaction runtime_api.validate_transaction_before_version_2(&at, uxt) - }; + } }); res.map_err(|e| Error::RuntimeApi(e.to_string())) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index bbefe62054178..ece4dd7e670b5 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -52,9 +52,16 @@ pub use tracing::{ pub use crate::types::{ WasmMetadata, WasmAttributes, WasmValuesSet, WasmValue, WasmFields, WasmEvent, WasmLevel, WasmFieldName }; + +#[cfg(feature = "std")] +pub use crate::types::{ + WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER +}; + #[cfg(not(feature = "std"))] pub type Level = WasmLevel; + #[cfg(not(feature = "std"))] pub trait TracingSubscriber: Send + Sync { fn enabled(&self, metadata: &WasmMetadata) -> bool; diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index cd3bffde978ba..40ddf1bf7cbad 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -247,64 +247,66 @@ mod std_features { fn metadata(&self) -> &tracing_core::Metadata { unimplemented!() } } static CALLSITE: WasmCallsite = WasmCallsite; - static WASM_TRACING_NAME: &'static str = "wasm_tracing"; - static GENERIC_FIELDS: &'static [&'static str] = &["target", "name", "file", "line", "module_path", "params"]; + pub static WASM_TRACE_IDENTIFIER: &'static str = "wasm_tracing"; + pub static WASM_NAME_KEY: &'static str = "name"; + pub static WASM_TARGET_KEY: &'static str = "target"; + pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, "file", "line", "module_path", "params"]; static SPAN_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::ERROR, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::SPAN ); static SPAN_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::WARN, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::SPAN ); static SPAN_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::INFO, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::SPAN ); static SPAN_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::DEBUG, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::SPAN ); static SPAN_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::TRACE, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::SPAN ); static EVENT_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::ERROR, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::EVENT ); static EVENT_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::WARN, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::EVENT ); static EVENT_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::INFO, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::EVENT ); static EVENT_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::DEBUG, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::EVENT ); static EVENT_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACING_NAME, WASM_TRACING_NAME, tracing::Level::TRACE, None, None, None, + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), tracing_core::metadata::Kind::EVENT ); From bc4b6b0bf0ddcbaa40147118c2857da164ed7961 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 21 Aug 2020 12:31:15 +0200 Subject: [PATCH 054/113] fixing runtime-test --- client/executor/runtime-test/Cargo.toml | 2 ++ client/executor/runtime-test/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/executor/runtime-test/Cargo.toml b/client/executor/runtime-test/Cargo.toml index 037359ac9eef6..dddbb780ca808 100644 --- a/client/executor/runtime-test/Cargo.toml +++ b/client/executor/runtime-test/Cargo.toml @@ -29,5 +29,7 @@ std = [ "sp-io/std", "sp-sandbox/std", "sp-std/std", + "sp-core/std", + "sp-runtime/std", "sp-allocator/std", ] diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index 3b00061e2af66..fa24f6cbaa8fb 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -253,8 +253,8 @@ sp_core::wasm_export_functions! { sp_allocator::FreeingBumpHeapAllocator::new(0); } - fn test_enter_span() -> u64 { - wasm_tracing::new_span("integration_test_span_target", "integration_test_span_name") + fn test_enter_span() { + wasm_tracing::enter(0) } fn test_exit_span(span_id: u64) { From 99fcfc8d8f34f1ded95e23128ec4b346f8504b7e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 21 Aug 2020 12:32:53 +0200 Subject: [PATCH 055/113] move tracing-build setup into runtime-test --- bin/node/runtime/build.rs | 11 +---------- client/executor/runtime-test/build.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bin/node/runtime/build.rs b/bin/node/runtime/build.rs index c45de46dba96f..a2f09a460e69d 100644 --- a/bin/node/runtime/build.rs +++ b/bin/node/runtime/build.rs @@ -23,14 +23,5 @@ fn main() { .with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder") .export_heap_base() .import_memory() - .build(); - - 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(); + .build() } diff --git a/client/executor/runtime-test/build.rs b/client/executor/runtime-test/build.rs index 1ed5aa44bc5c4..cf4fca01acd9f 100644 --- a/client/executor/runtime-test/build.rs +++ b/client/executor/runtime-test/build.rs @@ -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(); } From 001b0649506eae24c7123f3458d07ccc4c19f462 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 21 Aug 2020 19:31:42 +0200 Subject: [PATCH 056/113] Merge DebugWriter from tracing and frame-support, move to sp-std --- frame/support/src/debug.rs | 25 ++++--------------------- primitives/std/src/lib.rs | 25 ++++++++++++++++++++++++- primitives/tracing/src/types.rs | 13 +++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/frame/support/src/debug.rs b/frame/support/src/debug.rs index e4a48068460c6..3c4422b71ac23 100644 --- a/frame/support/src/debug.rs +++ b/frame/support/src/debug.rs @@ -92,6 +92,7 @@ use sp_std::fmt::{self, Debug}; pub use log::{info, debug, error, trace, warn}; pub use crate::runtime_print as print; +pub use sp_std::Writer; /// Native-only logging. /// @@ -132,9 +133,9 @@ macro_rules! runtime_print { ($($arg:tt)+) => { { use core::fmt::Write; - let mut w = $crate::debug::Writer::default(); + let mut w = $crate::sp_core::Writer::default(); let _ = core::write!(&mut w, $($arg)+); - w.print(); + sp_io::misc::print_utf8(&w.inner()) } } } @@ -144,24 +145,6 @@ pub fn debug(data: &impl Debug) { runtime_print!("{:?}", data); } -/// A target for `core::write!` macro - constructs a string in memory. -#[derive(Default)] -pub struct Writer(Vec); - -impl fmt::Write for Writer { - fn write_str(&mut self, s: &str) -> fmt::Result { - self.0.extend(s.as_bytes()); - Ok(()) - } -} - -impl Writer { - /// Print the content of this `Writer` out. - pub fn print(&self) { - sp_io::misc::print_utf8(&self.0) - } -} - /// Runtime logger implementation - `log` crate backend. /// /// The logger should be initialized if you want to display @@ -210,7 +193,7 @@ impl log::Log for RuntimeLogger { sp_io::logging::log( record.level().into(), record.target(), - &w.0, + &w.inner(), ); } diff --git a/primitives/std/src/lib.rs b/primitives/std/src/lib.rs index 8ff1efc63d8df..b323c43720da1 100644 --- a/primitives/std/src/lib.rs +++ b/primitives/std/src/lib.rs @@ -20,7 +20,6 @@ #![cfg_attr(not(feature = "std"), no_std)] - #![cfg_attr(feature = "std", doc = "Substrate runtime standard library as compiled when linked with Rust's standard library.")] #![cfg_attr(not(feature = "std"), @@ -65,6 +64,30 @@ include!("../with_std.rs"); #[cfg(not(feature = "std"))] include!("../without_std.rs"); + +/// A target for `core::write!` macro - constructs a string in memory. +#[derive(Default)] +pub struct Writer(vec::Vec); + +impl fmt::Write for Writer { + fn write_str(&mut self, s: &str) -> fmt::Result { + self.0.extend(s.as_bytes()); + Ok(()) + } +} + +impl Writer { + /// Access the content of this `Writer` e.g. for printout + pub fn inner(&self) -> &vec::Vec { + &self.0 + } + + /// Convert into the content of this `Writer` + pub fn into_inner(self) -> vec::Vec { + self.0 + } +} + /// Prelude of common useful imports. /// /// This should include only things which are in the normal std prelude. diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 40ddf1bf7cbad..cd42355efd0fc 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -19,6 +19,7 @@ use core::fmt::Debug; use sp_std::{ vec::Vec, }; +use sp_std::Writer; use codec::{Encode, Decode}; #[derive(Clone, Encode, Decode, Debug)] @@ -74,19 +75,11 @@ impl From for WasmValue { } } -struct DebugWriter(Vec); -impl core::fmt::Write for DebugWriter { - fn write_str(&mut self, s: &str) -> core::result::Result<(), core::fmt::Error> { - self.0.extend_from_slice(s.as_bytes()); - Ok(()) - } -} - impl From<&core::fmt::Arguments<'_>> for WasmValue { fn from(inp: &core::fmt::Arguments<'_>) -> WasmValue { - let mut buf = DebugWriter(Vec::new()); + let mut buf = Writer::default(); core::fmt::write(&mut buf, *inp).expect("Writing of arguments doesn't fail"); - WasmValue::Formatted(buf.0) + WasmValue::Formatted(buf.into_inner()) } } From 564f88c0fed7f24acea38ccc8c7e675c092d58db Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 21 Aug 2020 19:33:10 +0200 Subject: [PATCH 057/113] remove dangling fixme --- primitives/tracing/src/types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index cd42355efd0fc..8a87ec8423afc 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -179,7 +179,6 @@ impl From)>> for WasmValuesSet { } impl From)>> for WasmValuesSet { fn from(v: Vec<(&&WasmFieldName, Option)>) -> Self { - // FIXME: remove this clone! WasmValuesSet(v.into_iter().map(|(k, v)| ((**k).clone(), v)).collect()) } } From bad9ad031dee6cea9f1c8acb937aa4c1c7768f36 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 24 Aug 2020 10:04:51 +0200 Subject: [PATCH 058/113] Docs for tracing primitives --- frame/support/src/debug.rs | 5 +- primitives/io/src/lib.rs | 12 +-- primitives/tracing/Cargo.toml | 2 +- primitives/tracing/src/lib.rs | 122 ++++++++++++++++++++++--- primitives/tracing/src/types.rs | 77 +++++++++++----- primitives/tracing/src/wasm_tracing.rs | 20 ++-- 6 files changed, 186 insertions(+), 52 deletions(-) diff --git a/frame/support/src/debug.rs b/frame/support/src/debug.rs index 3c4422b71ac23..6cd06cc2e739c 100644 --- a/frame/support/src/debug.rs +++ b/frame/support/src/debug.rs @@ -87,7 +87,6 @@ //! native::print!("My struct: {:?}", x); //! ``` -use sp_std::vec::Vec; use sp_std::fmt::{self, Debug}; pub use log::{info, debug, error, trace, warn}; @@ -133,7 +132,7 @@ macro_rules! runtime_print { ($($arg:tt)+) => { { use core::fmt::Write; - let mut w = $crate::sp_core::Writer::default(); + let mut w = $crate::sp_std::Writer::default(); let _ = core::write!(&mut w, $($arg)+); sp_io::misc::print_utf8(&w.inner()) } @@ -187,7 +186,7 @@ impl log::Log for RuntimeLogger { fn log(&self, record: &log::Record) { use fmt::Write; - let mut w = Writer::default(); + let mut w = sp_std::Writer::default(); let _ = core::write!(&mut w, "{}", record.args()); sp_io::logging::log( diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index f82e7b7189904..0d3db3b8e68e2 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1027,7 +1027,7 @@ pub trait WasmTracing { d.enabled(metadata) }) } - fn new_span(&mut self, span: Crossing) -> u64 { + fn new_span(&mut self, span: Crossing) -> u64 { let span : tracing::Span = span.into_inner().into(); match span.id() { Some(id) => tracing::dispatcher::get_default(|d| { @@ -1039,8 +1039,8 @@ pub trait WasmTracing { } } } - - fn event(&mut self, event: Crossing) { + + fn event(&mut self, event: Crossing) { event.into_inner().emit(); } @@ -1065,15 +1065,15 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { wasm_tracing::enabled(Crossing(metadata.clone())) } - fn new_span(&self, attrs: sp_tracing::WasmAttributes) -> u64 { + fn new_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { wasm_tracing::new_span(Crossing(attrs)) } fn event(&self, parent_id: Option, - metadata: &sp_tracing::WasmMetadata, + metadata: &sp_tracing::WasmMetadata, values: &sp_tracing::WasmValuesSet ) { - wasm_tracing::event(Crossing(sp_tracing::WasmEvent { + wasm_tracing::event(Crossing(sp_tracing::WasmEntryAttributes { parent_id, metadata: metadata.clone(), fields: values.clone() diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 2a524cb57efc5..2bbabdd54343f 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "Instrumentation primitives and macros for Substrate." [package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] sp-std = { version = "2.0.0-rc6", path = "../std", default-features = false} diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index ece4dd7e670b5..f2dce385aca5f 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -31,6 +31,62 @@ #![cfg_attr(not(feature = "std"), no_std)] +/// Tracing facilities and helpers. +/// +/// This is modeled after the `tracing`/`tracing-core` interface and uses that more or +/// less directly for the native side. Because of certain optimisations the these crates +/// have done, the wasm implementation diverges slightly and is optimised for thtat use +/// case (like being able to cross the wasm/native boundary via scale codecs). +/// +/// One of said optimisations is that all macros will yield to a `noop` in non-std unless +/// the `with-tracing` feature is explicitly activated. This allows you to just use the +/// tracing wherever you deem fit and without any performance impact by default. Only if +/// the specific `with-tracing`-feature is activated on this crate will it actually include +/// the tracing code in the non-std environment. +/// +/// Because of that optimisation, you should not use the `span!` and `span_*!` macros +/// directly as they yield nothing without the feature present. Instead you should use +/// `enter_span!` and `within_span!` – which would strip away even any parameter conversion +/// you do within the span-definition (and thus optimise your performance). For your +/// convineience you directly specify the `Level` and name of the span or use the full +/// feature set of `span!`/`span_*!` on it: +/// +/// # Example +/// +/// ```rust +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "fn wide span"); +/// { +/// sp_tracing::enter_span!(sp_tracing::trace_span!("outer-span")); +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); +/// // .. +/// } // inner span exists here +/// } // outer span exists here +/// +/// sp_tracing::within_span! { +/// sp_tracing::debug_span!("debug-span", you_can_pass="any params"); +/// 1 + 1; +/// // some other complex code +/// } // debug span ends here +/// +/// ``` +/// +/// +/// # Setup +/// +/// This project only provides the macros and facilities to manage tracing +/// it doesn't implement the tracing subscriber or backend directly – that is +/// up to the developer integrating it into a specific environment. In native +/// this can and must be done through the regular `tracing`-facitilies, please +/// see their documentation for details. +/// +/// On the wasm-side we've adopted a similar approach of having a global +/// `TracingSubscriber` that the macros call and that does the actual work +/// of tracking. To provide your tracking, you must implement `TracingSubscriber` +/// and call `set_tracing_subscriber` at the very beginning of your execution – +/// the default subscriber is doing nothing, so any spans or events happening before +/// will not be recorded! + mod types; #[cfg(not(feature = "std"))] @@ -50,7 +106,7 @@ pub use tracing::{ }; pub use crate::types::{ - WasmMetadata, WasmAttributes, WasmValuesSet, WasmValue, WasmFields, WasmEvent, WasmLevel, WasmFieldName + WasmMetadata, WasmEntryAttributes, WasmValuesSet, WasmValue, WasmFields, WasmLevel, WasmFieldName }; #[cfg(feature = "std")] @@ -61,13 +117,30 @@ pub use crate::types::{ #[cfg(not(feature = "std"))] pub type Level = WasmLevel; - +/// Defines the interface for the wasm-side tracing subcriber. This is +/// very much modeled after the `tracing_core::Subscriber`, but adapted +/// to be feasible to cross the wasm-native boundary. +/// +/// This is generally expected to be a proxy that moves the data over to +/// the native side as tracking within `wasm` is probably ineffecient. However +/// any implementation may do internal optimisations for performance. +/// #[cfg(not(feature = "std"))] pub trait TracingSubscriber: Send + Sync { + /// Give the `WasmMetadata`, should we even continue recording this span/event + /// or stop execution before. + /// This may or may not be implemented wasm- and/or native side or have optimisations + /// added. fn enabled(&self, metadata: &WasmMetadata) -> bool; - fn new_span(&self, attrs: WasmAttributes) -> u64; + /// Create a new `Span` with the given `WasmEntryAttributes`, return the u64 tracking ID for + /// it. Will only be called if `attrs.metadata` was found to be enabled. + fn new_span(&self, attrs: WasmEntryAttributes) -> u64; + /// Record the `WasmValueSet` for `WasMetadata` as a new event. Willl only be called if + /// `WasmMetadata` was found to be enabled; fn event(&self, parent_id: Option, metadata: &WasmMetadata, values: &WasmValuesSet); + /// Mark the given `span` to be entered. A span may not be entered twice. fn enter(&self, span: u64); + /// Exit the given span. You can discard the span info now. fn exit(&self, span: u64); } @@ -89,10 +162,14 @@ mod global_subscription { unsafe impl core::marker::Sync for SubscriptionHolder {} - /// NOTE: - /// theoretically this can panic when the subscriber instance is currently borrowed, - /// however this is guaranteed to not happen by us running in a threadless env - /// and never handing out the borrow + /// Set the given `TracingSubscriber` as target for the tracing spans. + /// This should happen first, any span and event calls run before are not recorded. + /// + /// **IMPORTANT**: + /// This uses unsafe features to provide a lazily-set instance-wide global. This is not + /// thread-safe and will panic if called from withina `with_tracing_subscriber`-call. + /// + /// See module index documentation for how to set the system up properly. pub fn set_tracing_subscriber(subscriber: Box) { unsafe { @@ -101,6 +178,10 @@ mod global_subscription { } } + /// Gain access to the globally set `TracingSubscriber`. + /// Used to record events and spans. + /// *IMPORTANT*: do not call `set_tracing_subscriber` from within. That will lead + /// to undefined behaviour. #[cfg(all(not(feature = "std"), feature = "with-tracing"))] pub fn with_tracing_subscriber(f: F) -> Option where F: FnOnce(&Box) -> R @@ -120,14 +201,14 @@ pub use global_subscription::{set_tracing_subscriber, with_tracing_subscriber}; /// Runs given code within a tracing span, measuring it's execution time. /// -/// If tracing is not enabled, the code is still executed. Pass in level and name before followed -/// by `;` and the code to execute, or use any valid `sp_tracing::Span`. +/// If tracing is not enabled, the code is still executed. Pass in level and name or +/// use any valid `sp_tracing::Span`followe by `;` and the code to execute, /// /// # Example /// /// ``` /// sp_tracing::within_span! { -/// sp_tracing::Level::TRACE, +/// sp_tracing::Level::TRACE, /// "test-span"; /// 1 + 1; /// // some other complex code @@ -138,6 +219,12 @@ pub use global_subscription::{set_tracing_subscriber, with_tracing_subscriber}; /// 1 + 1; /// // some other complex code /// } +/// +/// sp_tracing::within_span! { +/// sp_tracing::debug_span!("debug-span", you_can_pass="any params"); +/// 1 + 1; +/// // some other complex code +/// } /// ``` #[cfg(any(feature = "std", feature = "with-tracing"))] #[macro_export] @@ -192,7 +279,11 @@ macro_rules! enter_span { /// Enter a span. /// /// The span will be valid, until the scope is left. Use either level and name -/// or pass in any valid `sp_tracing::Span` for extended usage. +/// or pass in any valid `sp_tracing::Span` for extended usage. The span will +/// be exited on drop – which is at the end of the block or to the next +/// `enter_span!` calls, as this overwrites the local variable. For nested +/// usage or to ensure the span closes at certain time either put it into a block +/// or use `within_span!` /// /// # Example /// @@ -200,6 +291,15 @@ macro_rules! enter_span { /// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); /// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); /// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); +/// +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "outer-span"); +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); +/// // .. +/// } // inner span exists here +/// } // outer span exists here +/// /// ``` #[cfg(any(feature = "std", feature = "with-tracing"))] #[macro_export] diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 8a87ec8423afc..e0db54e9f17a8 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -15,6 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +/// Types for wasm based tracing. Loosly inspired by `tracing-core` but +/// optimised for the specific use case. + use core::fmt::Debug; use sp_std::{ vec::Vec, @@ -22,15 +25,22 @@ use sp_std::{ use sp_std::Writer; use codec::{Encode, Decode}; +/// The Tracing Level – the user can filter by this #[derive(Clone, Encode, Decode, Debug)] pub enum WasmLevel { + /// This is a fatal errors ERROR, + /// This is a warning you should be aware of WARN, + /// Nice to now info INFO, + /// Further information for debugging purposes DEBUG, + /// The lowest level, keeping track of minute detail TRACE } +/// A paramter value provided to the span/event #[derive(Encode, Decode, Clone, Debug)] pub enum WasmValue { U8(u8), @@ -41,7 +51,10 @@ pub enum WasmValue { U64(u64), Bool(bool), Str(Vec), + /// Debug or Display call, this is most-likely a print-able UTF8 String Formatted(Vec), + /// SCALE CODEC encoded object – the name should allow the received to know + /// how to decode this. Encoded(Vec), } @@ -125,6 +138,10 @@ impl From for WasmValue { } } +/// The name of a field provided as the argument name when contstructing an +/// `event!` or `span!`. +/// Generally generated automaticaly via `stringify` from an `'static &str`. +/// Likely print-able. #[derive(Encode, Decode, Clone, Debug)] pub struct WasmFieldName(Vec); @@ -141,7 +158,7 @@ impl From<&str> for WasmFieldName { } } - +/// A list of `WasmFieldName`s in the order provided #[derive(Encode, Decode, Clone, Debug)] pub struct WasmFields(Vec); @@ -164,11 +181,15 @@ impl From> for WasmFields { } impl WasmFields { + /// Create an empty entry pub fn empty() -> Self { WasmFields(Vec::with_capacity(0)) } } + +/// A list of `WasmFieldName`s with the given `WasmValue` (if provided) +/// in the order specified. #[derive(Encode, Decode, Clone, Debug)] pub struct WasmValuesSet(Vec<(WasmFieldName, Option)>); @@ -190,60 +211,73 @@ impl From)>> for WasmValuesSet { } impl WasmValuesSet { + /// Create an empty entry pub fn empty() -> Self { WasmValuesSet(Vec::with_capacity(0)) } } - +/// Metadata provides generic information about the specifc location of the +/// `span!` or `event!` call on the wasm-side. #[derive(Encode, Decode, Clone, Debug)] pub struct WasmMetadata { + /// The name given to `event!`/`span!`, `&'static str` converted to bytes pub name: Vec, + /// The given target to `event!`/`span!` – or module-name, `&'static str` converted to bytes pub target: Vec, + /// The level of this entry pub level: WasmLevel, + /// The file this was emitted from – useful for debugging; `&'static str` converted to bytes pub file: Vec, + /// The specific line number in the file – useful for debugging pub line: u32, + /// The module path; `&'static str` converted to bytes pub module_path: Vec, + /// Whether this is a call to `span!` or `event!` pub is_span: bool, + /// The list of fields specified in the call pub fields: WasmFields, } +/// Span or Event Attributes #[derive(Encode, Decode, Clone, Debug)] -pub struct WasmAttributes { +pub struct WasmEntryAttributes { + /// the parent, if directly specified – otherwise assume most inner span pub parent_id: Option, + /// the metadata of the location pub metadata: WasmMetadata, + /// the Values provided pub fields: WasmValuesSet, } -#[derive(Encode, Decode, Clone, Debug)] -pub struct WasmEvent { - pub parent_id: Option, - pub metadata: WasmMetadata, - pub fields: WasmValuesSet, -} - -// TODO - Do we need this when we have WasmValuesSet ? -// #[derive(Encode, Decode)] -// pub struct WasmRecord; - - #[cfg(feature = "std")] mod std_features { use tracing_core::callsite; use tracing; + /// Static entry use for wasm-originated metadata. pub struct WasmCallsite; impl callsite::Callsite for WasmCallsite { fn set_interest(&self, _: tracing_core::Interest) { unimplemented!() } fn metadata(&self) -> &tracing_core::Metadata { unimplemented!() } } static CALLSITE: WasmCallsite = WasmCallsite; + /// The identifier we are using to inject the wasm events in the generic `tracing` system pub static WASM_TRACE_IDENTIFIER: &'static str = "wasm_tracing"; + /// The fieldname for the wasm-originated name pub static WASM_NAME_KEY: &'static str = "name"; + /// The fieldname for the wasm-originated target pub static WASM_TARGET_KEY: &'static str = "target"; + /// The the list of all static field names we construct from the given metadata pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, "file", "line", "module_path", "params"]; + // Implementation Note: + // the original `tracing` crate generates these static metadata entries at every `span!` and + // `event!` location to allow for highly optimised filtering. For us to allow level-based emitting + // of wasm events we need these static metadata entries to inject into that system. We then provide + // generic `From`-implementations picking the right metadata to refer to. + static SPAN_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), @@ -320,8 +354,8 @@ mod std_features { } } - impl From for tracing::Span { - fn from(a: crate::WasmAttributes) -> tracing::Span { + impl From for tracing::Span { + fn from(a: crate::WasmEntryAttributes) -> tracing::Span { let name = std::str::from_utf8(&a.metadata.name).unwrap_or_default(); let target = std::str::from_utf8(&a.metadata.target).unwrap_or_default(); let file = std::str::from_utf8(&a.metadata.file).unwrap_or_default(); @@ -331,15 +365,16 @@ mod std_features { let metadata : &tracing_core::metadata::Metadata<'static> = (&a.metadata).into(); tracing::span::Span::child_of( - a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), &metadata, &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } ) } } - impl crate::WasmEvent { - pub fn emit(self: crate::WasmEvent) { + impl crate::WasmEntryAttributes { + /// convert the given Attributes to an event and emit it using `tracing_core`. + pub fn emit(self: crate::WasmEntryAttributes) { let name = std::str::from_utf8(&self.metadata.name).unwrap_or_default(); let target = std::str::from_utf8(&self.metadata.target).unwrap_or_default(); let file = std::str::from_utf8(&self.metadata.file).unwrap_or_default(); @@ -349,7 +384,7 @@ mod std_features { let metadata : &tracing_core::metadata::Metadata<'static> = (&self.metadata).into(); tracing_core::Event::child_of( - self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), &metadata, &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } ) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index f55ab735be27d..a6f2c78c44bf0 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -93,7 +93,7 @@ mod inner { pub fn in_scope T, T>(&self, f: F) -> T { let _enter = self.enter(); f() - } + } } impl Entered { @@ -104,7 +104,7 @@ mod inner { } } - impl Drop for Entered { + impl Drop for Entered { fn drop(&mut self) { self.exit(); } @@ -164,7 +164,7 @@ mod inner { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet }; let metadata = WasmMetadata { name: concat!( @@ -209,7 +209,7 @@ mod inner { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet }; let metadata = WasmMetadata { name: concat!( @@ -379,7 +379,7 @@ mod inner { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), @@ -393,7 +393,7 @@ mod inner { }; if $crate::is_enabled!(&metadata) { let span_id = $crate::with_tracing_subscriber(|t| t.new_span( - WasmAttributes { + WasmEntryAttributes { parent_id: Some($parent.0), fields: $crate::valueset!(&metadata.fields, $($fields)*), metadata: metadata.clone(), @@ -413,7 +413,7 @@ mod inner { if $crate::level_enabled!($lvl) { #[allow(unused_imports)] use $crate::{ - WasmMetadata, WasmAttributes, WasmEvent, WasmFields, WasmFieldName, WasmValuesSet + WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet }; let metadata = WasmMetadata { name: $name.as_bytes().to_vec(), @@ -427,7 +427,7 @@ mod inner { }; if $crate::is_enabled!(&metadata) { let span_id = $crate::with_tracing_subscriber(|t| t.new_span( - WasmAttributes { + WasmEntryAttributes { parent_id: None, metadata: metadata.clone(), fields: $crate::valueset!(&metadata.fields, $($fields)*) @@ -1955,7 +1955,7 @@ macro_rules! level_enabled { // FIXME: use the runtime interface to figure this out true // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL - + }; } @@ -2082,7 +2082,7 @@ macro_rules! valueset { }; ($fields:expr,) => ( WasmValuesSet::empty() - + ); } From 29c9da7f92bf6ee70bc8d1bcf5c8eba49e2f7021 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 24 Aug 2020 10:26:31 +0200 Subject: [PATCH 059/113] cleaning up a bit more --- frame/executive/src/lib.rs | 20 ++++++++++---------- frame/support/src/debug.rs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 76e7354ab5da1..1d55cbc049b10 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -419,21 +419,21 @@ where source: TransactionSource, uxt: Block::Extrinsic, ) -> TransactionValidity { - use sp_tracing::within_span; + use sp_tracing::{enter_span, within_span}; - within_span!{ sp_tracing::Level::TRACE, "validate_transaction"; { - - let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; + enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" }; - let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; + let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; - let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; + let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; - within_span! { - sp_tracing::Level::TRACE, "validate"; - xt.validate::(source, &dispatch_info, encoded_len) + let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; + + within_span! { + sp_tracing::Level::TRACE, "validate"; + xt.validate::(source, &dispatch_info, encoded_len) } - } } + } } /// Start an offchain worker and generate extrinsics. diff --git a/frame/support/src/debug.rs b/frame/support/src/debug.rs index 6cd06cc2e739c..86b40f1664dcf 100644 --- a/frame/support/src/debug.rs +++ b/frame/support/src/debug.rs @@ -192,7 +192,7 @@ impl log::Log for RuntimeLogger { sp_io::logging::log( record.level().into(), record.target(), - &w.inner(), + w.inner(), ); } From 8e76ca72d387b782bac3d7ca7b3f58d7d6b6ba6e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 24 Aug 2020 10:26:52 +0200 Subject: [PATCH 060/113] Wasm interface docs --- primitives/io/src/lib.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 0d3db3b8e68e2..e88c3aaac46f3 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1018,15 +1018,32 @@ impl Crossing { } } -/// Interface that provides tracing functions +/// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate +/// interfaces. See `sp-tracing` for more information. #[runtime_interface] pub trait WasmTracing { + /// Given the crossing over `WasmMetadata`, return whether this should be handled or not. + /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. + /// + /// When returning false the calling code should skip any tracing-related execution. In general + /// within the same block execution this is not exepected to change and there doesn't have to be + /// checked more than once per metadata. This exists for optimisation purposes but is still not + /// cheap as it needs to jump the wasm-native-barrier, so caching the result wasm-side might be + /// a useful addition. fn enabled(&mut self, metadata: Crossing) -> bool { let metadata : &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); tracing::dispatcher::get_default(|d| { d.enabled(metadata) }) } + + /// Open a new span with the given attributes. Return the u64 reference of the span. Where `0` + /// means no span was created or will be tracked. + /// + /// On the native side this goes through the default `tracing` dispatcher to register the span + /// and then calls `clone_span` with the ID to signal that we are keeping it around on the wasm- + /// side even after the local span is dropped. The resulting ID is then handed over to the waasm- + /// side. fn new_span(&mut self, span: Crossing) -> u64 { let span : tracing::Span = span.into_inner().into(); match span.id() { @@ -1040,15 +1057,21 @@ pub trait WasmTracing { } } + /// Emit the given event to the global tracer on the native side fn event(&mut self, event: Crossing) { event.into_inner().emit(); } + /// Signal that a given span-id has been entered. On native, this directly + /// proxies this to the global dispatcher. fn enter(&mut self, span: u64) { tracing::dispatcher::get_default(|d| { d.enter(&tracing_core::span::Id::from_u64(span)) }); } + + /// Signal that a given span-id has been exited. On native, this directly + /// proxies this to the global dispatcher. fn exit(&mut self, span: u64) { tracing::dispatcher::get_default(|d| { d.exit(&tracing_core::span::Id::from_u64(span)) @@ -1088,14 +1111,15 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { } #[cfg(all(not(feature="std"), feature="with-tracing"))] -/// Initialize tracing of sp_tracing +/// Initialize tracing of sp_tracing on wasm with `with-tracing` enabled pub fn init_tracing() { use sp_std::boxed::Box; sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber {} )); } #[cfg(not(all(not(feature="std"), feature="with-tracing")))] -/// Initialize tracing of sp_tracing not necessary – noop +/// Initialize tracing of sp_tracing not necessary – noop. To enable build +/// without std and with the `with-tracing`-feature. pub fn init_tracing() { } /// Wasm-only interface that provides functions for interacting with the sandbox. From 21fff398ce93e355d498bf01604f9b7e8319334c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 24 Aug 2020 11:09:33 +0200 Subject: [PATCH 061/113] optimise docs.rs setup --- primitives/tracing/Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 2bbabdd54343f..d2bfdb777d0f6 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -9,6 +9,11 @@ repository = "https://github.com/paritytech/substrate/" description = "Instrumentation primitives and macros for Substrate." [package.metadata.docs.rs] +# let's default to wasm32 +default-target = "wasm32-unknown-unknown" +# with the tracing enabled +features = ["with-tracing"] +# allowing for linux-gnu here, too, allows for `std` to show up as well targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] From afd5ef251e9dbe5f73fd1a881f194a02a6e049d3 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 08:44:34 +0200 Subject: [PATCH 062/113] adding tracing flags to uncomment --- bin/node-template/runtime/build.rs | 2 ++ bin/node/runtime/build.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/bin/node-template/runtime/build.rs b/bin/node-template/runtime/build.rs index 52705043a2019..3625b3a4ab591 100644 --- a/bin/node-template/runtime/build.rs +++ b/bin/node-template/runtime/build.rs @@ -6,5 +6,7 @@ fn main() { .with_wasm_builder_from_crates("2.0.0") .export_heap_base() .import_memory() + // Uncomment the following to activate tracing in WASM + // .append_to_rust_flags("--cfg feature=\\\"with-tracing\\\"") .build() } diff --git a/bin/node/runtime/build.rs b/bin/node/runtime/build.rs index a2f09a460e69d..bb33bf5867412 100644 --- a/bin/node/runtime/build.rs +++ b/bin/node/runtime/build.rs @@ -23,5 +23,7 @@ fn main() { .with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder") .export_heap_base() .import_memory() + // Uncomment the following to enable wasm-based tracing + // .append_to_rust_flags("--cfg feature=\\\"with-tracing\\\"") .build() } From 8cb58009b6bb56e984460993b21c4eec2e22e1ea Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Tue, 25 Aug 2020 08:17:49 +0100 Subject: [PATCH 063/113] remove brace --- frame/executive/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 1d55cbc049b10..620b9d8efe3a3 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -432,7 +432,6 @@ where within_span! { sp_tracing::Level::TRACE, "validate"; xt.validate::(source, &dispatch_info, encoded_len) - } } } From 780fab3a55bcd2b3c76afc0653cc6f6e930cd05f Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 09:21:18 +0200 Subject: [PATCH 064/113] fixing imports --- primitives/tracing/src/wasm_tracing.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index a6f2c78c44bf0..80920aba191e1 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -16,10 +16,6 @@ #![no_std] -use sp_std::{ - vec -}; - #[cfg(not(feature = "with-tracing"))] mod inner { // we are no-op @@ -1974,7 +1970,7 @@ macro_rules! valueset { // === base case === (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { - WasmValuesSet::from(vec![ $($val),* ]) + WasmValuesSet::from(sp_std::vec![ $($val),* ]) }; // === recursive case (more tts) === @@ -2091,7 +2087,7 @@ macro_rules! valueset { macro_rules! fieldset { // == base case == (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { - WasmFields::from(vec![ $($out),* ] as Vec<&str>) + WasmFields::from(sp_std::vec![ $($out),* ] as sp_std::vec::Vec<&str>) }; // == recursive cases (more tts) == From 0880b70f6b845d1c6a9afb4760af61afa6d5e4d1 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 09:21:35 +0200 Subject: [PATCH 065/113] fixing broken syntax --- frame/executive/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 1d55cbc049b10..620b9d8efe3a3 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -432,7 +432,6 @@ where within_span! { sp_tracing::Level::TRACE, "validate"; xt.validate::(source, &dispatch_info, encoded_len) - } } } From 6c7cb0aca50c698c6d8bcbc40ed34172ce15e2b0 Mon Sep 17 00:00:00 2001 From: Matt Rutherford Date: Tue, 25 Aug 2020 08:42:37 +0100 Subject: [PATCH 066/113] add required modules --- frame/offences/src/lib.rs | 2 +- frame/timestamp/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/offences/src/lib.rs b/frame/offences/src/lib.rs index 9a067d903fe2d..351c10dc2f41c 100644 --- a/frame/offences/src/lib.rs +++ b/frame/offences/src/lib.rs @@ -25,7 +25,7 @@ mod mock; mod tests; -use sp_std::vec::Vec; +use sp_std::{vec, vec::Vec}; use frame_support::{ decl_module, decl_event, decl_storage, Parameter, debug, traits::Get, diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index d74a94cb9201b..e59e6463302f7 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -95,7 +95,7 @@ mod benchmarking; mod default_weights; -use sp_std::{result, cmp}; +use sp_std::{result, cmp, vec, vec::Vec}; use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier}; #[cfg(feature = "std")] use frame_support::debug; From d98f5bdbf3bbefa193521e27dfc38eb16cce06b6 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 14:09:09 +0200 Subject: [PATCH 067/113] nicer formatting --- frame/executive/Cargo.toml | 3 +- frame/executive/src/lib.rs | 7 ++- primitives/tracing/src/types.rs | 87 +++++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/frame/executive/Cargo.toml b/frame/executive/Cargo.toml index 95f4a0ed28a37..c83ebd3e67e76 100644 --- a/frame/executive/Cargo.toml +++ b/frame/executive/Cargo.toml @@ -20,10 +20,10 @@ sp-runtime = { version = "2.0.0-rc6", default-features = false, path = "../../pr sp-tracing = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/tracing" } sp-std = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/io" } +sp-core = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/core" } [dev-dependencies] hex-literal = "0.2.1" -sp-core = { version = "2.0.0-rc6", path = "../../primitives/core" } sp-io ={ version = "2.0.0-rc6", path = "../../primitives/io" } pallet-indices = { version = "2.0.0-rc6", path = "../indices" } pallet-balances = { version = "2.0.0-rc6", path = "../balances" } @@ -40,6 +40,7 @@ std = [ "frame-support/std", "frame-system/std", "serde", + "sp-core/std", "sp-runtime/std", "sp-tracing/std", "sp-std/std", diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 620b9d8efe3a3..ef51de57f3c14 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -365,7 +365,11 @@ where to_note: Option>, ) -> ApplyExtrinsicResult { sp_tracing::enter_span!( - sp_tracing::trace_span!(target: "executive", "apply_extrinsic", extrinsic=?uxt) + sp_tracing::info_span!( + target: "executive", + "apply_extrinsic", + ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode()) + ) ); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; @@ -381,6 +385,7 @@ where // Decode parameters and dispatch let dispatch_info = xt.get_dispatch_info(); + sp_tracing::event!(target: "executive", sp_tracing::Level::INFO, ?dispatch_info.weight); let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; >::note_applied_extrinsic(&r, dispatch_info); diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index e0db54e9f17a8..37ffc302217c7 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -41,7 +41,7 @@ pub enum WasmLevel { } /// A paramter value provided to the span/event -#[derive(Encode, Decode, Clone, Debug)] +#[derive(Encode, Decode, Clone)] pub enum WasmValue { U8(u8), I8(i8), @@ -58,6 +58,48 @@ pub enum WasmValue { Encoded(Vec), } +impl core::fmt::Debug for WasmValue { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + match self { + WasmValue::U8(ref i) => { + f.write_fmt(format_args!("{}_u8", i)) + } + WasmValue::I8(ref i) => { + f.write_fmt(format_args!("{}_i8", i)) + } + WasmValue::U32(ref i) => { + f.write_fmt(format_args!("{}_u32", i)) + } + WasmValue::I32(ref i) => { + f.write_fmt(format_args!("{}_i32", i)) + } + WasmValue::I64(ref i) => { + f.write_fmt(format_args!("{}_i64", i)) + } + WasmValue::U64(ref i) => { + f.write_fmt(format_args!("{}_u64", i)) + } + WasmValue::Bool(ref i) => { + f.write_fmt(format_args!("{}_bool", i)) + } + WasmValue::Formatted(ref i) | WasmValue::Str(ref i) => { + if let Ok(v) = core::str::from_utf8(i) { + f.write_fmt(format_args!("{}", v)) + } else { + f.write_fmt(format_args!("{:?}", i)) + } + } + WasmValue::Encoded(ref v) => { + f.write_str("Scale(")?; + for byte in v { + f.write_fmt(format_args!("{:02x}", byte))?; + } + f.write_str(")") + } + } + } +} + impl From for WasmValue { fn from(u: u8) -> WasmValue { WasmValue::U8(u) @@ -142,9 +184,21 @@ impl From for WasmValue { /// `event!` or `span!`. /// Generally generated automaticaly via `stringify` from an `'static &str`. /// Likely print-able. -#[derive(Encode, Decode, Clone, Debug)] +#[derive(Encode, Decode, Clone)] pub struct WasmFieldName(Vec); +impl core::fmt::Debug for WasmFieldName { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Ok(v) = core::str::from_utf8(&self.0) { + f.write_fmt(format_args!("{}", v)) + } else { + for byte in self.0.iter() { + f.write_fmt(format_args!("{:02x}", byte))?; + } + Ok(()) + } + } +} impl From> for WasmFieldName { fn from(v: Vec) -> Self { @@ -163,6 +217,7 @@ impl From<&str> for WasmFieldName { pub struct WasmFields(Vec); impl WasmFields { + /// Iterate over the fields pub fn iter(&self) -> core::slice::Iter<'_, WasmFieldName> { self.0.iter() } @@ -190,9 +245,35 @@ impl WasmFields { /// A list of `WasmFieldName`s with the given `WasmValue` (if provided) /// in the order specified. -#[derive(Encode, Decode, Clone, Debug)] +#[derive(Encode, Decode, Clone)] pub struct WasmValuesSet(Vec<(WasmFieldName, Option)>); +impl core::fmt::Debug for WasmValuesSet { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + let mut wrt = f.debug_struct(""); + let mut non_str = false; + for (f, v) in self.0.iter() { + if let Ok(s) = core::str::from_utf8(&f.0) { + match v { + Some(ref i) => wrt.field(s, i), + None => wrt.field(s, &(None as Option)), + }; + } else { + non_str = true; + } + } + + // FIXME: replace with using `finish_non_exhaustive()` once stable + // https://github.com/rust-lang/rust/issues/67364 + if non_str { + wrt.field("..", &".."); + } + + wrt.finish() + } +} + + impl From)>> for WasmValuesSet { fn from(v: Vec<(WasmFieldName, Option)>) -> Self { WasmValuesSet(v) From a4b92b3dbe2215b045bfa8594b7c2a55efdc4314 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 14:28:39 +0200 Subject: [PATCH 068/113] better target management --- client/tracing/src/lib.rs | 28 +++++++++++++++++++++++----- frame/executive/src/lib.rs | 10 +++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index c8aeab1fdafd0..dff960d000793 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -290,12 +290,15 @@ impl Subscriber for ProfilingSubscriber { let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed)); 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 id + if attrs.metadata().target() == WASM_TRACE_IDENTIFIER { + // 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 id + } } } + let span_datum = SpanDatum { id: id.clone(), parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), @@ -323,10 +326,25 @@ impl Subscriber for ProfilingSubscriber { fn event(&self, event: &Event<'_>) { let mut values = Values::default(); event.record(&mut values); + let target = { + if event.metadata().target() == WASM_TRACE_IDENTIFIER { + // 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, event.metadata().level()) { + return // nothing to be done, we ignore + } + wasm_target.to_owned() + } else { + event.metadata().target().to_owned() + } + } else { + event.metadata().target().to_owned() + } + }; let trace_event = TraceEvent { name: event.metadata().name(), - target: event.metadata().target().to_owned(), level: event.metadata().level().clone(), + target, values, parent_id: event.parent().cloned().or_else(|| self.current_span.id()), }; diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index ef51de57f3c14..8def4e0c022dd 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -292,7 +292,7 @@ where pub fn execute_block(block: Block) { sp_io::init_tracing(); sp_tracing::within_span! { - sp_tracing::info_span!(target: "executive", "execute_block", ?block); + sp_tracing::info_span!( "execute_block", ?block); { Self::initialize_block(block.header()); @@ -365,11 +365,8 @@ where to_note: Option>, ) -> ApplyExtrinsicResult { sp_tracing::enter_span!( - sp_tracing::info_span!( - target: "executive", - "apply_extrinsic", - ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode()) - ) + sp_tracing::info_span!("apply_extrinsic", + ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())) ); // Verify that the signature is good. let xt = uxt.check(&Default::default())?; @@ -385,7 +382,6 @@ where // Decode parameters and dispatch let dispatch_info = xt.get_dispatch_info(); - sp_tracing::event!(target: "executive", sp_tracing::Level::INFO, ?dispatch_info.weight); let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; >::note_applied_extrinsic(&r, dispatch_info); From 85dab685afa41c3508be40da43f67d32c3733cad Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 25 Aug 2020 14:49:22 +0200 Subject: [PATCH 069/113] adding low level storage tracing events into frame --- frame/support/src/storage/hashed.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/frame/support/src/storage/hashed.rs b/frame/support/src/storage/hashed.rs index 96a487111a2af..c2ca520a1b3c8 100644 --- a/frame/support/src/storage/hashed.rs +++ b/frame/support/src/storage/hashed.rs @@ -28,6 +28,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="get", key=?key); unhashed::get(&hash(key).as_ref()) } @@ -39,6 +41,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="get_or_default", key=?key); unhashed::get_or_default(&hash(key).as_ref()) } @@ -50,6 +54,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="get_or", key=?key); unhashed::get_or(&hash(key).as_ref(), default_value) } @@ -62,6 +68,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="get_or_else", key=?key); unhashed::get_or_else(&hash(key).as_ref(), default_value) } @@ -72,6 +80,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::INFO, fun="put", key=?key, value=?value.encode()); unhashed::put(&hash(key).as_ref(), value) } @@ -82,6 +92,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="take", key=?key); unhashed::take(&hash(key).as_ref()) } @@ -93,6 +105,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="take_or_default", key=?key); unhashed::take_or_default(&hash(key).as_ref()) } @@ -104,6 +118,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="take_or", key=?key); unhashed::take_or(&hash(key).as_ref(), default_value) } @@ -116,6 +132,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="take_or_else", key=?key); unhashed::take_or_else(&hash(key).as_ref(), default_value) } @@ -125,6 +143,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="exists", key=?key); unhashed::exists(&hash(key).as_ref()) } @@ -134,6 +154,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::INFO, fun="kill", key=?key); unhashed::kill(&hash(key).as_ref()) } @@ -143,6 +165,8 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::TRACE, fun="get_raw", key=?key); unhashed::get_raw(&hash(key).as_ref()) } @@ -152,5 +176,7 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { + sp_tracing::event!(target: "frame_storage", + sp_tracing::Level::INFO, fun="put_raw", key=?key, value=?value.encode()); unhashed::put_raw(&hash(key).as_ref(), value) } From 7394b57e171bcb8955311bee65de2079da3a353f Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 26 Aug 2020 17:07:11 +0100 Subject: [PATCH 070/113] add custom Debug impl for WasmMetadata --- primitives/tracing/src/types.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 37ffc302217c7..e77c1ed1f96f9 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -300,7 +300,7 @@ impl WasmValuesSet { /// Metadata provides generic information about the specifc location of the /// `span!` or `event!` call on the wasm-side. -#[derive(Encode, Decode, Clone, Debug)] +#[derive(Encode, Decode, Clone)] pub struct WasmMetadata { /// The name given to `event!`/`span!`, `&'static str` converted to bytes pub name: Vec, @@ -320,6 +320,25 @@ pub struct WasmMetadata { pub fields: WasmFields, } +impl core::fmt::Debug for WasmMetadata { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("WasmMetadata") + .field("name", &decode_field(&self.name)) + .field("target", &decode_field(&self.target)) + .field("level", &self.level) + .field("file", &decode_field(&self.file)) + .field("line", &self.line) + .field("module_path", &decode_field(&self.module_path)) + .field("is_span", &self.is_span) + .field("fields", &self.fields) + .finish() + } +} + +fn decode_field(field: &[u8]) -> &str { + core::str::from_utf8(field).unwrap_or_default() +} + /// Span or Event Attributes #[derive(Encode, Decode, Clone, Debug)] pub struct WasmEntryAttributes { From 79f278d099701f7a3b13d5f51732b553fde7a4cb Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 13:46:19 +0200 Subject: [PATCH 071/113] cloning profiler --- client/tracing/src/lib.rs | 80 +++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index dff960d000793..508bc8aeb0b36 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -28,6 +28,7 @@ use rustc_hash::FxHashMap; use std::fmt; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::{Duration, Instant}; +use std::collections::hash_map::Entry; use parking_lot::Mutex; use serde::ser::{Serialize, Serializer, SerializeMap}; @@ -109,6 +110,9 @@ pub struct SpanDatum { pub overall_time: Duration, /// Values recorded to this span pub values: Values, + /// Count how many times this has been cloned, only + /// exit when this was the last reference. + pub ref_count: usize } /// Holds associated values for a tracing span @@ -308,6 +312,7 @@ impl Subscriber for ProfilingSubscriber { line: attrs.metadata().line().unwrap_or(0), start_time: Instant::now(), overall_time: ZERO_DURATION, + ref_count: 1, values, }; self.span_data.lock().insert(id.clone(), span_datum); @@ -351,45 +356,78 @@ impl Subscriber for ProfilingSubscriber { self.trace_handler.handle_event(trace_event); } + fn clone_span(&self, span: &Id) -> Id { + println!("{:?}: cloning", span); + if let Some(mut s) = self.span_data.lock().get_mut(&span) { + println!("counted"); + s.ref_count = s.ref_count.saturating_add(1); + } else { + println!("no clone"); + } + span.clone() + } + fn enter(&self, span: &Id) { - self.current_span.enter(span.clone()); - let mut span_data = self.span_data.lock(); - let start_time = Instant::now(); - if let Some(mut s) = span_data.get_mut(&span) { - s.start_time = start_time; + println!("{:?}: enter", span); + if let Some(mut s) = self.span_data.lock().get_mut(&span) { + println!("entered"); + self.current_span.enter(span.clone()); + s.start_time = Instant::now(); + } else { + println!("no enter"); } } fn exit(&self, span: &Id) { - self.current_span.exit(); + println!("{:?}: exit", span); let end_time = Instant::now(); let mut span_data = self.span_data.lock(); if let Some(mut s) = span_data.get_mut(&span) { + if s.ref_count != 0 { + println!("no exit"); + return // this isn't the last cloned span, ignore + } + println!("exiting"); + self.current_span.exit(); s.overall_time = end_time - s.start_time + s.overall_time; } } fn try_close(&self, span: Id) -> bool { - let span_datum = { + println!("{:?}: try close", span); + let mut span_datum = { let mut span_data = self.span_data.lock(); - span_data.remove(&span) - }; - if let Some(mut span_datum) = span_datum { - 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) { - span_datum.name = n; - } - if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { - span_datum.target = t; + match span_data.entry(span).and_modify(|d| { + d.ref_count = d.ref_count.saturating_sub(1); + }) { + Entry::Vacant(_) => { + println!("unkown"); + return false; } - if self.check_target(&span_datum.target, &span_datum.level) { - self.trace_handler.handle_span(span_datum); + Entry::Occupied(o) => { + if o.get().ref_count != 0 { + println!("not closing"); + return false; + } + println!("closing"); + o.remove() } - } else { - self.trace_handler.handle_span(span_datum); } }; + 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) { + span_datum.name = n; + } + if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { + span_datum.target = t; + } + if self.check_target(&span_datum.target, &span_datum.level) { + self.trace_handler.handle_span(span_datum); + } + } else { + self.trace_handler.handle_span(span_datum); + } true } } From ec3934cfcb4d1930b09010f192c340a455e824f7 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 13:46:39 +0200 Subject: [PATCH 072/113] adding info about cloning profiler --- primitives/tracing/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index f2dce385aca5f..492132f0cd90b 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -86,6 +86,13 @@ /// and call `set_tracing_subscriber` at the very beginning of your execution – /// the default subscriber is doing nothing, so any spans or events happening before /// will not be recorded! +/// +/// **Note**: The subscriber eventually handling the global subscriptions *must* +/// implement `clone_span` and do ref-counting on the spans alive properly. Because +/// the regular `span` is being dropped when crossing the wasm-barrier, this +/// implementation informs the subscriber with `clone_span` that they are keeping +/// around a reference and thus, if the references are tracked correctly, should +/// not exit the span when the outer, native span is dropped too early. mod types; From d9e8e31b664c986d23f67499b1f28a5aa1fef6b2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 13:47:09 +0200 Subject: [PATCH 073/113] using in-scope for within calls --- primitives/tracing/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 492132f0cd90b..52dce9b9d8d2c 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -240,10 +240,9 @@ macro_rules! within_span { $span:expr; $( $code:tt )* ) => { - { - $crate::enter_span!($span); + $span.in_scope(|| $( $code )* - } + ) }; ( $lvl:expr, From f68a8e5093286033724e79e711613b3135ba54ff Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 22:36:03 +0200 Subject: [PATCH 074/113] proper time tracing, cleaning up println --- client/tracing/src/lib.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 508bc8aeb0b36..e23d8be7eddfa 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -357,59 +357,44 @@ impl Subscriber for ProfilingSubscriber { } fn clone_span(&self, span: &Id) -> Id { - println!("{:?}: cloning", span); if let Some(mut s) = self.span_data.lock().get_mut(&span) { - println!("counted"); s.ref_count = s.ref_count.saturating_add(1); - } else { - println!("no clone"); } span.clone() } fn enter(&self, span: &Id) { - println!("{:?}: enter", span); if let Some(mut s) = self.span_data.lock().get_mut(&span) { - println!("entered"); self.current_span.enter(span.clone()); s.start_time = Instant::now(); - } else { - println!("no enter"); } } fn exit(&self, span: &Id) { - println!("{:?}: exit", span); let end_time = Instant::now(); let mut span_data = self.span_data.lock(); if let Some(mut s) = span_data.get_mut(&span) { - if s.ref_count != 0 { - println!("no exit"); + if s.ref_count > 1 { return // this isn't the last cloned span, ignore } - println!("exiting"); self.current_span.exit(); s.overall_time = end_time - s.start_time + s.overall_time; } } fn try_close(&self, span: Id) -> bool { - println!("{:?}: try close", span); let mut span_datum = { let mut span_data = self.span_data.lock(); match span_data.entry(span).and_modify(|d| { d.ref_count = d.ref_count.saturating_sub(1); }) { Entry::Vacant(_) => { - println!("unkown"); return false; } Entry::Occupied(o) => { if o.get().ref_count != 0 { - println!("not closing"); return false; } - println!("closing"); o.remove() } } From 7db90f372ce1bd43e9e22672933178802a221ee3 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 22:36:42 +0200 Subject: [PATCH 075/113] allow to disable tracing on runtime_interface-macro --- .../runtime-interface/proc-macro/src/lib.rs | 45 +++++++++++++++++-- .../bare_function_interface.rs | 17 +++++-- .../host_function_interface.rs | 1 - .../proc-macro/src/runtime_interface/mod.rs | 6 ++- 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/primitives/runtime-interface/proc-macro/src/lib.rs b/primitives/runtime-interface/proc-macro/src/lib.rs index 2f5b9de1c14e7..a54e99ea6c01a 100644 --- a/primitives/runtime-interface/proc-macro/src/lib.rs +++ b/primitives/runtime-interface/proc-macro/src/lib.rs @@ -26,21 +26,60 @@ //! 3. The [`PassByEnum`](derive.PassByInner.html) derive macro for implementing `PassBy` with `Enum`. //! 4. The [`PassByInner`](derive.PassByInner.html) derive macro for implementing `PassBy` with `Inner`. -use syn::{parse_macro_input, ItemTrait, DeriveInput}; +use syn::{parse_macro_input, ItemTrait, DeriveInput, Result, Token}; +use syn::parse::{Parse, ParseStream}; mod pass_by; mod runtime_interface; mod utils; +struct Options { + wasm_only: bool, + tracing: bool +} + +impl Options { + fn unpack(self) -> (bool, bool) { + (self.wasm_only, self.tracing) + } +} +impl Default for Options { + fn default() -> Self { + Options { wasm_only: false, tracing: true } + } +} + +impl Parse for Options { + fn parse(input: ParseStream) -> Result { + let mut res = Self::default(); + while !input.is_empty() { + let lookahead = input.lookahead1(); + if lookahead.peek(runtime_interface::keywords::wasm_only) { + let _ = input.parse::(); + res.wasm_only = true; + } else if lookahead.peek(runtime_interface::keywords::no_tracing) { + let _ = input.parse::(); + res.tracing = false; + } else if lookahead.peek(Token![,]) { + let _ = input.parse::(); + } else { + return Err(lookahead.error()) + } + } + Ok(res) + } + +} + #[proc_macro_attribute] pub fn runtime_interface( attrs: proc_macro::TokenStream, input: proc_macro::TokenStream, ) -> proc_macro::TokenStream { let trait_def = parse_macro_input!(input as ItemTrait); - let wasm_only = parse_macro_input!(attrs as Option); + let (wasm_only, tracing) = parse_macro_input!(attrs as Options).unpack(); - runtime_interface::runtime_interface_impl(trait_def, wasm_only.is_some()) + runtime_interface::runtime_interface_impl(trait_def, wasm_only, tracing) .unwrap_or_else(|e| e.to_compile_error()) .into() } diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index 29b375dd0509d..30ee483492149 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -46,7 +46,7 @@ use std::iter; /// Generate one bare function per trait method. The name of the bare function is equal to the name /// of the trait method. -pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result { +pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool, tracing: bool) -> Result { let trait_name = &trait_def.ident; let runtime_interface = get_runtime_interface(trait_def)?; @@ -63,7 +63,7 @@ pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result = runtime_interface.all_versions().try_fold(token_stream?, |mut t, (version, method)| { - t.extend(function_std_impl(trait_name, method, version, is_wasm_only)?); + t.extend(function_std_impl(trait_name, method, version, is_wasm_only, tracing)?); Ok(t) }); @@ -145,6 +145,7 @@ fn function_std_impl( method: &TraitItemMethod, version: u32, is_wasm_only: bool, + tracing: bool, ) -> Result { let function_name = create_function_ident_with_version(&method.sig.ident, version); let function_name_str = function_name.to_string(); @@ -168,13 +169,21 @@ fn function_std_impl( let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version")); // Don't make the function public accessible when this is a wasm only interface. let call_to_trait = generate_call_to_trait(trait_name, method, version, is_wasm_only); + let call_to_trait = if ! tracing { + call_to_trait + } else { + parse_quote!( + #crate_::sp_tracing::within_span! { #crate_::sp_tracing::trace_span!(#function_name_str); + #call_to_trait + } + ) + }; Ok( quote_spanned! { method.span() => #[cfg(feature = "std")] #( #attrs )* fn #function_name( #( #args, )* ) #return_value { - #crate_::sp_tracing::enter_span!(#crate_::sp_tracing::Level::Trace, #function_name_str); #call_to_trait } } @@ -186,7 +195,7 @@ fn generate_call_to_trait( trait_name: &Ident, method: &TraitItemMethod, version: u32, - is_wasm_only: bool, + is_wasm_only: bool ) -> TokenStream { let crate_ = generate_crate_access(); let method_name = create_function_ident_with_version(&method.sig.ident, version); diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 7b44ae1ef2628..7a4dbc5773a28 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -227,7 +227,6 @@ fn generate_host_function_implementation( __function_context__: &mut dyn #crate_::sp_wasm_interface::FunctionContext, args: &mut dyn Iterator, ) -> std::result::Result, String> { - #crate_::sp_tracing::enter_span!(#crate_::sp_tracing::Level::Trace, #name); #( #wasm_to_ffi_values )* #( #ffi_to_host_values )* #host_function_call diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs index c9b6edf68fd5a..18d5d371ee1b3 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs @@ -33,14 +33,16 @@ mod trait_decl_impl; pub mod keywords { // Custom keyword `wasm_only` that can be given as attribute to [`runtime_interface`]. syn::custom_keyword!(wasm_only); + // Disable tracing-macros added to the [`runtime_interface`] by specifying this optional entry + syn::custom_keyword!(no_tracing); } /// Implementation of the `runtime_interface` attribute. /// /// It expects the trait definition the attribute was put above and if this should be an wasm only /// interface. -pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool) -> Result { - let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only)?; +pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool, tracing: bool) -> Result { + let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only, tracing)?; let crate_include = generate_runtime_interface_include(); let mod_name = Ident::new(&trait_def.ident.to_string().to_snake_case(), Span::call_site()); let trait_decl_impl = trait_decl_impl::process(&trait_def, is_wasm_only)?; From a08cb44b7f62f6699b4bd74d82694934ed8bb0a0 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 22:37:03 +0200 Subject: [PATCH 076/113] disable tracing for wasm-tracing-interface --- primitives/io/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index e88c3aaac46f3..afd61675d00e6 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1020,7 +1020,7 @@ impl Crossing { /// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate /// interfaces. See `sp-tracing` for more information. -#[runtime_interface] +#[runtime_interface(wasm_only,no_tracing)] pub trait WasmTracing { /// Given the crossing over `WasmMetadata`, return whether this should be handled or not. /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. From 4395a6c9f7e6b323c06e1a93dc72c897bfbd08f8 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 22:40:15 +0200 Subject: [PATCH 077/113] simplify wasm-tracing-api --- frame/executive/src/lib.rs | 168 +++++++++++++------------ frame/support/src/dispatch.rs | 40 +++--- primitives/io/src/lib.rs | 28 ++--- primitives/tracing/src/lib.rs | 73 ++--------- primitives/tracing/src/wasm_tracing.rs | 28 +---- 5 files changed, 134 insertions(+), 203 deletions(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 8def4e0c022dd..27be31eac6f62 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -207,14 +207,15 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { - sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block"); - let digests = Self::extract_pre_digest(&header); - Self::initialize_block_impl( - header.number(), - header.parent_hash(), - header.extrinsics_root(), - &digests - ); + sp_tracing::within_span!(sp_tracing::Level::TRACE, "init_block"; { + let digests = Self::extract_pre_digest(&header); + Self::initialize_block_impl( + header.number(), + header.parent_hash(), + header.extrinsics_root(), + &digests + ); + }) } fn extract_pre_digest(header: &System::Header) -> DigestOf { @@ -271,29 +272,28 @@ where } fn initial_checks(block: &Block) { - sp_tracing::enter_span!(sp_tracing::Level::TRACE, "initial_checks"); - let header = block.header(); - - // Check that `parent_hash` is correct. - let n = header.number().clone(); - assert!( - n > System::BlockNumber::zero() - && >::block_hash(n - System::BlockNumber::one()) == *header.parent_hash(), - "Parent hash should be valid." - ); + sp_tracing::within_span!(sp_tracing::Level::TRACE, "initial_checks"; { + let header = block.header(); + + // Check that `parent_hash` is correct. + let n = header.number().clone(); + assert!( + n > System::BlockNumber::zero() + && >::block_hash(n - System::BlockNumber::one()) == *header.parent_hash(), + "Parent hash should be valid." + ); - // Check that transaction trie root represents the transactions. - let xts_root = extrinsics_root::(&block.extrinsics()); - header.extrinsics_root().check_equal(&xts_root); - assert!(header.extrinsics_root() == &xts_root, "Transaction trie root must be valid."); + // Check that transaction trie root represents the transactions. + let xts_root = extrinsics_root::(&block.extrinsics()); + header.extrinsics_root().check_equal(&xts_root); + assert!(header.extrinsics_root() == &xts_root, "Transaction trie root must be valid."); + }) } /// Actually execute all transitions for `block`. pub fn execute_block(block: Block) { sp_io::init_tracing(); - sp_tracing::within_span! { - sp_tracing::info_span!( "execute_block", ?block); - { + sp_tracing::within_span!(sp_tracing::info_span!( "execute_block", ?block); { Self::initialize_block(block.header()); // any initial checks @@ -311,7 +311,7 @@ where // any final checks Self::final_checks(&header); - } }; + }) } /// Execute given extrinsics and take care of post-extrinsics book-keeping. @@ -327,15 +327,16 @@ where /// Finalize the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalize_block() -> System::Header { - sp_tracing::enter_span!( sp_tracing::Level::TRACE, "finalize_block" ); - >::note_finished_extrinsics(); - let block_number = >::block_number(); - as OnFinalize>::on_finalize(block_number); - >::on_finalize(block_number); - - // set up extrinsics - >::derive_extrinsics(); - >::finalize() + sp_tracing::within_span!(sp_tracing::Level::TRACE, "finalize_block" ; { + >::note_finished_extrinsics(); + let block_number = >::block_number(); + as OnFinalize>::on_finalize(block_number); + >::on_finalize(block_number); + + // set up extrinsics + >::derive_extrinsics(); + >::finalize() + }) } /// Apply extrinsic outside of the block execution function. @@ -364,52 +365,54 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { - sp_tracing::enter_span!( - sp_tracing::info_span!("apply_extrinsic", - ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())) - ); - // Verify that the signature is good. - let xt = uxt.check(&Default::default())?; - - // We don't need to make sure to `note_extrinsic` only after we know it's going to be - // executed to prevent it from leaking in storage since at this point, it will either - // execute or panic (and revert storage changes). - if let Some(encoded) = to_note { - >::note_extrinsic(encoded); - } + sp_tracing::within_span!(sp_tracing::info_span!("apply_extrinsic", + ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())); + { + // Verify that the signature is good. + let xt = uxt.check(&Default::default())?; + + // We don't need to make sure to `note_extrinsic` only after we know it's going to be + // executed to prevent it from leaking in storage since at this point, it will either + // execute or panic (and revert storage changes). + if let Some(encoded) = to_note { + >::note_extrinsic(encoded); + } - // AUDIT: Under no circumstances may this function panic from here onwards. + // AUDIT: Under no circumstances may this function panic from here onwards. - // Decode parameters and dispatch - let dispatch_info = xt.get_dispatch_info(); - let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; + // Decode parameters and dispatch + let dispatch_info = xt.get_dispatch_info(); + let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; - >::note_applied_extrinsic(&r, dispatch_info); + >::note_applied_extrinsic(&r, dispatch_info); - Ok(r.map(|_| ()).map_err(|e| e.error)) + Ok(r.map(|_| ()).map_err(|e| e.error)) + }) } fn final_checks(header: &System::Header) { - sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks"); - // remove temporaries - let new_header = >::finalize(); - - // check digest - assert_eq!( - header.digest().logs().len(), - new_header.digest().logs().len(), - "Number of digest items must match that calculated." - ); - let items_zip = header.digest().logs().iter().zip(new_header.digest().logs().iter()); - for (header_item, computed_item) in items_zip { - header_item.check_equal(&computed_item); - assert!(header_item == computed_item, "Digest item must match that calculated."); - } + sp_tracing::within_span!(sp_tracing::Level::TRACE, "final_checks"; + { + // remove temporaries + let new_header = >::finalize(); - // check storage root. - let storage_root = new_header.state_root(); - header.state_root().check_equal(&storage_root); - assert!(header.state_root() == storage_root, "Storage root must match that calculated."); + // check digest + assert_eq!( + header.digest().logs().len(), + new_header.digest().logs().len(), + "Number of digest items must match that calculated." + ); + let items_zip = header.digest().logs().iter().zip(new_header.digest().logs().iter()); + for (header_item, computed_item) in items_zip { + header_item.check_equal(&computed_item); + assert!(header_item == computed_item, "Digest item must match that calculated."); + } + + // check storage root. + let storage_root = new_header.state_root(); + header.state_root().check_equal(&storage_root); + assert!(header.state_root() == storage_root, "Storage root must match that calculated."); + }) } /// Check a given signed transaction for validity. This doesn't execute any @@ -420,20 +423,21 @@ where source: TransactionSource, uxt: Block::Extrinsic, ) -> TransactionValidity { - use sp_tracing::{enter_span, within_span}; + use sp_tracing::{within_span}; - enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" }; + within_span!(sp_tracing::Level::TRACE, "validate_transaction"; { - let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; + let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; - let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; + let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default()) }?; - let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; + let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; - within_span! { - sp_tracing::Level::TRACE, "validate"; - xt.validate::(source, &dispatch_info, encoded_len) - } + within_span! { + sp_tracing::Level::TRACE, "validate"; + xt.validate::(source, &dispatch_info, encoded_len) + } + }) } /// Start an offchain worker and generate extrinsics. diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 0544d5b40281d..4fe182f0c8a9d 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1274,8 +1274,9 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); - { $( $impl )* } + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_initialize"); + { $( $impl )* } + } } } }; @@ -1290,8 +1291,9 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize($param: $param_ty) -> $return { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); - { $( $impl )* } + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_initialize"); + { $( $impl )* } + } } } }; @@ -1316,8 +1318,9 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_runtime_upgrade() -> $return { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade")); - { $( $impl )* } + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_runtime_upgrade"); + { $( $impl )* } + } } } }; @@ -1371,8 +1374,9 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); - { $( $impl )* } + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_finalize"); + { $( $impl )* } + } } } }; @@ -1387,8 +1391,9 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize($param: $param_ty) { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); - { $( $impl )* } + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_finalize"); + { $( $impl )* } + } } } }; @@ -1456,9 +1461,13 @@ macro_rules! decl_module { $vis fn $name( $origin: $origin_ty $(, $param: $param_ty )* ) -> $crate::dispatch::DispatchResult { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); - { $( $impl )* } - Ok(()) + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!(stringify!($name)); + { + { $( $impl )* } + Ok(()) + } + } + } }; @@ -1475,8 +1484,9 @@ macro_rules! decl_module { ) => { $(#[$fn_attr])* $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { - $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); - $( $impl )* + $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!(stringify!($name)); + { $( $impl )* } + } } }; diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index afd61675d00e6..3fbfc2ec44487 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1044,12 +1044,15 @@ pub trait WasmTracing { /// and then calls `clone_span` with the ID to signal that we are keeping it around on the wasm- /// side even after the local span is dropped. The resulting ID is then handed over to the waasm- /// side. - fn new_span(&mut self, span: Crossing) -> u64 { + fn enter_span(&mut self, span: Crossing) -> u64 { let span : tracing::Span = span.into_inner().into(); match span.id() { Some(id) => tracing::dispatcher::get_default(|d| { // inform dispatch that we'll keep the ID around - d.clone_span(&id).into_u64() + // then enter it immediately + let final_id = d.clone_span(&id); + d.enter(&final_id); + final_id.into_u64() }), _ => { 0 @@ -1062,19 +1065,13 @@ pub trait WasmTracing { event.into_inner().emit(); } - /// Signal that a given span-id has been entered. On native, this directly - /// proxies this to the global dispatcher. - fn enter(&mut self, span: u64) { - tracing::dispatcher::get_default(|d| { - d.enter(&tracing_core::span::Id::from_u64(span)) - }); - } - /// Signal that a given span-id has been exited. On native, this directly /// proxies this to the global dispatcher. fn exit(&mut self, span: u64) { tracing::dispatcher::get_default(|d| { - d.exit(&tracing_core::span::Id::from_u64(span)) + let id = tracing_core::span::Id::from_u64(span); + d.exit(&id); + d.try_close(id); }); } } @@ -1088,8 +1085,8 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { wasm_tracing::enabled(Crossing(metadata.clone())) } - fn new_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { - wasm_tracing::new_span(Crossing(attrs)) + fn enter_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { + wasm_tracing::enter_span(Crossing(attrs)) } fn event(&self, parent_id: Option, @@ -1102,11 +1099,8 @@ impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { fields: values.clone() })) } - fn enter(&self, span: u64) { - wasm_tracing::enter(span) - } fn exit(&self, span: u64) { - wasm_tracing::enter(span) + wasm_tracing::exit(span) } } diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 52dce9b9d8d2c..1b468d36070a4 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -17,8 +17,7 @@ //! Substrate tracing primitives and macros. //! -//! To trace functions or invidual code in Substrate, this crate provides [`within_span`] -//! and [`enter_span`]. See the individual docs for how to use these macros. +//! To trace functions or invidual code in Substrate, this crate provides [`within_span`]. //! //! Note that to allow traces from wasm execution environment there are //! 2 reserved identifiers for tracing `Field` recording, stored in the consts: @@ -45,24 +44,15 @@ /// the tracing code in the non-std environment. /// /// Because of that optimisation, you should not use the `span!` and `span_*!` macros -/// directly as they yield nothing without the feature present. Instead you should use -/// `enter_span!` and `within_span!` – which would strip away even any parameter conversion +/// directly as they yield nothing without the feature present. Instead you must use +/// `within_span!` – which would strip away even any parameter conversion /// you do within the span-definition (and thus optimise your performance). For your -/// convineience you directly specify the `Level` and name of the span or use the full +/// convinience you directly specify the `Level` and name of the span or use the full /// feature set of `span!`/`span_*!` on it: /// /// # Example /// /// ```rust -/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "fn wide span"); -/// { -/// sp_tracing::enter_span!(sp_tracing::trace_span!("outer-span")); -/// { -/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); -/// // .. -/// } // inner span exists here -/// } // outer span exists here -/// /// sp_tracing::within_span! { /// sp_tracing::debug_span!("debug-span", you_can_pass="any params"); /// 1 + 1; @@ -139,14 +129,12 @@ pub trait TracingSubscriber: Send + Sync { /// This may or may not be implemented wasm- and/or native side or have optimisations /// added. fn enabled(&self, metadata: &WasmMetadata) -> bool; - /// Create a new `Span` with the given `WasmEntryAttributes`, return the u64 tracking ID for - /// it. Will only be called if `attrs.metadata` was found to be enabled. - fn new_span(&self, attrs: WasmEntryAttributes) -> u64; + /// Enter a new `Span` with the given `WasmEntryAttributes`, return the u64 tracking ID for + /// it or 0 if not. Will only be called if `attrs.metadata` was found to be enabled. + fn enter_span(&self, attrs: WasmEntryAttributes) -> u64; /// Record the `WasmValueSet` for `WasMetadata` as a new event. Willl only be called if /// `WasmMetadata` was found to be enabled; fn event(&self, parent_id: Option, metadata: &WasmMetadata, values: &WasmValuesSet); - /// Mark the given `span` to be entered. A span may not be entered twice. - fn enter(&self, span: u64); /// Exit the given span. You can discard the span info now. fn exit(&self, span: u64); } @@ -271,51 +259,4 @@ macro_rules! within_span { ) => { $( $code )* }; -} - - -/// Enter a span - noop for `no_std` without `with-tracing` -#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] -#[macro_export] -macro_rules! enter_span { - ( $lvl:expr, $name:expr ) => ( ); - ( $name:expr ) => ( ) // no-op -} - -/// Enter a span. -/// -/// The span will be valid, until the scope is left. Use either level and name -/// or pass in any valid `sp_tracing::Span` for extended usage. The span will -/// be exited on drop – which is at the end of the block or to the next -/// `enter_span!` calls, as this overwrites the local variable. For nested -/// usage or to ensure the span closes at certain time either put it into a block -/// or use `within_span!` -/// -/// # Example -/// -/// ``` -/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); -/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); -/// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); -/// -/// { -/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "outer-span"); -/// { -/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); -/// // .. -/// } // inner span exists here -/// } // outer span exists here -/// -/// ``` -#[cfg(any(feature = "std", feature = "with-tracing"))] -#[macro_export] -macro_rules! enter_span { - ( $span:expr ) => { - // FIXME: this could be clashing, make the local variable based on name to prevent that - let __within_span__ = $span; - let __tracing_guard__ = __within_span__.enter(); - }; - ( $lvl:expr, $name:expr ) => { - $crate::enter_span!($crate::span!($crate::Level::TRACE, $name)) - }; } \ No newline at end of file diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 80920aba191e1..a29c54688be5d 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -71,7 +71,6 @@ mod inner { // just a simplistic holder for span and entered spans // that exits on drop pub struct Span(u64); // 0 means no item - pub struct Entered(u64); // 0 means no item impl Span { pub fn new(v: u64) -> Self { @@ -80,29 +79,12 @@ mod inner { pub fn none() -> Self { Span::new(0) } - pub fn enter(&self) -> Entered { - if self.0 != 0 { - crate::with_tracing_subscriber(|t| t.enter(self.0)); - } - Entered(self.0) - } - pub fn in_scope T, T>(&self, f: F) -> T { - let _enter = self.enter(); - f() - } - } - - impl Entered { - pub fn exit(&mut self) { + pub fn in_scope T, T>(self, f: F) -> T { + let x = f(); if self.0 != 0 { crate::with_tracing_subscriber(|t| t.exit(self.0)); } - } - } - - impl Drop for Entered { - fn drop(&mut self) { - self.exit(); + x } } @@ -388,7 +370,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - let span_id = $crate::with_tracing_subscriber(|t| t.new_span( + let span_id = $crate::with_tracing_subscriber(|t| t.enter_span( WasmEntryAttributes { parent_id: Some($parent.0), fields: $crate::valueset!(&metadata.fields, $($fields)*), @@ -422,7 +404,7 @@ mod inner { fields: $crate::fieldset!( $($fields)* ) }; if $crate::is_enabled!(&metadata) { - let span_id = $crate::with_tracing_subscriber(|t| t.new_span( + let span_id = $crate::with_tracing_subscriber(|t| t.enter_span( WasmEntryAttributes { parent_id: None, metadata: metadata.clone(), From e7792029c451d8c2aa7f89dba36b67b10502e3f2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 1 Sep 2020 22:41:23 +0200 Subject: [PATCH 078/113] update client to new interface --- client/transaction-pool/src/api.rs | 38 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index 712a7e156abce..853b66f6e74bb 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -168,26 +168,28 @@ where Client::Api: TaggedTransactionQueue, sp_api::ApiErrorFor: Send + std::fmt::Display, { - sp_tracing::enter_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::, _>(&at, |v| v >= 2) - .unwrap_or_default() - }; - - let res = sp_tracing::within_span!( - sp_tracing::Level::TRACE, "runtime::validate_transaction"; + sp_tracing::within_span!(sp_tracing::Level::TRACE, "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) - } - }); + let runtime_api = client.runtime_api(); + let has_v2 = sp_tracing::within_span! { sp_tracing::Level::TRACE, "check_version"; + runtime_api + .has_api_with::, _>(&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())) + res.map_err(|e| Error::RuntimeApi(e.to_string())) + }) } impl FullChainApi From c2d856dbb0b788130fb80be86dd89374f2512332 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 09:57:21 +0200 Subject: [PATCH 079/113] fixing docs and tests for sp-tracing --- primitives/tracing/src/lib.rs | 4 +++- primitives/tracing/src/wasm_tracing.rs | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 1b468d36070a4..f2a7053009c56 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -229,7 +229,9 @@ macro_rules! within_span { $( $code:tt )* ) => { $span.in_scope(|| - $( $code )* + { + $( $code )* + } ) }; ( diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index a29c54688be5d..349fdf4240d4d 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -68,23 +68,40 @@ mod inner { module_path, concat, format_args, file, line, }; - // just a simplistic holder for span and entered spans + // just a simplistic holder for the entered span // that exits on drop pub struct Span(u64); // 0 means no item impl Span { + /// Hold the `id` of the entered span pub fn new(v: u64) -> Self { Span(v) } + /// Create a not-activated Span pub fn none() -> Self { Span::new(0) } + /// This is a noop, just pointing a reference to itself only + /// existing to be compliant with the general usage. + /// In this implementation, spans are already entered + pub fn enter(&self) -> &Self { + // return a reference to self prevents using enter and + // `in_scope` on the same span. + &self + } + + /// Execute `f` and consume the span, which leads to it + /// immediately exiting before return pub fn in_scope T, T>(self, f: F) -> T { - let x = f(); + f() + } + } + + impl Drop for Span { + fn drop(&mut self) { if self.0 != 0 { crate::with_tracing_subscriber(|t| t.exit(self.0)); } - x } } From 5cbae70067056778e6cc5f1c332b0c9b3f2b980e Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 10:25:33 +0200 Subject: [PATCH 080/113] update integration tests --- client/executor/runtime-test/src/lib.rs | 4 +- client/executor/src/integration_tests/mod.rs | 47 ++------------------ primitives/io/src/lib.rs | 10 +++++ primitives/tracing/src/types.rs | 35 ++++++++++++++- 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/client/executor/runtime-test/src/lib.rs b/client/executor/runtime-test/src/lib.rs index fa24f6cbaa8fb..04397afd776d7 100644 --- a/client/executor/runtime-test/src/lib.rs +++ b/client/executor/runtime-test/src/lib.rs @@ -253,8 +253,8 @@ sp_core::wasm_export_functions! { sp_allocator::FreeingBumpHeapAllocator::new(0); } - fn test_enter_span() { - wasm_tracing::enter(0) + fn test_enter_span() -> u64 { + wasm_tracing::enter_span(Default::default()) } fn test_exit_span(span_id: u64) { diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index c63ece8e81038..6847afcca6128 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -679,53 +679,13 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { // Create subscriber with wasm_tracing disabled let test_subscriber = sc_tracing::ProfilingSubscriber::new_with_handler( - Box::new(handler), "integration_test_span_target"); + Box::new(handler), "default"); 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", &[], @@ -752,8 +712,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); } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 3fbfc2ec44487..208857bba1283 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1018,6 +1018,16 @@ impl Crossing { } } +// useful for testing +impl core::default::Default for Crossing + where T: core::default::Default + Encode + Decode +{ + fn default() -> Self { + Self(Default::default()) + } + +} + /// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate /// interfaces. See `sp-tracing` for more information. #[runtime_interface(wasm_only,no_tracing)] diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index e77c1ed1f96f9..be5591a5fbc29 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -20,7 +20,7 @@ use core::fmt::Debug; use sp_std::{ - vec::Vec, + vec, vec::Vec, }; use sp_std::Writer; use codec::{Encode, Decode}; @@ -40,6 +40,12 @@ pub enum WasmLevel { TRACE } +impl core::default::Default for WasmLevel { + fn default() -> Self { + WasmLevel::TRACE + } +} + /// A paramter value provided to the span/event #[derive(Encode, Decode, Clone)] pub enum WasmValue { @@ -335,6 +341,23 @@ impl core::fmt::Debug for WasmMetadata { } } +impl core::default::Default for WasmMetadata { + fn default() -> Self { + let target = "default".as_bytes().to_vec(); + WasmMetadata { + target, + name: Default::default(), + level: Default::default(), + file: Default::default(), + line: Default::default(), + module_path: Default::default(), + is_span: true, + fields: WasmFields::empty() + } + } +} + + fn decode_field(field: &[u8]) -> &str { core::str::from_utf8(field).unwrap_or_default() } @@ -350,6 +373,16 @@ pub struct WasmEntryAttributes { pub fields: WasmValuesSet, } +impl core::default::Default for WasmEntryAttributes { + fn default() -> Self { + WasmEntryAttributes { + parent_id: None, + metadata: Default::default(), + fields: WasmValuesSet(vec![]), + } + } +} + #[cfg(feature = "std")] mod std_features { From 4d892fa6957c0d454b11ed435e36f2563e3a6ba6 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 10:31:58 +0200 Subject: [PATCH 081/113] re-activating enter_span --- frame/executive/src/lib.rs | 168 +++++++++++++++++----------------- frame/support/src/dispatch.rs | 40 +++----- primitives/tracing/src/lib.rs | 65 ++++++++++++- 3 files changed, 158 insertions(+), 115 deletions(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 27be31eac6f62..8def4e0c022dd 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -207,15 +207,14 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { - sp_tracing::within_span!(sp_tracing::Level::TRACE, "init_block"; { - let digests = Self::extract_pre_digest(&header); - Self::initialize_block_impl( - header.number(), - header.parent_hash(), - header.extrinsics_root(), - &digests - ); - }) + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block"); + let digests = Self::extract_pre_digest(&header); + Self::initialize_block_impl( + header.number(), + header.parent_hash(), + header.extrinsics_root(), + &digests + ); } fn extract_pre_digest(header: &System::Header) -> DigestOf { @@ -272,28 +271,29 @@ where } fn initial_checks(block: &Block) { - sp_tracing::within_span!(sp_tracing::Level::TRACE, "initial_checks"; { - let header = block.header(); - - // Check that `parent_hash` is correct. - let n = header.number().clone(); - assert!( - n > System::BlockNumber::zero() - && >::block_hash(n - System::BlockNumber::one()) == *header.parent_hash(), - "Parent hash should be valid." - ); + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "initial_checks"); + let header = block.header(); + + // Check that `parent_hash` is correct. + let n = header.number().clone(); + assert!( + n > System::BlockNumber::zero() + && >::block_hash(n - System::BlockNumber::one()) == *header.parent_hash(), + "Parent hash should be valid." + ); - // Check that transaction trie root represents the transactions. - let xts_root = extrinsics_root::(&block.extrinsics()); - header.extrinsics_root().check_equal(&xts_root); - assert!(header.extrinsics_root() == &xts_root, "Transaction trie root must be valid."); - }) + // Check that transaction trie root represents the transactions. + let xts_root = extrinsics_root::(&block.extrinsics()); + header.extrinsics_root().check_equal(&xts_root); + assert!(header.extrinsics_root() == &xts_root, "Transaction trie root must be valid."); } /// Actually execute all transitions for `block`. pub fn execute_block(block: Block) { sp_io::init_tracing(); - sp_tracing::within_span!(sp_tracing::info_span!( "execute_block", ?block); { + sp_tracing::within_span! { + sp_tracing::info_span!( "execute_block", ?block); + { Self::initialize_block(block.header()); // any initial checks @@ -311,7 +311,7 @@ where // any final checks Self::final_checks(&header); - }) + } }; } /// Execute given extrinsics and take care of post-extrinsics book-keeping. @@ -327,16 +327,15 @@ where /// Finalize the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalize_block() -> System::Header { - sp_tracing::within_span!(sp_tracing::Level::TRACE, "finalize_block" ; { - >::note_finished_extrinsics(); - let block_number = >::block_number(); - as OnFinalize>::on_finalize(block_number); - >::on_finalize(block_number); - - // set up extrinsics - >::derive_extrinsics(); - >::finalize() - }) + sp_tracing::enter_span!( sp_tracing::Level::TRACE, "finalize_block" ); + >::note_finished_extrinsics(); + let block_number = >::block_number(); + as OnFinalize>::on_finalize(block_number); + >::on_finalize(block_number); + + // set up extrinsics + >::derive_extrinsics(); + >::finalize() } /// Apply extrinsic outside of the block execution function. @@ -365,54 +364,52 @@ where encoded_len: usize, to_note: Option>, ) -> ApplyExtrinsicResult { - sp_tracing::within_span!(sp_tracing::info_span!("apply_extrinsic", - ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())); - { - // Verify that the signature is good. - let xt = uxt.check(&Default::default())?; - - // We don't need to make sure to `note_extrinsic` only after we know it's going to be - // executed to prevent it from leaking in storage since at this point, it will either - // execute or panic (and revert storage changes). - if let Some(encoded) = to_note { - >::note_extrinsic(encoded); - } + sp_tracing::enter_span!( + sp_tracing::info_span!("apply_extrinsic", + ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())) + ); + // Verify that the signature is good. + let xt = uxt.check(&Default::default())?; + + // We don't need to make sure to `note_extrinsic` only after we know it's going to be + // executed to prevent it from leaking in storage since at this point, it will either + // execute or panic (and revert storage changes). + if let Some(encoded) = to_note { + >::note_extrinsic(encoded); + } - // AUDIT: Under no circumstances may this function panic from here onwards. + // AUDIT: Under no circumstances may this function panic from here onwards. - // Decode parameters and dispatch - let dispatch_info = xt.get_dispatch_info(); - let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; + // Decode parameters and dispatch + let dispatch_info = xt.get_dispatch_info(); + let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; - >::note_applied_extrinsic(&r, dispatch_info); + >::note_applied_extrinsic(&r, dispatch_info); - Ok(r.map(|_| ()).map_err(|e| e.error)) - }) + Ok(r.map(|_| ()).map_err(|e| e.error)) } fn final_checks(header: &System::Header) { - sp_tracing::within_span!(sp_tracing::Level::TRACE, "final_checks"; - { - // remove temporaries - let new_header = >::finalize(); - - // check digest - assert_eq!( - header.digest().logs().len(), - new_header.digest().logs().len(), - "Number of digest items must match that calculated." - ); - let items_zip = header.digest().logs().iter().zip(new_header.digest().logs().iter()); - for (header_item, computed_item) in items_zip { - header_item.check_equal(&computed_item); - assert!(header_item == computed_item, "Digest item must match that calculated."); - } + sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks"); + // remove temporaries + let new_header = >::finalize(); + + // check digest + assert_eq!( + header.digest().logs().len(), + new_header.digest().logs().len(), + "Number of digest items must match that calculated." + ); + let items_zip = header.digest().logs().iter().zip(new_header.digest().logs().iter()); + for (header_item, computed_item) in items_zip { + header_item.check_equal(&computed_item); + assert!(header_item == computed_item, "Digest item must match that calculated."); + } - // check storage root. - let storage_root = new_header.state_root(); - header.state_root().check_equal(&storage_root); - assert!(header.state_root() == storage_root, "Storage root must match that calculated."); - }) + // check storage root. + let storage_root = new_header.state_root(); + header.state_root().check_equal(&storage_root); + assert!(header.state_root() == storage_root, "Storage root must match that calculated."); } /// Check a given signed transaction for validity. This doesn't execute any @@ -423,21 +420,20 @@ where source: TransactionSource, uxt: Block::Extrinsic, ) -> TransactionValidity { - use sp_tracing::{within_span}; + use sp_tracing::{enter_span, within_span}; - within_span!(sp_tracing::Level::TRACE, "validate_transaction"; { + enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" }; - let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; + let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; - let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default()) }?; + let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; - let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; + let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; - within_span! { - sp_tracing::Level::TRACE, "validate"; - xt.validate::(source, &dispatch_info, encoded_len) - } - }) + within_span! { + sp_tracing::Level::TRACE, "validate"; + xt.validate::(source, &dispatch_info, encoded_len) + } } /// Start an offchain worker and generate extrinsics. diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 4fe182f0c8a9d..0544d5b40281d 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1274,9 +1274,8 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_initialize"); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); + { $( $impl )* } } } }; @@ -1291,9 +1290,8 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_initialize($param: $param_ty) -> $return { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_initialize"); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize")); + { $( $impl )* } } } }; @@ -1318,9 +1316,8 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_runtime_upgrade() -> $return { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_runtime_upgrade"); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade")); + { $( $impl )* } } } }; @@ -1374,9 +1371,8 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_finalize"); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); + { $( $impl )* } } } }; @@ -1391,9 +1387,8 @@ macro_rules! decl_module { for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )* { fn on_finalize($param: $param_ty) { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!("on_finalize"); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize")); + { $( $impl )* } } } }; @@ -1461,13 +1456,9 @@ macro_rules! decl_module { $vis fn $name( $origin: $origin_ty $(, $param: $param_ty )* ) -> $crate::dispatch::DispatchResult { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!(stringify!($name)); - { - { $( $impl )* } - Ok(()) - } - } - + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); + { $( $impl )* } + Ok(()) } }; @@ -1484,9 +1475,8 @@ macro_rules! decl_module { ) => { $(#[$fn_attr])* $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { - $crate::sp_tracing::within_span! { $crate::sp_tracing::trace_span!(stringify!($name)); - { $( $impl )* } - } + $crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!(stringify!($name))); + $( $impl )* } }; diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index f2a7053009c56..ce90e9911cbcd 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -17,7 +17,8 @@ //! Substrate tracing primitives and macros. //! -//! To trace functions or invidual code in Substrate, this crate provides [`within_span`]. +//! To trace functions or invidual code in Substrate, this crate provides [`within_span`] +//! and [`enter_span`]. See the individual docs for how to use these macros. //! //! Note that to allow traces from wasm execution environment there are //! 2 reserved identifiers for tracing `Field` recording, stored in the consts: @@ -44,15 +45,24 @@ /// the tracing code in the non-std environment. /// /// Because of that optimisation, you should not use the `span!` and `span_*!` macros -/// directly as they yield nothing without the feature present. Instead you must use -/// `within_span!` – which would strip away even any parameter conversion +/// directly as they yield nothing without the feature present. Instead you should use +/// `enter_span!` and `within_span!` – which would strip away even any parameter conversion /// you do within the span-definition (and thus optimise your performance). For your -/// convinience you directly specify the `Level` and name of the span or use the full +/// convineience you directly specify the `Level` and name of the span or use the full /// feature set of `span!`/`span_*!` on it: /// /// # Example /// /// ```rust +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "fn wide span"); +/// { +/// sp_tracing::enter_span!(sp_tracing::trace_span!("outer-span")); +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); +/// // .. +/// } // inner span exists here +/// } // outer span exists here +/// /// sp_tracing::within_span! { /// sp_tracing::debug_span!("debug-span", you_can_pass="any params"); /// 1 + 1; @@ -261,4 +271,51 @@ macro_rules! within_span { ) => { $( $code )* }; +} + + +/// Enter a span - noop for `no_std` without `with-tracing` +#[cfg(all(not(feature = "std"), not(feature = "with-tracing")))] +#[macro_export] +macro_rules! enter_span { + ( $lvl:expr, $name:expr ) => ( ); + ( $name:expr ) => ( ) // no-op +} + +/// Enter a span. +/// +/// The span will be valid, until the scope is left. Use either level and name +/// or pass in any valid `sp_tracing::Span` for extended usage. The span will +/// be exited on drop – which is at the end of the block or to the next +/// `enter_span!` calls, as this overwrites the local variable. For nested +/// usage or to ensure the span closes at certain time either put it into a block +/// or use `within_span!` +/// +/// # Example +/// +/// ``` +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); +/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); +/// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); +/// +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "outer-span"); +/// { +/// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "inner-span"); +/// // .. +/// } // inner span exists here +/// } // outer span exists here +/// +/// ``` +#[cfg(any(feature = "std", feature = "with-tracing"))] +#[macro_export] +macro_rules! enter_span { + ( $span:expr ) => { + // FIXME: this could be clashing, make the local variable based on name to prevent that + let __within_span__ = $span; + let __tracing_guard__ = __within_span__.enter(); + }; + ( $lvl:expr, $name:expr ) => { + $crate::enter_span!($crate::span!($crate::Level::TRACE, $name)) + }; } \ No newline at end of file From d7ab2b6a65f2c95e9fca63e30a2ddd2ba7c31aea Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 10:34:12 +0200 Subject: [PATCH 082/113] dropping FIXME, it's documented --- primitives/tracing/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index ce90e9911cbcd..5b6309ef5ba8b 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -295,6 +295,7 @@ macro_rules! enter_span { /// /// ``` /// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); +/// // previous will be dropped here /// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); /// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); /// @@ -311,7 +312,8 @@ macro_rules! enter_span { #[macro_export] macro_rules! enter_span { ( $span:expr ) => { - // FIXME: this could be clashing, make the local variable based on name to prevent that + // Calling this twice in a row will overwrite (and drop) the earlier + // that is a _documented feature_! let __within_span__ = $span; let __tracing_guard__ = __within_span__.enter(); }; From 8536f7791d4adc545ce274c89984e455fc1719e6 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 10:50:00 +0200 Subject: [PATCH 083/113] fix formatting --- client/tracing/src/lib.rs | 10 +++++++--- frame/executive/src/lib.rs | 12 +++++++++--- .../proc-macro/src/runtime_interface/mod.rs | 6 +++++- primitives/tracing/src/lib.rs | 7 +++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index e23d8be7eddfa..3c6f7c7045733 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -281,11 +281,15 @@ fn parse_target(s: &str) -> (String, Level) { impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if metadata.target() == WASM_TRACE_IDENTIFIER || self.check_target(metadata.target(), metadata.level()) { - log::debug!(target: "tracing", "Enabled target: {}, level: {}", metadata.target(), metadata.level()); + if metadata.target() == WASM_TRACE_IDENTIFIER + || self.check_target(metadata.target(), metadata.level()) + { + log::debug!(target: "tracing", "Enabled target: {}, level: {}", + metadata.target(), metadata.level()); true } else { - log::debug!(target: "tracing", "Disabled target: {}, level: {}", metadata.target(), metadata.level()); + log::debug!(target: "tracing", "Disabled target: {}, level: {}", + metadata.target(), metadata.level()); false } } diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 8def4e0c022dd..41bc15bbd4e35 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -424,11 +424,17 @@ where enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" }; - let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; uxt.using_encoded(|d| d.len()) }; + let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded"; + uxt.using_encoded(|d| d.len()) + }; - let xt = within_span!{ sp_tracing::Level::TRACE, "check"; uxt.check(&Default::default())? }; + let xt = within_span!{ sp_tracing::Level::TRACE, "check"; + uxt.check(&Default::default()) + }?; - let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; xt.get_dispatch_info() }; + let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info"; + xt.get_dispatch_info() + }; within_span! { sp_tracing::Level::TRACE, "validate"; diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs index 18d5d371ee1b3..b49ea974d2eb9 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs @@ -41,7 +41,11 @@ pub mod keywords { /// /// It expects the trait definition the attribute was put above and if this should be an wasm only /// interface. -pub fn runtime_interface_impl(trait_def: ItemTrait, is_wasm_only: bool, tracing: bool) -> Result { +pub fn runtime_interface_impl( + trait_def: ItemTrait, + is_wasm_only: bool, + tracing: bool +) -> Result { let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only, tracing)?; let crate_include = generate_runtime_interface_include(); let mod_name = Ident::new(&trait_def.ident.to_string().to_snake_case(), Span::call_site()); diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 5b6309ef5ba8b..43f4f06eb4674 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -163,7 +163,9 @@ mod global_subscription { inner: UnsafeCell>> } - static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder { inner: UnsafeCell::new(None) }; + static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder { + inner: UnsafeCell::new(None) + }; unsafe impl core::marker::Sync for SubscriptionHolder {} @@ -296,7 +298,8 @@ macro_rules! enter_span { /// ``` /// sp_tracing::enter_span!(sp_tracing::Level::TRACE, "test-span"); /// // previous will be dropped here -/// sp_tracing::enter_span!(sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); +/// sp_tracing::enter_span!( +/// sp_tracing::span!(sp_tracing::Level::DEBUG, "debug-span", params="value")); /// sp_tracing::enter_span!(sp_tracing::info_span!("info-span", params="value")); /// /// { From 5194d0d7227e85a58cf4dbe2ef89f5e21589d52d Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 11:59:05 +0200 Subject: [PATCH 084/113] fix formatting --- primitives/tracing/src/types.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index be5591a5fbc29..f84907f349e3b 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -403,7 +403,8 @@ mod std_features { /// The fieldname for the wasm-originated target pub static WASM_TARGET_KEY: &'static str = "target"; /// The the list of all static field names we construct from the given metadata - pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, "file", "line", "module_path", "params"]; + pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, + "file", "line", "module_path", "params"]; // Implementation Note: // the original `tracing` crate generates these static metadata entries at every `span!` and From 21eddadbe7d4384f51f31e3f5f71816b22686fb8 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 2 Sep 2020 12:01:12 +0200 Subject: [PATCH 085/113] fix imports --- frame/timestamp/src/lib.rs | 2 +- primitives/tracing/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index e59e6463302f7..e0fa606ba89f4 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -95,7 +95,7 @@ mod benchmarking; mod default_weights; -use sp_std::{result, cmp, vec, vec::Vec}; +use sp_std::{result, cmp, vec}; use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier}; #[cfg(feature = "std")] use frame_support::debug; diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index d2bfdb777d0f6..46b7891934e2d 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -18,7 +18,7 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] sp-std = { version = "2.0.0-rc6", path = "../std", default-features = false} -codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false} +codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false, features = ["derive"]} tracing = { version = "0.1.18", default-features = false } tracing-core = { version = "0.1.13", optional = true } log = { version = "0.4.8", optional = true } From 47cb3907026883a86045e7a4e264b5e079036691 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 3 Sep 2020 11:32:18 +0200 Subject: [PATCH 086/113] more debug info --- client/tracing/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 3c6f7c7045733..b44234b42caf4 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -284,8 +284,8 @@ impl Subscriber for ProfilingSubscriber { if metadata.target() == WASM_TRACE_IDENTIFIER || self.check_target(metadata.target(), metadata.level()) { - log::debug!(target: "tracing", "Enabled target: {}, level: {}", - metadata.target(), metadata.level()); + log::debug!(target: "tracing", "Enabled target: {:?}", + metadata); true } else { log::debug!(target: "tracing", "Disabled target: {}, level: {}", From e3c6e0a16be8745bbe5f852b1e0b8c94c94fd6e5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 3 Sep 2020 11:32:44 +0200 Subject: [PATCH 087/113] inform wasm about it being disabled by returning 1 --- client/tracing/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index b44234b42caf4..0eb3ccfbcbf0f 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -298,11 +298,13 @@ impl Subscriber for ProfilingSubscriber { let id = Id::from_u64(self.next_id.fetch_add(1, Ordering::Relaxed)); let mut values = Values::default(); attrs.record(&mut values); + if attrs.metadata().target() == WASM_TRACE_IDENTIFIER { // 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 id + // returning as disabled + return Id::from_u64(0) } } } From 5fa4a8b6097286db05c63f84a07d1edb0834fad8 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 3 Sep 2020 11:36:33 +0200 Subject: [PATCH 088/113] only one tracer, but enabled multi-all support --- frame/executive/src/lib.rs | 4 ++ primitives/io/src/lib.rs | 87 +++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 41bc15bbd4e35..5f370643094f8 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -207,6 +207,7 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { + sp_io::init_tracing(); sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block"); let digests = Self::extract_pre_digest(&header); Self::initialize_block_impl( @@ -327,6 +328,7 @@ where /// Finalize the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalize_block() -> System::Header { + sp_io::init_tracing(); sp_tracing::enter_span!( sp_tracing::Level::TRACE, "finalize_block" ); >::note_finished_extrinsics(); let block_number = >::block_number(); @@ -420,6 +422,7 @@ where source: TransactionSource, uxt: Block::Extrinsic, ) -> TransactionValidity { + sp_io::init_tracing(); use sp_tracing::{enter_span, within_span}; enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" }; @@ -444,6 +447,7 @@ where /// Start an offchain worker and generate extrinsics. pub fn offchain_worker(header: &System::Header) { + sp_io::init_tracing(); // We need to keep events available for offchain workers, // hence we initialize the block manually. // OffchainWorker RuntimeApi should skip initialization. diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 208857bba1283..2aaf5d1527eb1 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1030,8 +1030,8 @@ impl core::default::Default for Crossing /// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate /// interfaces. See `sp-tracing` for more information. -#[runtime_interface(wasm_only,no_tracing)] -pub trait WasmTracing { +#[runtime_interface(wasm_only, no_tracing)] +trait WasmTracing { /// Given the crossing over `WasmMetadata`, return whether this should be handled or not. /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. /// @@ -1086,45 +1086,62 @@ pub trait WasmTracing { } } -#[cfg(not(feature="std"))] -/// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` -/// and pushes the information accross the runtime interface to the host -pub struct PassingTracingSubsciber; -#[cfg(not(feature="std"))] -impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { - fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { - wasm_tracing::enabled(Crossing(metadata.clone())) - } - fn enter_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { - wasm_tracing::enter_span(Crossing(attrs)) - } - fn event(&self, - parent_id: Option, - metadata: &sp_tracing::WasmMetadata, - values: &sp_tracing::WasmValuesSet - ) { - wasm_tracing::event(Crossing(sp_tracing::WasmEntryAttributes { - parent_id, - metadata: metadata.clone(), - fields: values.clone() - })) +#[cfg(all(not(feature="std"), feature="with-tracing"))] +mod tracing_setup { + use core::sync::atomic::{AtomicBool, Ordering}; + use sp_std::boxed::Box; + use super::{wasm_tracing, Crossing}; + + const TRACING_SET : AtomicBool = AtomicBool::new(false); + + + /// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` + /// and pushes the information accross the runtime interface to the host + struct PassingTracingSubsciber; + + impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { + fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { + wasm_tracing::enabled(Crossing(metadata.clone())) + } + fn enter_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { + wasm_tracing::enter_span(Crossing(attrs)) + } + fn event(&self, + parent_id: Option, + metadata: &sp_tracing::WasmMetadata, + values: &sp_tracing::WasmValuesSet + ) { + wasm_tracing::event(Crossing(sp_tracing::WasmEntryAttributes { + parent_id, + metadata: metadata.clone(), + fields: values.clone() + })) + } + fn exit(&self, span: u64) { + wasm_tracing::exit(span) + } } - fn exit(&self, span: u64) { - wasm_tracing::exit(span) + + + /// Initialize tracing of sp_tracing on wasm with `with-tracing` enabled. + /// Can be called multiple times from within the same process will only + /// set the global bridgin subscriber once. + pub fn init_tracing() { + if TRACING_SET.load(Ordering::Relaxed) == false { + sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber {} )); + TRACING_SET.store(true, Ordering::Relaxed); + } } } -#[cfg(all(not(feature="std"), feature="with-tracing"))] -/// Initialize tracing of sp_tracing on wasm with `with-tracing` enabled -pub fn init_tracing() { - use sp_std::boxed::Box; - sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber {} )); +#[cfg(not(all(not(feature="std"), feature="with-tracing")))] +mod tracing_setup { + /// Initialize tracing of sp_tracing not necessary – noop. To enable build + /// without std and with the `with-tracing`-feature. + pub fn init_tracing() { } } -#[cfg(not(all(not(feature="std"), feature="with-tracing")))] -/// Initialize tracing of sp_tracing not necessary – noop. To enable build -/// without std and with the `with-tracing`-feature. -pub fn init_tracing() { } +pub use tracing_setup::init_tracing; /// Wasm-only interface that provides functions for interacting with the sandbox. #[runtime_interface(wasm_only)] From 3d67c9d0b71c897809c090d174b66c6cf72796ca Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 3 Sep 2020 13:03:03 +0200 Subject: [PATCH 089/113] make trait pub again for tests --- primitives/io/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 2aaf5d1527eb1..51f964681cff9 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1031,7 +1031,7 @@ impl core::default::Default for Crossing /// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate /// interfaces. See `sp-tracing` for more information. #[runtime_interface(wasm_only, no_tracing)] -trait WasmTracing { +pub trait WasmTracing { /// Given the crossing over `WasmMetadata`, return whether this should be handled or not. /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. /// From 489792639ea03456561d3d8c1177424b43a8b387 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 10:23:30 +0200 Subject: [PATCH 090/113] Apply suggestions from code review Co-authored-by: Niklas Adolfsson --- client/tracing/src/lib.rs | 5 +++++ frame/offences/src/lib.rs | 2 +- primitives/io/src/lib.rs | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 0eb3ccfbcbf0f..78bacc1af9827 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -48,6 +48,11 @@ 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. +/// +/// This profiler notably implements full ref-counting – using `clone_span` – to allow +/// for proper tracking over the Wasm-Native-Barrier. If you replace this subscriber +/// with a different one, be sure to implement that feature, too, or you won't be able +/// to trace wasm-side-entries correctly. pub struct ProfilingSubscriber { next_id: AtomicU64, targets: Vec<(String, Level)>, diff --git a/frame/offences/src/lib.rs b/frame/offences/src/lib.rs index 351c10dc2f41c..9a067d903fe2d 100644 --- a/frame/offences/src/lib.rs +++ b/frame/offences/src/lib.rs @@ -25,7 +25,7 @@ mod mock; mod tests; -use sp_std::{vec, vec::Vec}; +use sp_std::vec::Vec; use frame_support::{ decl_module, decl_event, decl_storage, Parameter, debug, traits::Get, diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 51f964681cff9..b50008374bc3b 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1036,12 +1036,12 @@ pub trait WasmTracing { /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. /// /// When returning false the calling code should skip any tracing-related execution. In general - /// within the same block execution this is not exepected to change and there doesn't have to be - /// checked more than once per metadata. This exists for optimisation purposes but is still not + /// within the same block execution this is not expected to change and there doesn't have to be + /// checked more than once per metadata. This exists for optimisation purposes but is still not /// cheap as it needs to jump the wasm-native-barrier, so caching the result wasm-side might be /// a useful addition. fn enabled(&mut self, metadata: Crossing) -> bool { - let metadata : &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); + let metadata: &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); tracing::dispatcher::get_default(|d| { d.enabled(metadata) }) @@ -1052,10 +1052,10 @@ pub trait WasmTracing { /// /// On the native side this goes through the default `tracing` dispatcher to register the span /// and then calls `clone_span` with the ID to signal that we are keeping it around on the wasm- - /// side even after the local span is dropped. The resulting ID is then handed over to the waasm- + /// side even after the local span is dropped. The resulting ID is then handed over to the wasm- /// side. fn enter_span(&mut self, span: Crossing) -> u64 { - let span : tracing::Span = span.into_inner().into(); + let span: tracing::Span = span.into_inner().into(); match span.id() { Some(id) => tracing::dispatcher::get_default(|d| { // inform dispatch that we'll keep the ID around From c00dd61595287436a34ec6354e96af61100928a1 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 10:40:03 +0200 Subject: [PATCH 091/113] fixing wasm doc tests for proper usage --- primitives/tracing/src/wasm_tracing.rs | 103 +++++++++++++------------ 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs index 349fdf4240d4d..13dcd5769dc93 100644 --- a/primitives/tracing/src/wasm_tracing.rs +++ b/primitives/tracing/src/wasm_tracing.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -#![no_std] - #[cfg(not(feature = "with-tracing"))] mod inner { // we are no-op @@ -453,11 +451,11 @@ pub use inner::*; /// /// Creating a new span: /// ``` -/// # use sp_tracing::{span, Level}; +/// # use sp_tracing::{within_span, span, Level}; /// # fn main() { -/// let span = span!(Level::TRACE, "my span"); -/// let _enter = span.enter(); +/// within_span!(span!(Level::TRACE, "my span"); { /// // do work inside the span... +/// }); /// # } /// ``` #[macro_export] @@ -519,7 +517,7 @@ macro_rules! span { }; } -/// Constructs a span at the trace level. +/// Constructs a span at the trace level to be used with [`enter_span!`] and [`within_span!`] /// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] /// macro. @@ -531,24 +529,25 @@ macro_rules! span { /// [attributes]: index.html#configuring-attributes /// [Fields]: index.html#recording-fields /// [`span!`]: macro.span.html +/// [`enter_span!`]: macro.enter_span.html +/// [`within_span!`]: macro.within_span.html /// /// # Examples /// /// ``` -/// # use sp_tracing::{trace_span, span, Level}; +/// # use sp_tracing::{enter_span, trace_span, span, Level}; /// # fn main() { -/// trace_span!("my_span"); +/// enter_span!(trace_span!("my_span")); /// // is equivalent to: -/// span!(Level::TRACE, "my_span"); +/// enter_span!(span!(Level::TRACE, "my_span")); /// # } /// ``` /// /// ``` -/// # use sp_tracing::{trace_span, span, Level}; +/// # use sp_tracing::{within_span, trace_span, span, Level}; /// # fn main() { -/// let span = trace_span!("my span"); -/// span.in_scope(|| { -/// // do work inside the span... +/// within_span!(trace_span!("my span"); { +/// // whatever should happen /// }); /// # } /// ``` @@ -600,7 +599,7 @@ macro_rules! trace_span { ($name:expr) => { $crate::trace_span!($name,) }; } -/// Constructs a span at the debug level. +/// Constructs a span at the debug level to be used with [`enter_span!`] and [`within_span!`] /// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] /// macro. @@ -612,25 +611,26 @@ macro_rules! trace_span { /// [attributes]: index.html#configuring-attributes /// [Fields]: index.html#recording-fields /// [`span!`]: macro.span.html +/// [`enter_span!`]: macro.enter_span.html +/// [`within_span!`]: macro.within_span.html /// /// # Examples /// /// ```rust -/// # use sp_tracing::{debug_span, span, Level}; +/// # use sp_tracing::{enter_span, debug_span, span, Level}; /// # fn main() { -/// debug_span!("my_span"); +/// enter_span!(debug_span!("my_span")); /// // is equivalent to: -/// span!(Level::DEBUG, "my_span"); +/// enter_span!(span!(Level::DEBUG, "my_span")); /// # } /// ``` /// /// ```rust -/// # use sp_tracing::debug_span; +/// # use sp_tracing::{within_span, debug_span}; /// # fn main() { -/// let span = debug_span!("my span"); -/// span.in_scope(|| { -/// // do work inside the span... -/// }); +/// within_span! { debug_span!("my span"); +/// // do the work +/// }; /// # } /// ``` #[macro_export] @@ -681,7 +681,7 @@ macro_rules! debug_span { ($name:expr) => {$crate::debug_span!($name,)}; } -/// Constructs a span at the info level. +/// Constructs a span at the info level to be used with [`enter_span!`] and [`within_span!`] /// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] /// macro. @@ -693,25 +693,27 @@ macro_rules! debug_span { /// [attributes]: index.html#configuring-attributes /// [Fields]: index.html#recording-fields /// [`span!`]: macro.span.html +/// [`enter_span!`]: macro.enter_span.html +/// [`within_span!`]: macro.within_span.html /// /// # Examples /// /// ```rust -/// # use sp_tracing::{span, info_span, Level}; +/// # use sp_tracing::{enter_span, span, info_span, Level}; /// # fn main() { -/// info_span!("my_span"); +/// enter_span!(info_span!("my_span")); /// // is equivalent to: -/// span!(Level::INFO, "my_span"); +/// enter_span!(span!(Level::INFO, "my_span")); /// # } /// ``` /// /// ```rust -/// # use sp_tracing::info_span; +/// # use sp_tracing::{within_span, info_span}; /// # fn main() { -/// let span = info_span!("my span"); -/// span.in_scope(|| { -/// // do work inside the span... -/// }); +/// within_span! { info_span!("my span"); +/// 1 + 1; +/// // do the work +/// }; /// # } /// ``` #[macro_export] @@ -762,7 +764,7 @@ macro_rules! info_span { ($name:expr) => {$crate::info_span!($name,)}; } -/// Constructs a span at the warn level. +/// Constructs a span at the warn level to be used with [`enter_span!`] and [`within_span!`] /// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] /// macro. @@ -774,25 +776,26 @@ macro_rules! info_span { /// [attributes]: index.html#configuring-attributes /// [Fields]: index.html#recording-fields /// [`span!`]: macro.span.html +/// [`enter_span!`]: macro.enter_span.html +/// [`within_span!`]: macro.within_span.html /// /// # Examples /// /// ```rust -/// # use sp_tracing::{warn_span, span, Level}; +/// # use sp_tracing::{enter_span, warn_span, span, Level}; /// # fn main() { -/// warn_span!("my_span"); +/// enter_span!(warn_span!("my_span")); /// // is equivalent to: -/// span!(Level::WARN, "my_span"); +/// enter_span!(span!(Level::WARN, "my_span")); /// # } /// ``` /// /// ```rust -/// use sp_tracing::warn_span; +/// use sp_tracing::{within_span, warn_span}; /// # fn main() { -/// let span = warn_span!("my span"); -/// span.in_scope(|| { -/// // do work inside the span... -/// }); +/// within_span! { warn_span!("my span"); +/// // do the work +/// } /// # } /// ``` #[macro_export] @@ -842,7 +845,7 @@ macro_rules! warn_span { }; ($name:expr) => {$crate::warn_span!($name,)}; } -/// Constructs a span at the error level. +/// Constructs a span at the error level to be used with [`enter_span!`] and [`within_span!`] /// /// [Fields] and [attributes] are set using the same syntax as the [`span!`] /// macro. @@ -854,25 +857,27 @@ macro_rules! warn_span { /// [attributes]: index.html#configuring-attributes /// [Fields]: index.html#recording-fields /// [`span!`]: macro.span.html +/// [`enter_span!`]: macro.enter_span.html +/// [`within_span!`]: macro.within_span.html /// /// # Examples /// /// ```rust -/// # use sp_tracing::{span, error_span, Level}; +/// # use sp_tracing::{enter_span, span, error_span, Level}; /// # fn main() { -/// error_span!("my_span"); +/// enter_span!(error_span!("my_span")); /// // is equivalent to: -/// span!(Level::ERROR, "my_span"); +/// enter_span!(span!(Level::ERROR, "my_span")); /// # } /// ``` /// /// ```rust -/// # use sp_tracing::error_span; +/// # use sp_tracing::{within_span, error_span}; /// # fn main() { -/// let span = error_span!("my span"); -/// span.in_scope(|| { -/// // do work inside the span... -/// }); +/// within_span!{ error_span!("my span"); +/// // do the work +/// 1 + 1; +/// } /// # } /// ``` #[macro_export] From 88b59574476097dbfacef1e3925bd85f59e987ce Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 12:57:18 +0200 Subject: [PATCH 092/113] remove unnecessary import --- frame/timestamp/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index e0fa606ba89f4..d74a94cb9201b 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -95,7 +95,7 @@ mod benchmarking; mod default_weights; -use sp_std::{result, cmp, vec}; +use sp_std::{result, cmp}; use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier}; #[cfg(feature = "std")] use frame_support::debug; From 7419129fe1acd4e06856f3665c540cf0a735b362 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 17:31:12 +0200 Subject: [PATCH 093/113] fixing formatting --- .../runtime-interface/proc-macro/src/lib.rs | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/primitives/runtime-interface/proc-macro/src/lib.rs b/primitives/runtime-interface/proc-macro/src/lib.rs index a54e99ea6c01a..356de234c502f 100644 --- a/primitives/runtime-interface/proc-macro/src/lib.rs +++ b/primitives/runtime-interface/proc-macro/src/lib.rs @@ -34,70 +34,69 @@ mod runtime_interface; mod utils; struct Options { - wasm_only: bool, - tracing: bool + wasm_only: bool, + tracing: bool } impl Options { - fn unpack(self) -> (bool, bool) { - (self.wasm_only, self.tracing) - } + fn unpack(self) -> (bool, bool) { + (self.wasm_only, self.tracing) + } } impl Default for Options { - fn default() -> Self { - Options { wasm_only: false, tracing: true } - } + fn default() -> Self { + Options { wasm_only: false, tracing: true } + } } impl Parse for Options { fn parse(input: ParseStream) -> Result { - let mut res = Self::default(); - while !input.is_empty() { - let lookahead = input.lookahead1(); - if lookahead.peek(runtime_interface::keywords::wasm_only) { - let _ = input.parse::(); - res.wasm_only = true; - } else if lookahead.peek(runtime_interface::keywords::no_tracing) { - let _ = input.parse::(); - res.tracing = false; - } else if lookahead.peek(Token![,]) { - let _ = input.parse::(); - } else { - return Err(lookahead.error()) - } - } - Ok(res) - } - + let mut res = Self::default(); + while !input.is_empty() { + let lookahead = input.lookahead1(); + if lookahead.peek(runtime_interface::keywords::wasm_only) { + let _ = input.parse::(); + res.wasm_only = true; + } else if lookahead.peek(runtime_interface::keywords::no_tracing) { + let _ = input.parse::(); + res.tracing = false; + } else if lookahead.peek(Token![,]) { + let _ = input.parse::(); + } else { + return Err(lookahead.error()) + } + } + Ok(res) + } } #[proc_macro_attribute] pub fn runtime_interface( - attrs: proc_macro::TokenStream, - input: proc_macro::TokenStream, + attrs: proc_macro::TokenStream, + input: proc_macro::TokenStream, ) -> proc_macro::TokenStream { - let trait_def = parse_macro_input!(input as ItemTrait); - let (wasm_only, tracing) = parse_macro_input!(attrs as Options).unpack(); + let trait_def = parse_macro_input!(input as ItemTrait); + let (wasm_only, tracing) = parse_macro_input!(attrs as Options).unpack(); - runtime_interface::runtime_interface_impl(trait_def, wasm_only, tracing) - .unwrap_or_else(|e| e.to_compile_error()) - .into() + runtime_interface::runtime_interface_impl(trait_def, wasm_only, tracing) + .unwrap_or_else(|e| e.to_compile_error()) + .into() } #[proc_macro_derive(PassByCodec)] pub fn pass_by_codec(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::codec_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() + let input = parse_macro_input!(input as DeriveInput); + pass_by::codec_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() } #[proc_macro_derive(PassByInner)] pub fn pass_by_inner(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::inner_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() + let input = parse_macro_input!(input as DeriveInput); + pass_by::inner_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() } #[proc_macro_derive(PassByEnum)] pub fn pass_by_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::enum_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() + let input = parse_macro_input!(input as DeriveInput); + pass_by::enum_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() } From 38c1e4211b92d265338fde604ecfcff7cdee615a Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 17:40:03 +0200 Subject: [PATCH 094/113] minor style fixes --- .../proc-macro/src/runtime_interface/bare_function_interface.rs | 2 +- .../runtime-interface/proc-macro/src/runtime_interface/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index 30ee483492149..e93548f7ae550 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -195,7 +195,7 @@ fn generate_call_to_trait( trait_name: &Ident, method: &TraitItemMethod, version: u32, - is_wasm_only: bool + is_wasm_only: bool, ) -> TokenStream { let crate_ = generate_crate_access(); let method_name = create_function_ident_with_version(&method.sig.ident, version); diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs index b49ea974d2eb9..02c291975738c 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/mod.rs @@ -44,7 +44,7 @@ pub mod keywords { pub fn runtime_interface_impl( trait_def: ItemTrait, is_wasm_only: bool, - tracing: bool + tracing: bool, ) -> Result { let bare_functions = bare_function_interface::generate(&trait_def, is_wasm_only, tracing)?; let crate_include = generate_runtime_interface_include(); From 6d54ad64fc41bdf84fc35d0c6f531ddc08624806 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 18:52:55 +0200 Subject: [PATCH 095/113] downgrading wabt --- Cargo.lock | 883 +++++++++++++++++----------------- bin/node/executor/Cargo.toml | 2 +- bin/node/testing/Cargo.toml | 2 +- client/executor/Cargo.toml | 2 +- frame/support/test/Cargo.toml | 2 +- primitives/sandbox/Cargo.toml | 2 +- 6 files changed, 453 insertions(+), 440 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d17ad6dd79e47..1869842dec911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,12 +25,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" -[[package]] -name = "adler32" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" - [[package]] name = "aead" version = "0.3.2" @@ -73,7 +67,7 @@ dependencies = [ "aes", "block-cipher", "ghash", - "subtle 2.2.2", + "subtle 2.2.3", ] [[package]] @@ -136,9 +130,9 @@ checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" [[package]] name = "aho-corasick" -version = "0.7.10" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" dependencies = [ "memchr", ] @@ -160,7 +154,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -169,14 +163,14 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "anyhow" -version = "1.0.28" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" +checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" [[package]] name = "approx" @@ -189,15 +183,15 @@ dependencies = [ [[package]] name = "arbitrary" -version = "0.4.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75153c95fdedd7db9732dfbfc3702324a1627eec91ba56e37cd0ac78314ab2ed" +checksum = "7cb544f1057eaaff4b34f8c4dcf56fc3cd04debd291998405d135017a7c3c0f4" [[package]] name = "arc-swap" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" +checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" [[package]] name = "arrayref" @@ -258,6 +252,17 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5" +[[package]] +name = "async-channel" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee81ba99bee79f3c8ae114ae4baa7eaa326f63447cf2ec65e4393618b63f8770" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + [[package]] name = "async-std" version = "1.6.2" @@ -317,6 +322,12 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64f46ca51dca4837f1520754d1c8c36636356b81553d928dc9c177025369a06e" +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "atty" version = "0.2.14" @@ -325,7 +336,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -349,7 +360,7 @@ dependencies = [ "addr2line", "cfg-if", "libc", - "miniz_oxide 0.4.0", + "miniz_oxide", "object 0.20.0", "rustc-demangle", ] @@ -374,9 +385,9 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "bincode" -version = "1.2.1" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" dependencies = [ "byteorder 1.3.4", "serde", @@ -393,7 +404,7 @@ dependencies = [ "cfg-if", "clang-sys", "clap", - "env_logger 0.7.1", + "env_logger", "lazy_static", "lazycell", "log", @@ -418,7 +429,7 @@ dependencies = [ "once_cell 0.1.8", "pbkdf2", "rand 0.6.5", - "sha2 0.8.1", + "sha2 0.8.2", ] [[package]] @@ -538,12 +549,13 @@ dependencies = [ [[package]] name = "blocking" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d17efb70ce4421e351d61aafd90c16a20fb5bfe339fcdc32a86816280e62ce0" +checksum = "d2468ff7bf85066b4a3678fede6fe66db31846d753ff0adfbfab2c6a6e81612b" dependencies = [ - "futures-channel", - "futures-util", + "async-channel", + "atomic-waker", + "futures-lite", "once_cell 1.4.0", "parking", "waker-fn", @@ -557,9 +569,9 @@ checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" [[package]] name = "bstr" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" dependencies = [ "lazy_static", "memchr", @@ -578,9 +590,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.2.1" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ae9db68ad7fac5fe51304d20f016c911539251075a214f8e663babefa35187" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" [[package]] name = "byte-slice-cast" @@ -619,9 +631,9 @@ dependencies = [ [[package]] name = "bytes" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" [[package]] name = "c_linked_list" @@ -631,9 +643,9 @@ checksum = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" [[package]] name = "cache-padded" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24508e28c677875c380c20f4d28124fab6f8ed4ef929a1397d7b1a31e92f1005" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cargo_metadata" @@ -658,9 +670,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.50" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" dependencies = [ "jobserver", ] @@ -718,9 +730,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" dependencies = [ "js-sys", "num-integer", @@ -742,9 +754,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ "ansi_term 0.11.0", "atty", @@ -775,9 +787,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.42" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" dependencies = [ "cc", ] @@ -1024,12 +1036,13 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ "cfg-if", "crossbeam-utils", + "maybe-uninit", ] [[package]] @@ -1066,7 +1079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ "generic-array 0.14.3", - "subtle 2.2.2", + "subtle 2.2.3", ] [[package]] @@ -1102,9 +1115,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" +checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227" dependencies = [ "quote", "syn", @@ -1132,28 +1145,28 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839" +checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5" dependencies = [ "byteorder 1.3.4", "digest 0.8.1", "rand_core 0.5.1", - "subtle 2.2.2", + "subtle 2.2.3", "zeroize", ] [[package]] name = "data-encoding" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c0346158a19b3627234e15596f5e465c360fcdb97d817bcb255e0510f5a788" +checksum = "72aa14c04dfae8dd7d8a2b1cb7ca2152618cd01336dbfe704b8dcbf8d41dbd69" [[package]] name = "derive_more" -version = "0.99.5" +version = "0.99.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7" +checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76" dependencies = [ "proc-macro2", "quote", @@ -1196,14 +1209,13 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" dependencies = [ - "cfg-if", "libc", "redox_users", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1274,49 +1286,36 @@ dependencies = [ "ed25519", "rand 0.7.3", "serde", - "sha2 0.8.1", + "sha2 0.8.2", "zeroize", ] [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "enumflags2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a80e524ebf194285b57e5e7944018721c7fffc673253f5183f7accd88a2a3b0c" +checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed9afacaea0301eefb738c9deea725e6d53938004597cdc518a8cf9a7aa2f03" +checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "env_logger" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.7.1" @@ -1338,22 +1337,22 @@ checksum = "516aa8d7a71cb00a1c4146f0798549b93d083d4f189b3ced8f3de6b8f11ee6c4" [[package]] name = "erased-serde" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88b6d1705e16a4d62e05ea61cc0496c2bd190f4fa8e5c1f11ce747be6bcf3d1" +checksum = "6ca8b296792113e1500fd935ae487be6e00ce318952a6880555554824d6ebf38" dependencies = [ "serde", ] [[package]] name = "errno" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b480f641ccf0faf324e20c1d3e53d81b7484c698b42ea677f6907ae4db195371" +checksum = "6eab5ee3df98a279d9b316b1af6ac95422127b1290317e6d18c1743c99418b01" dependencies = [ "errno-dragonfly", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1393,6 +1392,12 @@ dependencies = [ "uint", ] +[[package]] +name = "event-listener" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "699d84875f1b72b4da017e6b0f77dfa88c0137f089958a88974d15938cbc2976" + [[package]] name = "evm" version = "0.17.0" @@ -1450,9 +1455,9 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ "backtrace", "failure_derive", @@ -1460,9 +1465,9 @@ dependencies = [ [[package]] name = "failure_derive" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2", "quote", @@ -1484,9 +1489,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b90eb1dec02087df472ab9f0db65f27edaa654a746830042688bcc2eaf68090f" +checksum = "36a9cb09840f81cd211e435d00a4e487edd263dc3c8ff815c32dd76ad668ebed" [[package]] name = "fdlimit" @@ -1499,11 +1504,11 @@ dependencies = [ [[package]] name = "file-per-thread-logger" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8505b75b31ef7285168dd237c4a7db3c1f3e0927e7d314e670bc98e854272fe9" +checksum = "8b3937f028664bd0e13df401ba49a4567ccda587420365823242977f06609ed1" dependencies = [ - "env_logger 0.6.2", + "env_logger", "log", ] @@ -1525,9 +1530,9 @@ dependencies = [ [[package]] name = "fixed-hash" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32529fc42e86ec06e5047092082aab9ad459b070c5d2a76b14f4f5ce70bf2e84" +checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" dependencies = [ "byteorder 1.3.4", "rand 0.7.3", @@ -1543,22 +1548,22 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" [[package]] name = "flate2" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42" +checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" dependencies = [ "cfg-if", "crc32fast", "libc", "libz-sys", - "miniz_oxide 0.3.6", + "miniz_oxide", ] [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" @@ -1757,7 +1762,7 @@ dependencies = [ "lazy_static", "libc", "libloading", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1767,7 +1772,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1894,6 +1899,21 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" +[[package]] +name = "futures-lite" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180d8fc9819eb48a0c976672fbeea13a73e10999e812bdc9e14644c25ad51d60" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.5" @@ -1976,7 +1996,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce54d63f8b0c75023ed920d46fd71d0cbbb830b0ee012726b5b4f506fb6dea5b" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures 0.3.5", "memchr", "pin-project", @@ -2125,21 +2145,21 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "377038bf3c89d18d6ca1431e7a5027194fbd724ca10592b9487ede5e8e144f42" +checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "futures-core", "futures-sink", "futures-util", "http 0.2.1", "indexmap", - "log", "slab", - "tokio 0.2.21", + "tokio 0.2.22", "tokio-util", + "tracing", ] [[package]] @@ -2185,9 +2205,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9b7860757ce258c89fd48d28b68c41713e597a7b09e793f6c6a6e2ea37c827" +checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" dependencies = [ "ahash 0.3.8", "autocfg 1.0.0", @@ -2204,9 +2224,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.10" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] @@ -2278,7 +2298,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "itoa", ] @@ -2301,7 +2321,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "http 0.2.1", ] @@ -2352,25 +2372,25 @@ dependencies = [ [[package]] name = "hyper" -version = "0.13.4" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6081100e960d9d74734659ffc9cc91daf1c0fc7aceb8eaa94ee1a3f5046f2e" +checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures-channel", "futures-core", "futures-util", - "h2 0.2.4", + "h2 0.2.6", "http 0.2.1", "http-body 0.3.1", "httparse", "itoa", - "log", - "net2", "pin-project", + "socket2", "time", - "tokio 0.2.21", + "tokio 0.2.22", "tower-service", + "tracing", "want 0.3.0", ] @@ -2380,14 +2400,14 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "ct-logs", "futures-util", - "hyper 0.13.4", + "hyper 0.13.7", "log", "rustls", "rustls-native-certs", - "tokio 0.2.21", + "tokio 0.2.22", "tokio-rustls", "webpki", ] @@ -2454,11 +2474,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.3.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" dependencies = [ "autocfg 1.0.0", + "hashbrown 0.8.1", "serde", ] @@ -2525,9 +2546,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "jobserver" @@ -2540,9 +2561,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.37" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a27d435371a2fa5b6d2b028a74bbdb1234f308da363226a2854ca3ff8ba7055" +checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916" dependencies = [ "wasm-bindgen", ] @@ -2699,9 +2720,9 @@ dependencies = [ [[package]] name = "kv-log-macro" -version = "1.0.4" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c54d9f465d530a752e6ebdc217e081a7a614b48cb200f6f0aee21ba6bc9aabb" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" dependencies = [ "log", ] @@ -2782,9 +2803,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.71" +version = "0.2.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" [[package]] name = "libloading" @@ -2793,7 +2814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" dependencies = [ "cc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -2809,7 +2830,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76c101edbb9c06955fd4085b77d2abc31cf3650134d77068b35c44967756ada8" dependencies = [ "atomic", - "bytes 0.5.4", + "bytes 0.5.6", "futures 0.3.5", "lazy_static", "libp2p-core", @@ -2868,7 +2889,7 @@ dependencies = [ "rand 0.7.3", "ring", "rw-stream-sink", - "sha2 0.8.1", + "sha2 0.8.2", "smallvec 1.4.1", "thiserror", "unsigned-varint 0.4.0", @@ -2933,7 +2954,7 @@ checksum = "0828b4f0c76c2edc68da574e391ce981bac5316d65785cddfe8c273d4c9bd4bb" dependencies = [ "base64 0.11.0", "byteorder 1.3.4", - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "futures 0.3.5", "futures_codec", @@ -2945,7 +2966,7 @@ dependencies = [ "prost", "prost-build", "rand 0.7.3", - "sha2 0.8.1", + "sha2 0.8.2", "smallvec 1.4.1", "unsigned-varint 0.4.0", "wasm-timer", @@ -2974,7 +2995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca9b4ccc868863317af3f65eb241811ceadd971d133183040140f5496037e0ae" dependencies = [ "arrayvec 0.5.1", - "bytes 0.5.4", + "bytes 0.5.6", "either", "fnv", "futures 0.3.5", @@ -2986,7 +3007,7 @@ dependencies = [ "prost", "prost-build", "rand 0.7.3", - "sha2 0.8.1", + "sha2 0.8.2", "smallvec 1.4.1", "uint", "unsigned-varint 0.4.0", @@ -3022,7 +3043,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df9e79541e71590846f773efce1b6d0538804992ee54ff2f407e05d63a9ddc23" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "futures 0.3.5", "futures_codec", @@ -3038,7 +3059,7 @@ version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0beba6459d06153f5f8e23da3df1d2183798b1f457c7c9468ff99760bcbcc60b" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "curve25519-dalek", "futures 0.3.5", "lazy_static", @@ -3047,7 +3068,7 @@ dependencies = [ "prost", "prost-build", "rand 0.7.3", - "sha2 0.8.1", + "sha2 0.8.2", "snow", "static_assertions", "x25519-dalek", @@ -3075,7 +3096,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a61dfd53d1264ddff1206e4827193efaa72bab27782dfcd63c0dec120a1875" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures 0.3.5", "futures_codec", "libp2p-core", @@ -3140,7 +3161,7 @@ dependencies = [ "rand 0.7.3", "ring", "rw-stream-sink", - "sha2 0.8.1", + "sha2 0.8.2", "static_assertions", "twofish", "wasm-bindgen", @@ -3261,8 +3282,8 @@ dependencies = [ "digest 0.8.1", "hmac-drbg", "rand 0.7.3", - "sha2 0.8.1", - "subtle 2.2.2", + "sha2 0.8.2", + "subtle 2.2.3", "typenum", ] @@ -3280,15 +3301,15 @@ dependencies = [ [[package]] name = "linked-hash-map" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" +checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" [[package]] name = "linked_hash_set" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c7c91c4c7bbeb4f2f7c4e5be11e6a05bd6830bc37249c47ce1ad86ad453ff9c" +checksum = "47186c6da4d81ca383c7c47c1bfc80f4b95f4720514d860a5407aaf4233f9588" dependencies = [ "linked-hash-map", ] @@ -3306,9 +3327,18 @@ dependencies = [ [[package]] name = "lite-json" -version = "0.1.0" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c73e713a23ac6e12074c9e96ef2dfb770921e0cb9244c093bd38424209e0e523" +dependencies = [ + "lite-parser", +] + +[[package]] +name = "lite-parser" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa835713bb12ba5204013497da16caf2dd2eee25ca829d0efaa054fb38c4ddd" +checksum = "0c50092e40e0ccd1bf2015a10333fde0502ff95b832b0895dc1ca0d7ac6c52f6" dependencies = [ "paste", ] @@ -3373,7 +3403,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "111b945ac72ec09eb7bc62a0fbdc3cc6e80555a7245f52a69d3921a75b53b153" dependencies = [ - "hashbrown 0.8.0", + "hashbrown 0.8.1", ] [[package]] @@ -3434,26 +3464,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" dependencies = [ "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "memoffset" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" dependencies = [ "autocfg 1.0.0", ] [[package]] name = "memory-db" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0777fbb396f666701d939e9b3876c18ada6b3581257d88631f2590bc366d8ebe" +checksum = "36f36ddb0b2cdc25d38babba472108798e3477f02be5165f038c5e393e50c57a" dependencies = [ "hash-db", - "hashbrown 0.8.0", + "hashbrown 0.8.1", "parity-util-mem", ] @@ -3477,27 +3507,18 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5" -dependencies = [ - "adler32", -] - -[[package]] -name = "miniz_oxide" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +checksum = "4d7559a8a40d0f97e1edea3220f698f78b1c5ab67532e49f68fde3910323b722" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ "cfg-if", "fuchsia-zircon", @@ -3526,21 +3547,21 @@ dependencies = [ [[package]] name = "mio-named-pipes" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" +checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" dependencies = [ "log", "mio", "miow 0.3.5", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "mio-uds" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", @@ -3566,7 +3587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" dependencies = [ "socket2", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3577,15 +3598,15 @@ checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" [[package]] name = "multihash" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae32179a9904ccc6e063de8beee7f5dd55fae85ecb851ca923d55722bc28cf5d" +checksum = "f75db05d738947aa5389863aadafbcf2e509d7ba099dc2ddcdf4fc66bf7a9e03" dependencies = [ "blake2b_simd", "blake2s_simd", "digest 0.8.1", "sha-1", - "sha2 0.8.1", + "sha2 0.8.2", "sha3", "unsigned-varint 0.3.3", ] @@ -3602,7 +3623,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9157e87afbc2ef0d84cc0345423d715f445edde00141c93721c162de35a05e5" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures 0.3.5", "log", "pin-project", @@ -3638,13 +3659,13 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" dependencies = [ "cfg-if", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3887,7 +3908,7 @@ dependencies = [ name = "node-rpc-client" version = "2.0.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "futures 0.1.29", "hyper 0.12.35", "jsonrpc-core-client", @@ -4091,9 +4112,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "5.1.1" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ "memchr", "version_check", @@ -4122,9 +4143,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ "autocfg 1.0.0", "num-traits", @@ -4144,9 +4165,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ "autocfg 1.0.0", "libm", @@ -4154,9 +4175,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -4199,9 +4220,9 @@ dependencies = [ [[package]] name = "oorandom" -version = "11.1.0" +version = "11.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcec7c9c2a95cacc7cd0ecb89d8a8454eca13906f6deb55258ffff0adeb9405" +checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c" [[package]] name = "opaque-debug" @@ -4227,7 +4248,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4915,7 +4936,7 @@ dependencies = [ name = "pallet-staking" version = "2.0.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "frame-benchmarking", "frame-support", "frame-system", @@ -5196,7 +5217,7 @@ dependencies = [ "tokio 0.1.22", "tokio-named-pipes", "tokio-uds", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5207,14 +5228,14 @@ checksum = "297ff91fa36aec49ce183484b102f6b75b46776822bd81525bfc4cc9b0dd0f5c" dependencies = [ "cfg-if", "ethereum-types", - "hashbrown 0.8.0", + "hashbrown 0.8.1", "impl-trait-for-tuples", "lru 0.5.3", "parity-util-mem-derive", "parking_lot 0.10.2", "primitive-types", "smallvec 1.4.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5245,9 +5266,9 @@ checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" [[package]] name = "parking" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4029bc3504a62d92e42f30b9095fdef73b8a0b2a06aa41ce2935143b05a1a06" +checksum = "50d4a6da31f8144a32532fe38fe8fb439a6842e0ec633f0037f0144c14e7f907" [[package]] name = "parking_lot" @@ -5277,7 +5298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ "lock_api 0.3.4", - "parking_lot_core 0.7.1", + "parking_lot_core 0.7.2", ] [[package]] @@ -5301,7 +5322,7 @@ dependencies = [ "rand 0.6.5", "rustc_version", "smallvec 0.6.13", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5316,21 +5337,21 @@ dependencies = [ "redox_syscall", "rustc_version", "smallvec 0.6.13", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "parking_lot_core" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e136c1904604defe99ce5fd71a28d473fa60a12255d511aa78a9ddf11237aeb" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", "cloudabi 0.0.3", "libc", "redox_syscall", "smallvec 1.4.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5345,14 +5366,14 @@ dependencies = [ "libc", "redox_syscall", "smallvec 1.4.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "paste" -version = "0.1.10" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4fb1930692d1b6a9cfabdde3d06ea0a7d186518e2f4d67660d8970e2fa647a" +checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" dependencies = [ "paste-impl", "proc-macro-hack", @@ -5360,14 +5381,11 @@ dependencies = [ [[package]] name = "paste-impl" -version = "0.1.10" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62486e111e571b1e93b710b61e8f493c0013be39629b714cb166bdb06aa5a8a" +checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" dependencies = [ "proc-macro-hack", - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -5407,9 +5425,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "petgraph" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c127eea4a29ec6c85d153c59dc1213f33ec74cead30fe4730aecc88cc1fd92" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" dependencies = [ "fixedbitset", "indexmap", @@ -5437,9 +5455,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" +checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" [[package]] name = "pin-utils" @@ -5449,9 +5467,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" [[package]] name = "platforms" @@ -5461,9 +5479,9 @@ checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e" [[package]] name = "plotters" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3bb8da247d27ae212529352020f3e5ee16e83c0c258061d27b08ab92675eeb" +checksum = "0d1685fbe7beba33de0330629da9d955ac75bd54f33d7b79f9a895590124f6bb" dependencies = [ "js-sys", "num-traits", @@ -5492,15 +5510,15 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" [[package]] name = "predicates" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "347a1b6f0b21e636bc9872fb60b83b8e185f6f5516298b8238699f7f9a531030" +checksum = "96bfead12e90dccead362d62bb2c90a5f6fc4584963645bc7f71a735e0b0735a" dependencies = [ "difference", "predicates-core", @@ -5536,9 +5554,9 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e4b9943a2da369aec5e96f7c10ebc74fcf434d39590d974b0a3460e6f67fbb" +checksum = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" dependencies = [ "fixed-hash", "impl-codec", @@ -5549,18 +5567,18 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ "toml", ] [[package]] name = "proc-macro-error" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -5571,34 +5589,32 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", - "syn-mid", "version_check", ] [[package]] name = "proc-macro-hack" -version = "0.5.15" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" +checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" [[package]] name = "proc-macro-nested" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" +checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "175c513d55719db99da20232b06cda8bab6b83ec2d04e3283edf0213c37c1a29" dependencies = [ "unicode-xid", ] @@ -5623,7 +5639,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "prost-derive", ] @@ -5633,7 +5649,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "heck", "itertools 0.8.2", "log", @@ -5664,7 +5680,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "prost", ] @@ -5691,7 +5707,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f" dependencies = [ - "env_logger 0.7.1", + "env_logger", "log", "rand 0.7.3", "rand_core 0.5.1", @@ -5710,9 +5726,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] @@ -5743,7 +5759,7 @@ dependencies = [ "libc", "rand_core 0.3.1", "rdrand", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5756,7 +5772,7 @@ dependencies = [ "fuchsia-cprng", "libc", "rand_core 0.3.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5775,7 +5791,7 @@ dependencies = [ "rand_os", "rand_pcg 0.1.2", "rand_xorshift", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5871,7 +5887,7 @@ checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" dependencies = [ "libc", "rand_core 0.4.2", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5886,7 +5902,7 @@ dependencies = [ "rand_core 0.4.2", "rdrand", "wasm-bindgen", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5936,10 +5952,11 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" +checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" dependencies = [ + "autocfg 1.0.0", "crossbeam-deque", "either", "rayon-core", @@ -5947,9 +5964,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" +checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" dependencies = [ "crossbeam-deque", "crossbeam-queue", @@ -5969,9 +5986,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_users" @@ -5986,18 +6003,18 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a214c7875e1b63fc1618db7c80efc0954f6156c9ff07699fd9039e255accdd1" +checksum = "745c1787167ddae5569661d5ffb8b25ae5fedbf46717eaa92d652221cec72623" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eb59cda66fcb9aec25841fb76bc01d2b34282dcdd705028da297db6f3eec8" +checksum = "7d21b475ab879ef0e315ad99067fa25778c3b0377f57f1b00207448dac1a3144" dependencies = [ "proc-macro2", "quote", @@ -6017,9 +6034,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.6" +version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ "aho-corasick", "memchr", @@ -6039,9 +6056,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "region" @@ -6052,16 +6069,16 @@ dependencies = [ "bitflags", "libc", "mach", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "remove_dir_all" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -6072,17 +6089,17 @@ checksum = "e005d658ad26eacc2b6c506dfde519f4e277e328d0eb3379ca61647d70a8f531" [[package]] name = "ring" -version = "0.16.12" +version = "0.16.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" +checksum = "952cd6b98c85bbc30efa1ba5783b8abf12fec8b3287ffa52605b9432313e34e4" dependencies = [ "cc", - "lazy_static", "libc", + "once_cell 1.4.0", "spin", "untrusted", "web-sys", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -6122,7 +6139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99371657d3c8e4d816fb6221db98fa408242b0b53bac08f8676a41f8554fe99f" dependencies = [ "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -6191,9 +6208,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" +checksum = "b9bdc5e856e51e685846fb6c13a1f5e5432946c2c90501bdc76a1319f19e29da" dependencies = [ "proc-macro2", "quote", @@ -6213,9 +6230,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "safe-mix" @@ -6259,10 +6276,10 @@ dependencies = [ name = "sc-authority-discovery" version = "0.8.0-rc6" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "derive_more", "either", - "env_logger 0.7.1", + "env_logger", "futures 0.3.5", "futures-timer 3.0.2", "libp2p", @@ -6365,7 +6382,7 @@ dependencies = [ "bip39", "chrono", "derive_more", - "env_logger 0.7.1", + "env_logger", "fdlimit", "futures 0.3.5", "hex", @@ -6402,7 +6419,7 @@ dependencies = [ "substrate-prometheus-endpoint", "tempfile", "time", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -6448,7 +6465,7 @@ name = "sc-client-db" version = "0.8.0-rc6" dependencies = [ "blake2-rfc", - "env_logger 0.7.1", + "env_logger", "hash-db", "kvdb", "kvdb-memorydb", @@ -6492,7 +6509,7 @@ name = "sc-consensus-aura" version = "0.8.0-rc6" dependencies = [ "derive_more", - "env_logger 0.7.1", + "env_logger", "futures 0.3.5", "futures-timer 3.0.2", "log", @@ -6530,7 +6547,7 @@ name = "sc-consensus-babe" version = "0.8.0-rc6" dependencies = [ "derive_more", - "env_logger 0.7.1", + "env_logger", "fork-tree", "futures 0.3.5", "futures-timer 3.0.2", @@ -6624,7 +6641,7 @@ version = "0.8.0-rc6" dependencies = [ "assert_matches", "derive_more", - "env_logger 0.7.1", + "env_logger", "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", @@ -6651,7 +6668,7 @@ dependencies = [ "substrate-test-runtime-client", "substrate-test-runtime-transaction-pool", "tempfile", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -6803,7 +6820,7 @@ version = "0.8.0-rc6" dependencies = [ "assert_matches", "derive_more", - "env_logger 0.7.1", + "env_logger", "finality-grandpa", "fork-tree", "futures 0.3.5", @@ -6839,7 +6856,7 @@ dependencies = [ "substrate-prometheus-endpoint", "substrate-test-runtime-client", "tempfile", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -6900,7 +6917,7 @@ dependencies = [ "serde_json", "sp-application-crypto", "sp-core", - "subtle 2.2.2", + "subtle 2.2.3", "tempfile", ] @@ -6931,10 +6948,10 @@ dependencies = [ "async-trait", "bitflags", "bs58", - "bytes 0.5.4", + "bytes 0.5.6", "derive_more", "either", - "env_logger 0.7.1", + "env_logger", "erased-serde", "fnv", "fork-tree", @@ -7005,7 +7022,7 @@ dependencies = [ name = "sc-network-test" version = "0.8.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "futures 0.3.5", "futures-timer 3.0.2", "libp2p", @@ -7031,12 +7048,12 @@ dependencies = [ name = "sc-offchain" version = "2.0.0-rc6" dependencies = [ - "bytes 0.5.4", - "env_logger 0.7.1", + "bytes 0.5.6", + "env_logger", "fnv", "futures 0.3.5", "futures-timer 3.0.2", - "hyper 0.13.4", + "hyper 0.13.7", "hyper-rustls", "lazy_static", "log", @@ -7057,7 +7074,7 @@ dependencies = [ "sp-utils", "substrate-test-runtime-client", "threadpool", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -7233,7 +7250,7 @@ dependencies = [ "substrate-prometheus-endpoint", "substrate-test-runtime-client", "tempfile", - "tokio 0.2.21", + "tokio 0.2.22", "tracing", "wasm-timer", ] @@ -7242,7 +7259,7 @@ dependencies = [ name = "sc-service-test" version = "2.0.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "fdlimit", "futures 0.1.29", "futures 0.3.5", @@ -7278,7 +7295,7 @@ dependencies = [ name = "sc-state-db" version = "0.8.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "log", "parity-scale-codec", "parity-util-mem", @@ -7384,12 +7401,12 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "039c25b130bd8c1321ee2d7de7fde2659fa9c2744e4bb29711cfc852ea53cd19" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -7405,8 +7422,8 @@ dependencies = [ "merlin", "rand 0.7.3", "rand_core 0.5.1", - "sha2 0.8.1", - "subtle 2.2.2", + "sha2 0.8.2", + "subtle 2.2.3", "zeroize", ] @@ -7439,9 +7456,9 @@ dependencies = [ [[package]] name = "scroll_derive" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" +checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" dependencies = [ "proc-macro2", "quote", @@ -7535,9 +7552,9 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" dependencies = [ "serde_derive", ] @@ -7554,9 +7571,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2", "quote", @@ -7565,9 +7582,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" dependencies = [ "itoa", "ryu", @@ -7588,9 +7605,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" dependencies = [ "block-buffer 0.7.3", "digest 0.8.1", @@ -7738,7 +7755,7 @@ dependencies = [ "slab", "socket2", "wepoll-sys-stjepang", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -7755,7 +7772,7 @@ dependencies = [ "ring", "rustc_version", "sha2 0.9.1", - "subtle 2.2.2", + "subtle 2.2.3", "x25519-dalek", ] @@ -7768,7 +7785,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -7778,7 +7795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85457366ae0c6ce56bf05a958aef14cd38513c236568618edbcd9a8c52cb80b0" dependencies = [ "base64 0.12.3", - "bytes 0.5.4", + "bytes 0.5.6", "flate2", "futures 0.3.5", "httparse", @@ -8069,7 +8086,7 @@ dependencies = [ "secrecy", "serde", "serde_json", - "sha2 0.8.1", + "sha2 0.8.2", "sp-debug-derive", "sp-externalities", "sp-runtime-interface", @@ -8522,9 +8539,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "stable_deref_trait" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" @@ -8576,9 +8593,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5472fb24d7e80ae84a7801b7978f95a19ec32cb1876faea59ab711eb901976" +checksum = "6cc388d94ffabf39b5ed5fadddc40147cb21e605f53db6f8f36a625d27489ac5" dependencies = [ "clap", "lazy_static", @@ -8587,9 +8604,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0eb37335aeeebe51be42e2dc07f031163fbabfa6ac67d7ea68b5c2f68d5f99" +checksum = "5e2513111825077552a6751dfad9e11ce0fba07d7276a3943a037d7e93e64c5f" dependencies = [ "heck", "proc-macro-error", @@ -8641,7 +8658,7 @@ dependencies = [ "hmac", "pbkdf2", "schnorrkel", - "sha2 0.8.1", + "sha2 0.8.2", "zeroize", ] @@ -8701,14 +8718,14 @@ dependencies = [ "sc-rpc-api", "serde", "sp-storage", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] name = "substrate-frame-rpc-system" version = "2.0.0-rc6" dependencies = [ - "env_logger 0.7.1", + "env_logger", "frame-system-rpc-runtime-api", "futures 0.3.5", "jsonrpc-core", @@ -8736,10 +8753,10 @@ dependencies = [ "async-std", "derive_more", "futures-util", - "hyper 0.13.4", + "hyper 0.13.7", "log", "prometheus", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -8852,7 +8869,7 @@ dependencies = [ "futures 0.3.5", "sc-service", "substrate-test-utils-derive", - "tokio 0.2.21", + "tokio 0.2.22", "trybuild", ] @@ -8871,7 +8888,7 @@ version = "0.1.0" dependencies = [ "sc-service", "substrate-test-utils", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -8901,37 +8918,26 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "subtle" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941" +checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.33" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" +checksum = "963f7d3cc59b59b9325165add223142bbf1df27655d07789f109896d353d8350" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "synstructure" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", @@ -8962,7 +8968,7 @@ dependencies = [ "rand 0.7.3", "redox_syscall", "remove_dir_all", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -8998,18 +9004,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.15" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b3d3d2ff68104100ab257bb6bb0cb26c901abe4bd4ba15961f3bf867924012" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.15" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca972988113b7715266f91250ddb98070d033c62a011fa0fcc57434a649310dd" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ "proc-macro2", "quote", @@ -9027,22 +9033,21 @@ dependencies = [ [[package]] name = "threadpool" -version = "1.7.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" dependencies = [ "num_cpus", ] [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "redox_syscall", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -9057,7 +9062,7 @@ dependencies = [ "pbkdf2", "rand 0.7.3", "rustc-hash", - "sha2 0.8.1", + "sha2 0.8.2", "unicode-normalization", ] @@ -9089,6 +9094,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" + [[package]] name = "tokio" version = "0.1.22" @@ -9115,11 +9126,11 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.21" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d099fa27b9702bed751524694adbe393e18b36b204da91eb1cbbbbb4a5ee2d58" +checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "futures-core", "iovec", @@ -9133,7 +9144,7 @@ dependencies = [ "signal-hook-registry", "slab", "tokio-macros", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -9262,7 +9273,7 @@ checksum = "228139ddd4fea3fa345a29233009635235833e52807af7ea6448ead03890d6a9" dependencies = [ "futures-core", "rustls", - "tokio 0.2.21", + "tokio 0.2.22", "webpki", ] @@ -9356,9 +9367,9 @@ dependencies = [ [[package]] name = "tokio-uds" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5076db410d6fdc6523df7595447629099a1fdc47b3d9f896220780fa48faf798" +checksum = "ab57a4ac4111c8c9dbcf70779f6fc8bc35ae4b2454809febac840ad19bd7e4e0" dependencies = [ "bytes 0.4.12", "futures 0.1.29", @@ -9378,12 +9389,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures-core", "futures-sink", "log", "pin-project-lite", - "tokio 0.2.21", + "tokio 0.2.22", ] [[package]] @@ -9408,15 +9419,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" dependencies = [ "cfg-if", + "log", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe233f4227389ab7df5b32649239da7ebe0b281824b4e84b342d04d3fd8c25e" +checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" dependencies = [ "proc-macro2", "quote", @@ -9503,7 +9515,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39f1a9a9252d38c5337cf0c5392988821a5cf1b2103245016968f2ab41de9e38" dependencies = [ "hash-db", - "hashbrown 0.8.0", + "hashbrown 0.8.1", "log", "rustc-hex", "smallvec 1.4.1", @@ -9530,15 +9542,15 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "trybuild" -version = "1.0.25" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "459186ab1afd6d93bd23c2269125f4f7694f8771fe0e64434b4bdc212b94034d" +checksum = "48105a4deaf74163c017939b45ef7322fba46e8b17281528039b0beb04235e92" dependencies = [ "dissimilar", "glob 0.3.0", @@ -9577,9 +9589,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "uint" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75a4cdd7b87b28840dba13c483b9a88ee6bbf16ba5c951ee1ecfcf723078e0d" +checksum = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" dependencies = [ "byteorder 1.3.4", "crunchy", @@ -9607,11 +9619,11 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" +checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" dependencies = [ - "smallvec 1.4.1", + "tinyvec", ] [[package]] @@ -9622,15 +9634,15 @@ checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" [[package]] name = "unicode-width" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "universal-hash" @@ -9639,7 +9651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ "generic-array 0.14.3", - "subtle 2.2.2", + "subtle 2.2.3", ] [[package]] @@ -9654,7 +9666,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "669d776983b692a906c881fcd0cfb34271a48e197e4d6cb8df32b05bfc3d3fa5" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures-io", "futures-util", "futures_codec", @@ -9662,9 +9674,9 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" @@ -9690,21 +9702,21 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "void" @@ -9714,9 +9726,9 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "wabt" -version = "0.9.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5c5c1286c6e578416982609f47594265f9d489f9b836157d403ad605a46693" +checksum = "94b5f5d6984ca42df66280baa8a15ac188a173ddaf4580b574a98931c01920e7" dependencies = [ "serde", "serde_derive", @@ -9726,9 +9738,9 @@ dependencies = [ [[package]] name = "wabt-sys" -version = "0.7.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d7043ebb3e5d96fad7a8d3ca22ee9880748ff8c3e18092cfb2a49d3b8f9084" +checksum = "b064c81821100adb4b71923cecfc67fef083db21c3bbd454b0162c7ffe63eeaa" dependencies = [ "cc", "cmake", @@ -9757,7 +9769,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ "same-file", - "winapi 0.3.8", + "winapi 0.3.9", "winapi-util", ] @@ -9817,9 +9829,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.10" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7add542ea1ac7fdaa9dc25e031a6af33b7d63376292bd24140c637d00d1c312a" +checksum = "dba48d66049d2a6cc8488702e7259ab7afc9043ad0dc5448444f46f2a453b362" dependencies = [ "cfg-if", "js-sys", @@ -9858,9 +9870,9 @@ checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" [[package]] name = "wasm-bindgen-test" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648da3460c6d2aa04b715a936329e2e311180efe650b2127d6267f4193ccac14" +checksum = "fd8e9dad8040e378f0696b017570c6bc929aac373180e06b3d67ac5059c52da3" dependencies = [ "console_error_panic_hook", "js-sys", @@ -9872,9 +9884,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2f86cd78a2aa7b1fb4bb6ed854eccb7f9263089c79542dca1576a1518a8467" +checksum = "c358c8d2507c1bae25efa069e62ea907aa28700b25c8c33dafb0b15ba4603627" dependencies = [ "proc-macro2", "quote", @@ -9965,7 +9977,7 @@ dependencies = [ "wasmtime-profiling", "wasmtime-runtime", "wat", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -10007,11 +10019,11 @@ dependencies = [ "more-asserts", "rayon", "serde", - "sha2 0.8.1", + "sha2 0.8.2", "thiserror", "toml", "wasmparser 0.59.0", - "winapi 0.3.8", + "winapi 0.3.9", "zstd", ] @@ -10041,7 +10053,7 @@ dependencies = [ "wasmtime-obj", "wasmtime-profiling", "wasmtime-runtime", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -10095,7 +10107,7 @@ dependencies = [ "region", "thiserror", "wasmtime-environ", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -10118,9 +10130,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.37" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d6f51648d8c56c366144378a33290049eafdd784071077f6fe37dae64c1c4cb" +checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d" dependencies = [ "js-sys", "wasm-bindgen", @@ -10128,9 +10140,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" +checksum = "ab146130f5f790d45f82aeeb09e55a256573373ec64409fc19a6fb82fb1032ae" dependencies = [ "ring", "untrusted", @@ -10180,9 +10192,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -10202,11 +10214,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -10291,18 +10303,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.5.1+zstd.1.4.4" +version = "0.5.3+zstd.1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5d978b793ae64375b80baf652919b148f6a496ac8802922d9999f5a553194f" +checksum = "01b32eaf771efa709e8308605bbf9319bf485dc1503179ec0469b611937c0cd8" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "2.0.3+zstd.1.4.4" +version = "2.0.5+zstd.1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee25eac9753cfedd48133fa1736cbd23b774e253d89badbeac7d12b23848d3f" +checksum = "1cfb642e0d27f64729a639c52db457e0ae906e7bc6f5fe8f5c453230400f1055" dependencies = [ "libc", "zstd-sys", @@ -10310,11 +10322,12 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "1.4.15+zstd.1.4.4" +version = "1.4.17+zstd.1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89719b034dc22d240d5b407fb0a3fe6d29952c181cff9a9f95c0bd40b4f8f7d8" +checksum = "b89249644df056b522696b1bb9e7c18c87e8ffa3e2f0dc3b0155875d6498f01b" dependencies = [ "cc", "glob 0.3.0", + "itertools 0.9.0", "libc", ] diff --git a/bin/node/executor/Cargo.toml b/bin/node/executor/Cargo.toml index d8fb2e4078bd1..84a2cf377e6f0 100644 --- a/bin/node/executor/Cargo.toml +++ b/bin/node/executor/Cargo.toml @@ -41,7 +41,7 @@ sp-application-crypto = { version = "2.0.0-rc6", path = "../../../primitives/app sp-runtime = { version = "2.0.0-rc6", path = "../../../primitives/runtime" } sp-externalities = { version = "0.8.0-rc6", path = "../../../primitives/externalities" } substrate-test-client = { version = "2.0.0-rc6", path = "../../../test-utils/client" } -wabt = "0.9.2" +wabt = "0.9.1" [features] wasmtime = [ diff --git a/bin/node/testing/Cargo.toml b/bin/node/testing/Cargo.toml index 23bf10336dcfe..1d4d6ccaa63f8 100644 --- a/bin/node/testing/Cargo.toml +++ b/bin/node/testing/Cargo.toml @@ -39,7 +39,7 @@ substrate-test-client = { version = "2.0.0-rc6", path = "../../../test-utils/cli pallet-timestamp = { version = "2.0.0-rc6", path = "../../../frame/timestamp" } pallet-transaction-payment = { version = "2.0.0-rc6", path = "../../../frame/transaction-payment" } pallet-treasury = { version = "2.0.0-rc6", path = "../../../frame/treasury" } -wabt = "0.9.2" +wabt = "0.9.1" sp-api = { version = "2.0.0-rc6", path = "../../../primitives/api" } sp-finality-tracker = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/finality-tracker" } sp-timestamp = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/timestamp" } diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index f963068ea37b2..029e01923ac70 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -37,7 +37,7 @@ libsecp256k1 = "0.3.4" [dev-dependencies] assert_matches = "1.3.0" -wabt = "0.9.2" +wabt = "0.9.1" hex-literal = "0.3.1" sc-runtime-test = { version = "2.0.0-rc6", path = "runtime-test" } substrate-test-runtime = { version = "2.0.0-rc6", path = "../../test-utils/runtime" } diff --git a/frame/support/test/Cargo.toml b/frame/support/test/Cargo.toml index f2f70fb95279e..7c839e4462ad1 100644 --- a/frame/support/test/Cargo.toml +++ b/frame/support/test/Cargo.toml @@ -21,7 +21,7 @@ sp-inherents = { version = "2.0.0-rc6", default-features = false, path = "../../ sp-runtime = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/runtime" } sp-core = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/core" } sp-std = { version = "2.0.0-rc6", default-features = false, path = "../../../primitives/std" } -trybuild = "1.0.17" +trybuild = "1.0.33" pretty_assertions = "0.6.1" rustversion = "1.0.0" diff --git a/primitives/sandbox/Cargo.toml b/primitives/sandbox/Cargo.toml index 98376c77464d5..0ee2feea2b94e 100755 --- a/primitives/sandbox/Cargo.toml +++ b/primitives/sandbox/Cargo.toml @@ -20,7 +20,7 @@ sp-wasm-interface = { version = "2.0.0-rc6", default-features = false, path = ". codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false } [dev-dependencies] -wabt = "0.9.2" +wabt = "0.9.1" assert_matches = "1.3.0" [features] From 7ae82649cc81d0d3300530d1bbd3f3e51ea14a25 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 7 Sep 2020 20:32:42 +0200 Subject: [PATCH 096/113] update error message for UI --- .../api/test/tests/ui/mock_only_self_reference.stderr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/primitives/api/test/tests/ui/mock_only_self_reference.stderr b/primitives/api/test/tests/ui/mock_only_self_reference.stderr index 6d1ac0e9a2563..ed5b64144a6f6 100644 --- a/primitives/api/test/tests/ui/mock_only_self_reference.stderr +++ b/primitives/api/test/tests/ui/mock_only_self_reference.stderr @@ -24,8 +24,8 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr 12 | sp_api::mock_impl_runtime_apis! { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | - = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` - found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` + found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for trait @@ -42,6 +42,6 @@ error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for t 12 | sp_api::mock_impl_runtime_apis! { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | - = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` - found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` + found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) From c69a51ede13be7938b9066f4d06acbda76f82701 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 8 Sep 2020 18:01:10 +0200 Subject: [PATCH 097/113] Fix interface test --- Cargo.lock | 5 +++-- primitives/runtime-interface/test/Cargo.toml | 1 + primitives/runtime-interface/test/src/lib.rs | 21 ++++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1869842dec911..b9a8edf38648f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8325,6 +8325,7 @@ dependencies = [ "sp-runtime-interface-test-wasm-deprecated", "sp-state-machine", "tracing", + "tracing-core", ] [[package]] @@ -9437,9 +9438,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545" +checksum = "4f0e00789804e99b20f12bc7003ca416309d28a6f495d6af58d1e2c2842461b5" dependencies = [ "lazy_static", ] diff --git a/primitives/runtime-interface/test/Cargo.toml b/primitives/runtime-interface/test/Cargo.toml index 39a48d10b141e..121035c27415e 100644 --- a/primitives/runtime-interface/test/Cargo.toml +++ b/primitives/runtime-interface/test/Cargo.toml @@ -21,3 +21,4 @@ sp-runtime = { version = "2.0.0-rc6", path = "../../runtime" } sp-core = { version = "2.0.0-rc6", path = "../../core" } sp-io = { version = "2.0.0-rc6", path = "../../io" } tracing = "0.1.18" +tracing-core = "0.1.15" diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index a56ad6339301f..c66609daa2f29 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -155,14 +155,26 @@ fn test_versionining_with_new_host_works() { #[test] fn test_tracing() { - use tracing::span::Id as SpanId; + use std::fmt; + use tracing::{span::Id as SpanId}; + use tracing_core::field::{Field, Visit}; #[derive(Clone)] struct TracingSubscriber(Arc>); + struct FieldConsumer(&'static str, Option); + impl Visit for FieldConsumer { + + fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { + if field.name() == self.0 { + self.1 = Some(format!("{:?}", value)) + } + } + } + #[derive(Default)] struct Inner { - spans: HashSet<&'static str>, + spans: HashSet, } impl tracing::subscriber::Subscriber for TracingSubscriber { @@ -171,7 +183,9 @@ fn test_tracing() { fn new_span(&self, span: &tracing::span::Attributes) -> tracing::Id { let mut inner = self.0.lock().unwrap(); let id = SpanId::from_u64((inner.spans.len() + 1) as _); - inner.spans.insert(span.metadata().name()); + let mut f = FieldConsumer("name", None); + span.record(&mut f); + inner.spans.insert(f.1.unwrap_or_else(||span.metadata().name().to_owned())); id } @@ -194,5 +208,4 @@ fn test_tracing() { let inner = subscriber.0.lock().unwrap(); assert!(inner.spans.contains("return_input_version_1")); - assert!(inner.spans.contains("ext_test_api_return_input_version_1")); } \ No newline at end of file From 71cca7a12e2867ed85b14592ff02de488cf4af7c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 9 Sep 2020 08:21:46 +0200 Subject: [PATCH 098/113] next attempt to fix macros --- .../api/test/tests/ui/mock_only_self_reference.stderr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/primitives/api/test/tests/ui/mock_only_self_reference.stderr b/primitives/api/test/tests/ui/mock_only_self_reference.stderr index ed5b64144a6f6..2b01215ae5e2a 100644 --- a/primitives/api/test/tests/ui/mock_only_self_reference.stderr +++ b/primitives/api/test/tests/ui/mock_only_self_reference.stderr @@ -24,8 +24,8 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr 12 | sp_api::mock_impl_runtime_apis! { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | - = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` - found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` + found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for trait @@ -42,6 +42,6 @@ error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for t 12 | sp_api::mock_impl_runtime_apis! { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | - = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` - found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime_client::substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` + found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) \ No newline at end of file From 97156dbbc8e9ad4ec11baff44c617d78ba5084b3 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 9 Sep 2020 10:37:31 +0200 Subject: [PATCH 099/113] geee --- primitives/api/test/tests/ui/mock_only_self_reference.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/api/test/tests/ui/mock_only_self_reference.stderr b/primitives/api/test/tests/ui/mock_only_self_reference.stderr index 2b01215ae5e2a..6d1ac0e9a2563 100644 --- a/primitives/api/test/tests/ui/mock_only_self_reference.stderr +++ b/primitives/api/test/tests/ui/mock_only_self_reference.stderr @@ -44,4 +44,4 @@ error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for t | = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) \ No newline at end of file + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) From c7521edf042d730270d008639b58109486516853 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 9 Sep 2020 11:19:14 +0200 Subject: [PATCH 100/113] revert tracing on hashed for future PR --- frame/support/src/storage/hashed.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/frame/support/src/storage/hashed.rs b/frame/support/src/storage/hashed.rs index c2ca520a1b3c8..96a487111a2af 100644 --- a/frame/support/src/storage/hashed.rs +++ b/frame/support/src/storage/hashed.rs @@ -28,8 +28,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="get", key=?key); unhashed::get(&hash(key).as_ref()) } @@ -41,8 +39,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="get_or_default", key=?key); unhashed::get_or_default(&hash(key).as_ref()) } @@ -54,8 +50,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="get_or", key=?key); unhashed::get_or(&hash(key).as_ref(), default_value) } @@ -68,8 +62,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="get_or_else", key=?key); unhashed::get_or_else(&hash(key).as_ref(), default_value) } @@ -80,8 +72,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::INFO, fun="put", key=?key, value=?value.encode()); unhashed::put(&hash(key).as_ref(), value) } @@ -92,8 +82,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="take", key=?key); unhashed::take(&hash(key).as_ref()) } @@ -105,8 +93,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="take_or_default", key=?key); unhashed::take_or_default(&hash(key).as_ref()) } @@ -118,8 +104,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="take_or", key=?key); unhashed::take_or(&hash(key).as_ref(), default_value) } @@ -132,8 +116,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="take_or_else", key=?key); unhashed::take_or_else(&hash(key).as_ref(), default_value) } @@ -143,8 +125,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="exists", key=?key); unhashed::exists(&hash(key).as_ref()) } @@ -154,8 +134,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::INFO, fun="kill", key=?key); unhashed::kill(&hash(key).as_ref()) } @@ -165,8 +143,6 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::TRACE, fun="get_raw", key=?key); unhashed::get_raw(&hash(key).as_ref()) } @@ -176,7 +152,5 @@ where HashFn: Fn(&[u8]) -> R, R: AsRef<[u8]>, { - sp_tracing::event!(target: "frame_storage", - sp_tracing::Level::INFO, fun="put_raw", key=?key, value=?value.encode()); unhashed::put_raw(&hash(key).as_ref(), value) } From 7a31707aead9be620363ffcdbfd5d3418d5d6c4f Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 9 Sep 2020 17:46:34 +0200 Subject: [PATCH 101/113] remove local macros, use originals --- Cargo.lock | 4 +- primitives/io/Cargo.toml | 8 +- primitives/io/src/lib.rs | 47 +- primitives/tracing/Cargo.toml | 6 +- primitives/tracing/src/lib.rs | 97 +- primitives/tracing/src/types.rs | 99 +- primitives/tracing/src/wasm_tracing.rs | 2154 ------------------------ 7 files changed, 137 insertions(+), 2278 deletions(-) delete mode 100644 primitives/tracing/src/wasm_tracing.rs diff --git a/Cargo.lock b/Cargo.lock index b9a8edf38648f..fdbc79fc66a2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9438,9 +9438,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f0e00789804e99b20f12bc7003ca416309d28a6f495d6af58d1e2c2842461b5" +checksum = "5bcf46c1f1f06aeea2d6b81f3c863d0930a596c86ad1920d4e5bad6dd1d7119a" dependencies = [ "lazy_static", ] diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 1d44dbe6a4f49..69a0add85e10a 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -28,8 +28,8 @@ sp-tracing = { version = "2.0.0-rc6", default-features = false, path = "../traci log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } -tracing = { version = "0.1.18", optional = true } -tracing-core = { version = "0.1.13", optional = true } +tracing = { version = "0.1.18", default-features = false } +tracing-core = { version = "0.1.15", default-features = false} [features] default = ["std"] @@ -45,8 +45,8 @@ std = [ "sp-externalities", "sp-wasm-interface/std", "sp-tracing/std", - "tracing", - "tracing-core", + "tracing/std", + "tracing-core/std", "log", "futures", "parking_lot", diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index b50008374bc3b..d6bdd9af41a57 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1089,36 +1089,42 @@ pub trait WasmTracing { #[cfg(all(not(feature="std"), feature="with-tracing"))] mod tracing_setup { use core::sync::atomic::{AtomicBool, Ordering}; - use sp_std::boxed::Box; + use tracing_core::{ + dispatcher::{Dispatch, set_global_default}, + span::{Id, Record, Attributes}, + Metadata, Event, + }; use super::{wasm_tracing, Crossing}; const TRACING_SET : AtomicBool = AtomicBool::new(false); - /// The PassingTracingSubscriber implements `sp_tracing::TracingSubscriber` + /// The PassingTracingSubscriber implements `tracing_core::Subscriber` /// and pushes the information accross the runtime interface to the host struct PassingTracingSubsciber; - impl sp_tracing::TracingSubscriber for PassingTracingSubsciber { - fn enabled(&self, metadata: &sp_tracing::WasmMetadata) -> bool { - wasm_tracing::enabled(Crossing(metadata.clone())) + impl tracing_core::Subscriber for PassingTracingSubsciber { + fn enabled(&self, metadata: &Metadata<'_>) -> bool { + wasm_tracing::enabled(Crossing(metadata.into())) + } + fn new_span(&self, attrs: &Attributes<'_>) -> Id { + Id::from_u64(wasm_tracing::enter_span(Crossing(attrs.into()))) + } + fn enter(&self, span: &Id) { + // We are already entered in the API here + todo! {} + } + fn record(&self, span: &Id, values: &Record<'_>) { + todo!{} } - fn enter_span(&self, attrs: sp_tracing::WasmEntryAttributes) -> u64 { - wasm_tracing::enter_span(Crossing(attrs)) + fn record_follows_from(&self, span: &Id, follows: &Id) { + todo!{ } } - fn event(&self, - parent_id: Option, - metadata: &sp_tracing::WasmMetadata, - values: &sp_tracing::WasmValuesSet - ) { - wasm_tracing::event(Crossing(sp_tracing::WasmEntryAttributes { - parent_id, - metadata: metadata.clone(), - fields: values.clone() - })) + fn event(&self, event: &Event<'_>) { + wasm_tracing::event(Crossing(event.into())) } - fn exit(&self, span: u64) { - wasm_tracing::exit(span) + fn exit(&self, span: &Id) { + wasm_tracing::exit(span.into_u64()) } } @@ -1128,7 +1134,8 @@ mod tracing_setup { /// set the global bridgin subscriber once. pub fn init_tracing() { if TRACING_SET.load(Ordering::Relaxed) == false { - sp_tracing::set_tracing_subscriber(Box::new(PassingTracingSubsciber {} )); + set_global_default(Dispatch::new(PassingTracingSubsciber {})) + .expect("We only ever call this once"); TRACING_SET.store(true, Ordering::Relaxed); } } diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 46b7891934e2d..5574a3f4db961 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -19,8 +19,8 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] sp-std = { version = "2.0.0-rc6", path = "../std", default-features = false} codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false, features = ["derive"]} -tracing = { version = "0.1.18", default-features = false } -tracing-core = { version = "0.1.13", optional = true } +tracing = { version = "0.1.19", default-features = false } +tracing-core = { version = "0.1.16", default-features = false } log = { version = "0.4.8", optional = true } [features] @@ -32,7 +32,7 @@ with-tracing = [ std = [ "with-tracing", "tracing/std", - "tracing-core", + "tracing-core/std", "codec/std", "sp-std/std", "log", diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index 43f4f06eb4674..f1aed0f0f27dc 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -96,20 +96,19 @@ mod types; -#[cfg(not(feature = "std"))] -#[macro_export] -mod wasm_tracing; +// #[cfg(not(feature = "std"))] +// #[macro_export] +// mod wasm_tracing; -#[cfg(not(feature = "std"))] -pub use wasm_tracing::Span; +// #[cfg(not(feature = "std"))] +// pub use wasm_tracing::Span; #[cfg(feature = "std")] use tracing; -#[cfg(feature = "std")] pub use tracing::{ debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span, - span, event, Level, + span, event, Level, Span, }; pub use crate::types::{ @@ -121,90 +120,6 @@ pub use crate::types::{ WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER }; -#[cfg(not(feature = "std"))] -pub type Level = WasmLevel; - -/// Defines the interface for the wasm-side tracing subcriber. This is -/// very much modeled after the `tracing_core::Subscriber`, but adapted -/// to be feasible to cross the wasm-native boundary. -/// -/// This is generally expected to be a proxy that moves the data over to -/// the native side as tracking within `wasm` is probably ineffecient. However -/// any implementation may do internal optimisations for performance. -/// -#[cfg(not(feature = "std"))] -pub trait TracingSubscriber: Send + Sync { - /// Give the `WasmMetadata`, should we even continue recording this span/event - /// or stop execution before. - /// This may or may not be implemented wasm- and/or native side or have optimisations - /// added. - fn enabled(&self, metadata: &WasmMetadata) -> bool; - /// Enter a new `Span` with the given `WasmEntryAttributes`, return the u64 tracking ID for - /// it or 0 if not. Will only be called if `attrs.metadata` was found to be enabled. - fn enter_span(&self, attrs: WasmEntryAttributes) -> u64; - /// Record the `WasmValueSet` for `WasMetadata` as a new event. Willl only be called if - /// `WasmMetadata` was found to be enabled; - fn event(&self, parent_id: Option, metadata: &WasmMetadata, values: &WasmValuesSet); - /// Exit the given span. You can discard the span info now. - fn exit(&self, span: u64); -} - - -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -mod global_subscription { - // Having a global subscription for WASM - use crate::TracingSubscriber; - use sp_std::{ - boxed::Box, - cell::UnsafeCell, - }; - - struct SubscriptionHolder { - inner: UnsafeCell>> - } - - static SUBSCRIBER_INSTANCE: SubscriptionHolder = SubscriptionHolder { - inner: UnsafeCell::new(None) - }; - - unsafe impl core::marker::Sync for SubscriptionHolder {} - - /// Set the given `TracingSubscriber` as target for the tracing spans. - /// This should happen first, any span and event calls run before are not recorded. - /// - /// **IMPORTANT**: - /// This uses unsafe features to provide a lazily-set instance-wide global. This is not - /// thread-safe and will panic if called from withina `with_tracing_subscriber`-call. - /// - /// See module index documentation for how to set the system up properly. - pub fn set_tracing_subscriber(subscriber: Box) - { - unsafe { - // Safety: Safe due to `inner`'s invariant - *SUBSCRIBER_INSTANCE.inner.get() = Some(subscriber) - } - } - - /// Gain access to the globally set `TracingSubscriber`. - /// Used to record events and spans. - /// *IMPORTANT*: do not call `set_tracing_subscriber` from within. That will lead - /// to undefined behaviour. - #[cfg(all(not(feature = "std"), feature = "with-tracing"))] - pub fn with_tracing_subscriber(f: F) -> Option - where F: FnOnce(&Box) -> R - { - unsafe { - // Safety: Safe due to `inner`'s invariant - match SUBSCRIBER_INSTANCE.inner.get().as_ref() { - Some(o) => o.as_ref().map(f), - _ => None - } - } - } -} - -#[cfg(all(not(feature = "std"), feature = "with-tracing"))] -pub use global_subscription::{set_tracing_subscriber, with_tracing_subscriber}; /// Runs given code within a tracing span, measuring it's execution time. /// diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index f84907f349e3b..8f6d603df85a2 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -18,7 +18,7 @@ /// Types for wasm based tracing. Loosly inspired by `tracing-core` but /// optimised for the specific use case. -use core::fmt::Debug; +use core::{format_args, fmt::Debug}; use sp_std::{ vec, vec::Vec, }; @@ -40,6 +40,21 @@ pub enum WasmLevel { TRACE } + +impl From<&tracing_core::Level> for WasmLevel { + fn from(l: &tracing_core::Level) -> WasmLevel { + match l { + &tracing_core::Level::ERROR => WasmLevel::ERROR, + &tracing_core::Level::WARN => WasmLevel::WARN, + &tracing_core::Level::INFO => WasmLevel::INFO, + &tracing_core::Level::DEBUG => WasmLevel::DEBUG, + &tracing_core::Level::TRACE => WasmLevel::TRACE, + } + } +} + + + impl core::default::Default for WasmLevel { fn default() -> Self { WasmLevel::TRACE @@ -136,10 +151,10 @@ impl From for WasmValue { } } -impl From<&core::fmt::Arguments<'_>> for WasmValue { - fn from(inp: &core::fmt::Arguments<'_>) -> WasmValue { +impl From> for WasmValue { + fn from(inp: core::fmt::Arguments<'_>) -> WasmValue { let mut buf = Writer::default(); - core::fmt::write(&mut buf, *inp).expect("Writing of arguments doesn't fail"); + core::fmt::write(&mut buf, inp).expect("Writing of arguments doesn't fail"); WasmValue::Formatted(buf.into_inner()) } } @@ -248,6 +263,11 @@ impl WasmFields { } } +impl From<&tracing_core::field::FieldSet> for WasmFields { + fn from(wm: &tracing_core::field::FieldSet) -> WasmFields { + WasmFields(wm.iter().map(|s| s.name().into()).collect()) + } +} /// A list of `WasmFieldName`s with the given `WasmValue` (if provided) /// in the order specified. @@ -304,6 +324,38 @@ impl WasmValuesSet { } } +impl tracing_core::field::Visit for WasmValuesSet { + fn record_debug(&mut self, field: &tracing_core::field::Field, value: &dyn Debug) { + self.0.push( ( + field.name().into(), + Some(WasmValue::from(format_args!("{:?}", value))) + )) + } + fn record_i64(&mut self, field: &tracing_core::field::Field, value: i64) { + self.0.push( ( + field.name().into(), + Some(WasmValue::from(value)) + )) + } + fn record_u64(&mut self, field: &tracing_core::field::Field, value: u64) { + self.0.push( ( + field.name().into(), + Some(WasmValue::from(value)) + )) + } + fn record_bool(&mut self, field: &tracing_core::field::Field, value: bool) { + self.0.push( ( + field.name().into(), + Some(WasmValue::from(value)) + )) + } + fn record_str(&mut self, field: &tracing_core::field::Field, value: &str) { + self.0.push( ( + field.name().into(), + Some(WasmValue::from(value)) + )) + } +} /// Metadata provides generic information about the specifc location of the /// `span!` or `event!` call on the wasm-side. #[derive(Encode, Decode, Clone)] @@ -326,6 +378,21 @@ pub struct WasmMetadata { pub fields: WasmFields, } +impl From<&tracing_core::Metadata<'_>> for WasmMetadata { + fn from(wm: &tracing_core::Metadata<'_>) -> WasmMetadata { + WasmMetadata { + name: wm.name().as_bytes().to_vec(), + target: wm.target().as_bytes().to_vec(), + level: wm.level().into(), + file: wm.file().map(|f| f.as_bytes().to_vec()).unwrap_or_default(), + line: wm.line().unwrap_or_default(), + module_path: wm.module_path().map(|m| m.as_bytes().to_vec()).unwrap_or_default(), + is_span: wm.is_span(), + fields: wm.fields().into() + } + } +} + impl core::fmt::Debug for WasmMetadata { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("WasmMetadata") @@ -373,6 +440,30 @@ pub struct WasmEntryAttributes { pub fields: WasmValuesSet, } +impl From<&tracing_core::Event<'_>> for WasmEntryAttributes { + fn from(evt: &tracing_core::Event<'_>) -> WasmEntryAttributes { + let mut fields = WasmValuesSet(Vec::new()); + evt.record(&mut fields); + WasmEntryAttributes { + parent_id: evt.parent().map(|id| id.into_u64()), + metadata: evt.metadata().into(), + fields: fields + } + } +} + +impl From<&tracing_core::span::Attributes<'_>> for WasmEntryAttributes { + fn from(attrs: &tracing_core::span::Attributes<'_>) -> WasmEntryAttributes { + let mut fields = WasmValuesSet(Vec::new()); + attrs.record(&mut fields); + WasmEntryAttributes { + parent_id: attrs.parent().map(|id| id.into_u64()), + metadata: attrs.metadata().into(), + fields: fields + } + } +} + impl core::default::Default for WasmEntryAttributes { fn default() -> Self { WasmEntryAttributes { diff --git a/primitives/tracing/src/wasm_tracing.rs b/primitives/tracing/src/wasm_tracing.rs deleted file mode 100644 index 13dcd5769dc93..0000000000000 --- a/primitives/tracing/src/wasm_tracing.rs +++ /dev/null @@ -1,2154 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -#[cfg(not(feature = "with-tracing"))] -mod inner { - // we are no-op - pub type Span = (); - - #[doc(hidden)] - #[macro_export] - macro_rules! __tracing_mk_span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { {} }; - } - - /// Constructs a new `Event` – noop - #[macro_export] - macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> { {} }; - - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => { {} }; - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> {{}}; - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => { {} }; - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => { {} }; - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => { {} }; - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => { {} }; - ($lvl:expr, $($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => { {} }; - ($lvl:expr, ?$($k:ident).+) => { {} }; - ($lvl:expr, %$($k:ident).+) => { {} }; - ($lvl:expr, $($k:ident).+) => { {} }; - ( $lvl:expr, $($arg:tt)+ ) => { {} }; - } -} - -#[cfg(feature = "with-tracing")] -mod inner { - use core::{ - module_path, concat, format_args, file, line, - }; - - // just a simplistic holder for the entered span - // that exits on drop - pub struct Span(u64); // 0 means no item - - impl Span { - /// Hold the `id` of the entered span - pub fn new(v: u64) -> Self { - Span(v) - } - /// Create a not-activated Span - pub fn none() -> Self { - Span::new(0) - } - /// This is a noop, just pointing a reference to itself only - /// existing to be compliant with the general usage. - /// In this implementation, spans are already entered - pub fn enter(&self) -> &Self { - // return a reference to self prevents using enter and - // `in_scope` on the same span. - &self - } - - /// Execute `f` and consume the span, which leads to it - /// immediately exiting before return - pub fn in_scope T, T>(self, f: F) -> T { - f() - } - } - - impl Drop for Span { - fn drop(&mut self) { - if self.0 != 0 { - crate::with_tracing_subscriber(|t| t.exit(self.0)); - } - } - } - - /// Constructs a new `Event`. - /// - /// The event macro is invoked with a `Level` and up to 32 key-value fields. - /// Optionally, a format string and arguments may follow the fields; this will - /// be used to construct an implicit field named "message". - /// - /// See [the top-level documentation][lib] for details on the syntax accepted by - /// this macro. - /// - /// [lib]: index.html#using-the-macros - /// - /// # Examples - /// - /// ```rust - /// use sp_tracing::{event, Level}; - /// - /// # fn main() { - /// let data = (42, "forty-two"); - /// let private_data = "private"; - /// let error = "a bad error"; - /// - /// event!(Level::ERROR, %error, "Received error"); - /// event!( - /// target: "app_events", - /// Level::WARN, - /// private_data, - /// ?data, - /// "App warning: {}", - /// error - /// ); - /// event!(Level::INFO, the_answer = data.0); - /// # } - /// ``` - /// - // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As - // /// events are recorded immediately when the macro is invoked, there is no - // /// opportunity for fields to be recorded later. A trailing comma on the final - // /// field is valid. - // /// - // /// For example, the following does not compile: - // /// ```rust,compile_fail - // /// # #[macro_use] - // /// # extern crate sp_tracing; - // /// # use sp_tracing::Level; - // /// # fn main() { - // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") - // /// #} - // /// ``` - #[macro_export] - macro_rules! event { - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ( - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ), - }; - if $crate::is_enabled!(&metadata) { - $crate::with_tracing_subscriber(|t| t.event( - Some($parent.0), - &metadata, - &$crate::valueset!(&metadata.fields, $($fields)*), - )); - } - } - ); - - (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: $target, - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( - $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) - ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ( - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: concat!( - "event ", - file!(), - ":", - line!() - ).as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: false, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ) - }; - if $crate::is_enabled!(&metadata) { - $crate::with_tracing_subscriber(|t| t.event( - None, - &metadata, - &$crate::valueset!(&metadata.fields, $($fields)*), - )); - } - } - ); - (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: $target, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( - $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) - ); - (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $lvl, { $($arg)+ }) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - parent: $parent, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $lvl, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $lvl, - { message = format_args!($($arg)+), $($fields)* } - ) - ); - ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { $($k).+ = $($field)*} - ) - ); - ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { $($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { ?$($k).+, $($field)*} - ) - ); - ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $lvl, - { %$($k).+, $($field)*} - ) - ); - ($lvl:expr, ?$($k:ident).+) => ( - $crate::event!($lvl, ?$($k).+,) - ); - ($lvl:expr, %$($k:ident).+) => ( - $crate::event!($lvl, %$($k).+,) - ); - ($lvl:expr, $($k:ident).+) => ( - $crate::event!($lvl, $($k).+,) - ); - ( $lvl:expr, $($arg:tt)+ ) => ( - $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) - ); - } - - #[doc(hidden)] - #[macro_export] - macro_rules! __tracing_mk_span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: $name.as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: true, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ) - }; - if $crate::is_enabled!(&metadata) { - let span_id = $crate::with_tracing_subscriber(|t| t.enter_span( - WasmEntryAttributes { - parent_id: Some($parent.0), - fields: $crate::valueset!(&metadata.fields, $($fields)*), - metadata: metadata.clone(), - }) - ).unwrap_or_default(); - $crate::Span::new(span_id) - } else { - $crate::Span::none() - } - } else { - $crate::Span::none() - } - } - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - { - if $crate::level_enabled!($lvl) { - #[allow(unused_imports)] - use $crate::{ - WasmMetadata, WasmEntryAttributes, WasmFields, WasmFieldName, WasmValuesSet - }; - let metadata = WasmMetadata { - name: $name.as_bytes().to_vec(), - file: file!().as_bytes().to_vec(), - line: line!(), - is_span: true, - target: $target.into(), - level: $lvl, - module_path: module_path!().as_bytes().to_vec(), - fields: $crate::fieldset!( $($fields)* ) - }; - if $crate::is_enabled!(&metadata) { - let span_id = $crate::with_tracing_subscriber(|t| t.enter_span( - WasmEntryAttributes { - parent_id: None, - metadata: metadata.clone(), - fields: $crate::valueset!(&metadata.fields, $($fields)*) - }) - ).unwrap_or_default(); - $crate::Span::new(span_id) - } else { - $crate::Span::none() - } - } else { - $crate::Span::none() - } - } - }; - } -} - -pub use inner::*; - -/// Constructs a new span. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// Creating a new span: -/// ``` -/// # use sp_tracing::{within_span, span, Level}; -/// # fn main() { -/// within_span!(span!(Level::TRACE, "my span"); { -/// // do work inside the span... -/// }); -/// # } -/// ``` -#[macro_export] -macro_rules! span { - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, parent: $parent, $lvl, $name,) - }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::__tracing_mk_span!(target: $target, parent: $parent, $lvl, $name, $($fields)*) - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::__tracing_mk_span!(target: $target, $lvl, $name, $($fields)*) - }; - (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, parent: $parent, $lvl, $name,) - }; - (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $lvl, - $name, - $($fields)* - ) - }; - (parent: $parent:expr, $lvl:expr, $name:expr) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $lvl, - $name, - ) - }; - (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: $target, - $lvl, - $name, - $($fields)* - ) - }; - (target: $target:expr, $lvl:expr, $name:expr) => { - $crate::span!(target: $target, $lvl, $name,) - }; - ($lvl:expr, $name:expr, $($fields:tt)*) => { - $crate::span!( - target: module_path!(), - $lvl, - $name, - $($fields)* - ) - }; - ($lvl:expr, $name:expr) => { - $crate::span!( - target: module_path!(), - $lvl, - $name, - ) - }; -} - -/// Constructs a span at the trace level to be used with [`enter_span!`] and [`within_span!`] -/// -/// [Fields] and [attributes] are set using the same syntax as the [`span!`] -/// macro. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// [attributes]: index.html#configuring-attributes -/// [Fields]: index.html#recording-fields -/// [`span!`]: macro.span.html -/// [`enter_span!`]: macro.enter_span.html -/// [`within_span!`]: macro.within_span.html -/// -/// # Examples -/// -/// ``` -/// # use sp_tracing::{enter_span, trace_span, span, Level}; -/// # fn main() { -/// enter_span!(trace_span!("my_span")); -/// // is equivalent to: -/// enter_span!(span!(Level::TRACE, "my_span")); -/// # } -/// ``` -/// -/// ``` -/// # use sp_tracing::{within_span, trace_span, span, Level}; -/// # fn main() { -/// within_span!(trace_span!("my span"); { -/// // whatever should happen -/// }); -/// # } -/// ``` -#[macro_export] -macro_rules! trace_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::trace_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::trace_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::trace_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::TRACE, - $name, - $($field)* - ) - }; - ($name:expr) => { $crate::trace_span!($name,) }; -} - -/// Constructs a span at the debug level to be used with [`enter_span!`] and [`within_span!`] -/// -/// [Fields] and [attributes] are set using the same syntax as the [`span!`] -/// macro. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// [attributes]: index.html#configuring-attributes -/// [Fields]: index.html#recording-fields -/// [`span!`]: macro.span.html -/// [`enter_span!`]: macro.enter_span.html -/// [`within_span!`]: macro.within_span.html -/// -/// # Examples -/// -/// ```rust -/// # use sp_tracing::{enter_span, debug_span, span, Level}; -/// # fn main() { -/// enter_span!(debug_span!("my_span")); -/// // is equivalent to: -/// enter_span!(span!(Level::DEBUG, "my_span")); -/// # } -/// ``` -/// -/// ```rust -/// # use sp_tracing::{within_span, debug_span}; -/// # fn main() { -/// within_span! { debug_span!("my span"); -/// // do the work -/// }; -/// # } -/// ``` -#[macro_export] -macro_rules! debug_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::debug_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::debug_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::debug_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::DEBUG, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::debug_span!($name,)}; -} - -/// Constructs a span at the info level to be used with [`enter_span!`] and [`within_span!`] -/// -/// [Fields] and [attributes] are set using the same syntax as the [`span!`] -/// macro. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// [attributes]: index.html#configuring-attributes -/// [Fields]: index.html#recording-fields -/// [`span!`]: macro.span.html -/// [`enter_span!`]: macro.enter_span.html -/// [`within_span!`]: macro.within_span.html -/// -/// # Examples -/// -/// ```rust -/// # use sp_tracing::{enter_span, span, info_span, Level}; -/// # fn main() { -/// enter_span!(info_span!("my_span")); -/// // is equivalent to: -/// enter_span!(span!(Level::INFO, "my_span")); -/// # } -/// ``` -/// -/// ```rust -/// # use sp_tracing::{within_span, info_span}; -/// # fn main() { -/// within_span! { info_span!("my span"); -/// 1 + 1; -/// // do the work -/// }; -/// # } -/// ``` -#[macro_export] -macro_rules! info_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::info_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::info_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::INFO, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::info_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::INFO, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::info_span!($name,)}; -} - -/// Constructs a span at the warn level to be used with [`enter_span!`] and [`within_span!`] -/// -/// [Fields] and [attributes] are set using the same syntax as the [`span!`] -/// macro. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// [attributes]: index.html#configuring-attributes -/// [Fields]: index.html#recording-fields -/// [`span!`]: macro.span.html -/// [`enter_span!`]: macro.enter_span.html -/// [`within_span!`]: macro.within_span.html -/// -/// # Examples -/// -/// ```rust -/// # use sp_tracing::{enter_span, warn_span, span, Level}; -/// # fn main() { -/// enter_span!(warn_span!("my_span")); -/// // is equivalent to: -/// enter_span!(span!(Level::WARN, "my_span")); -/// # } -/// ``` -/// -/// ```rust -/// use sp_tracing::{within_span, warn_span}; -/// # fn main() { -/// within_span! { warn_span!("my span"); -/// // do the work -/// } -/// # } -/// ``` -#[macro_export] -macro_rules! warn_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::warn_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::warn_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::WARN, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::warn_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::WARN, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::warn_span!($name,)}; -} -/// Constructs a span at the error level to be used with [`enter_span!`] and [`within_span!`] -/// -/// [Fields] and [attributes] are set using the same syntax as the [`span!`] -/// macro. -/// -/// See [the top-level documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [lib]: index.html#using-the-macros -/// [attributes]: index.html#configuring-attributes -/// [Fields]: index.html#recording-fields -/// [`span!`]: macro.span.html -/// [`enter_span!`]: macro.enter_span.html -/// [`within_span!`]: macro.within_span.html -/// -/// # Examples -/// -/// ```rust -/// # use sp_tracing::{enter_span, span, error_span, Level}; -/// # fn main() { -/// enter_span!(error_span!("my_span")); -/// // is equivalent to: -/// enter_span!(span!(Level::ERROR, "my_span")); -/// # } -/// ``` -/// -/// ```rust -/// # use sp_tracing::{within_span, error_span}; -/// # fn main() { -/// within_span!{ error_span!("my span"); -/// // do the work -/// 1 + 1; -/// } -/// # } -/// ``` -#[macro_export] -macro_rules! error_span { - (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - parent: $parent, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (target: $target:expr, parent: $parent:expr, $name:expr) => { - $crate::error_span!(target: $target, parent: $parent, $name,) - }; - (parent: $parent:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (parent: $parent:expr, $name:expr) => { - $crate::error_span!(parent: $parent, $name,) - }; - (target: $target:expr, $name:expr, $($field:tt)*) => { - $crate::span!( - target: $target, - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - (target: $target:expr, $name:expr) => { - $crate::error_span!(target: $target, $name,) - }; - ($name:expr, $($field:tt)*) => { - $crate::span!( - target: module_path!(), - $crate::Level::ERROR, - $name, - $($field)* - ) - }; - ($name:expr) => {$crate::error_span!($name,)}; -} - -/// Constructs an event at the trace level. -/// -/// This functions similarly to the [`event!`] macro. See [the top-level -/// documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [`event!`]: macro.event.html -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// ```rust -/// use sp_tracing::trace; -/// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } -/// # impl Position { -/// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; -/// # fn dist(&self, other: Position) -> f32 { -/// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2(); -/// # (x + y).sqrt() -/// # } -/// # } -/// # fn main() { -/// let pos = Position { x: 3.234, y: -1.223 }; -/// let origin_dist = pos.dist(Position::ORIGIN); -/// -/// trace!(position = ?pos, ?origin_dist); -/// trace!( -/// target: "app_events", -/// position = ?pos, -/// "x is {} and y is {}", -/// if pos.x >= 0.0 { "positive" } else { "negative" }, -/// if pos.y >= 0.0 { "positive" } else { "negative" } -/// ); -/// # } -/// ``` -#[macro_export] -macro_rules! trace { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::TRACE, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - {}, - $($arg)+ - ) - ); -} - -/// Constructs an event at the debug level. -/// -/// This functions similarly to the [`event!`] macro. See [the top-level -/// documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [`event!`]: macro.event.html -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// ```rust -/// use sp_tracing::debug; -/// # fn main() { -/// # #[derive(Debug)] struct Position { x: f32, y: f32 } -/// -/// let pos = Position { x: 3.234, y: -1.223 }; -/// -/// debug!(?pos.x, ?pos.y); -/// debug!(target: "app_events", position = ?pos, "New position"); -/// # } -/// ``` -#[macro_export] -macro_rules! debug { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::DEBUG, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::DEBUG, - {}, - $($arg)+ - ) - ); -} - -/// Constructs an event at the info level. -/// -/// This functions similarly to the [`event!`] macro. See [the top-level -/// documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [`event!`]: macro.event.html -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// ```rust -/// use sp_tracing::info; -/// # // this is so the test will still work in no-std mode -/// # #[derive(Debug)] -/// # pub struct Ipv4Addr; -/// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } -/// # fn main() { -/// # struct Connection { port: u32, speed: f32 } -/// -/// let addr = Ipv4Addr::new(127, 0, 0, 1); -/// let conn = Connection { port: 40, speed: 3.20 }; -/// -/// info!(conn.port, "connected to {:?}", addr); -/// info!( -/// target: "connection_events", -/// ip = ?addr, -/// conn.port, -/// ?conn.speed, -/// ); -/// # } -/// ``` -#[macro_export] -macro_rules! info { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::INFO, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::INFO, - {}, - $($arg)+ - ) - ); -} - -/// Constructs an event at the warn level. -/// -/// This functions similarly to the [`event!`] macro. See [the top-level -/// documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [`event!`]: macro.event.html -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// ```rust -/// use sp_tracing::warn; -/// # fn main() { -/// -/// let warn_description = "Invalid Input"; -/// let input = &[0x27, 0x45]; -/// -/// warn!(?input, warning = warn_description); -/// warn!( -/// target: "input_events", -/// warning = warn_description, -/// "Received warning for input: {:?}", input, -/// ); -/// # } -/// ``` -#[macro_export] -macro_rules! warn { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::WARN, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::WARN, - {}, - $($arg)+ - ) - ); -} - -/// Constructs an event at the error level. -/// -/// This functions similarly to the [`event!`] macro. See [the top-level -/// documentation][lib] for details on the syntax accepted by -/// this macro. -/// -/// [`event!`]: macro.event.html -/// [lib]: index.html#using-the-macros -/// -/// # Examples -/// -/// ```rust -/// use sp_tracing::error; -/// # fn main() { -/// -/// let (err_info, port) = ("No connection", 22); -/// -/// error!(port, error = %err_info); -/// error!(target: "app_events", "App Error: {}", err_info); -/// error!({ info = err_info }, "error on port: {}", port); -/// # } -/// ``` -#[macro_export] -macro_rules! error { - (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) - ); - (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) - ); - (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($field)+ }, - $($arg)+ - ) - ); - (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { ?$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { %$($k).+ = $($field)*} - ) - ); - (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { $($k).+, $($field)*} - ) - ); - (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { ?$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - { %$($k).+, $($field)*} - ) - ); - (parent: $parent:expr, $($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - parent: $parent, - $crate::Level::ERROR, - {}, - $($arg)+ - ) - ); - (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) - ); - (target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) - ); - (target: $target:expr, $($arg:tt)+ ) => ( - $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) - ); - ({ $($field:tt)+ }, $($arg:tt)+ ) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($field)+ }, - $($arg)+ - ) - ); - ($($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+ = $($field)*} - ) - ); - (?$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+ = $($field)*} - ) - ); - (%$($k:ident).+ = $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::TRACE, - { %$($k).+ = $($field)*} - ) - ); - ($($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+, $($field)*} - ) - ); - (?$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+, $($field)*} - ) - ); - (%$($k:ident).+, $($field:tt)*) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { %$($k).+, $($field)*} - ) - ); - (?$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { ?$($k).+ } - ) - ); - (%$($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { %$($k).+ } - ) - ); - ($($k:ident).+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - { $($k).+ } - ) - ); - ($($arg:tt)+) => ( - $crate::event!( - target: module_path!(), - $crate::Level::ERROR, - {}, - $($arg)+ - ) - ); -} - - -#[macro_export] -// TODO: determine if this ought to be public API? -#[doc(hidden)] -macro_rules! level_enabled { - ($lvl:expr) => { - // FIXME: use the runtime interface to figure this out - true - // $crate::dispatcher::has_been_set() && $lvl <= $crate::level_filters::STATIC_MAX_LEVEL - - }; -} - -#[macro_export] -// TODO: determine if this ought to be public API? -#[doc(hidden)] -macro_rules! is_enabled { - ($metadata:expr) => {{ - $crate::with_tracing_subscriber(|t| t.enabled(&$metadata)).unwrap_or(false) - }}; -} - -#[doc(hidden)] -#[macro_export] -macro_rules! valueset { - - // === base case === - (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { - WasmValuesSet::from(sp_std::vec![ $($val),* ]) - }; - - // === recursive case (more tts) === - - // TODO(#1138): determine a new syntax for uninitialized span fields, and - // re-enable this. - // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { - // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) - // }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&$val))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&$($k).+))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+) ))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$($k).+)))) }, - $next, - $($rest)* - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$val)))) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{}", &$val)))) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&$val))) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&$($k).+))) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, - $next, - ) - }; - (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { - $crate::valueset!( - @ { $($out),*, (&$next, Some(WasmValue::from(&format_args!("{:?}", &$($k).+)))) }, - $next, - ) - }; - // Remainder is unparseable, but exists --- must be format args! - (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { - $crate::valueset!(@ { (&$next, Some(WasmValue::from(&format_args!($($rest)+)))), $($out),* }, $next, ) - }; - - // === entry === - ($fields:expr, $($kvs:tt)+) => { - { - #[allow(unused_imports)] - use $crate::{WasmValuesSet, WasmValue}; - let mut iter = $fields.iter(); - $crate::valueset!( - @ { }, - iter.next().expect("Fields must be defined"), - $($kvs)+ - ) - } - }; - ($fields:expr,) => ( - WasmValuesSet::empty() - - ); -} - -#[doc(hidden)] -#[macro_export] -macro_rules! fieldset { - // == base case == - (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { - WasmFields::from(sp_std::vec![ $($out),* ] as sp_std::vec::Vec<&str>) - }; - - // == recursive cases (more tts) == - (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - // TODO(#1138): determine a new syntax for uninitialized span fields, and - // re-enable this. - // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { - // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - // }; - (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { - $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) - }; - - // Remainder is unparseable, but exists --- must be format args! - (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { - $crate::fieldset!(@ { "message", $($out),*, }) - }; - - // == entry == - ($($args:tt)*) => { - $crate::fieldset!(@ { } $($args)*,) - }; - -} - -#[doc(hidden)] -#[macro_export] -macro_rules! __tracing_stringify { - ($s:expr) => { - stringify!($s) - }; -} - -#[doc(hidden)] -#[macro_export] -macro_rules! if_log_enabled { - ($e:expr;) => { - $crate::if_log_enabled! { $e } - }; - ($if_log:block) => { - $crate::if_log_enabled! { $if_log else {} } - }; - ($if_log:block else $else_block:block) => { - $else_block - }; -} \ No newline at end of file From 3afa77e5e4f27f7b12a4202f879f96693bc5362c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 10 Sep 2020 13:26:54 +0200 Subject: [PATCH 102/113] we are able to convert to static items --- Cargo.lock | 2 + client/tracing/src/lib.rs | 51 +---- primitives/io/src/lib.rs | 2 +- primitives/tracing/Cargo.toml | 4 + primitives/tracing/src/lib.rs | 5 - primitives/tracing/src/types.rs | 342 ++++++++++++++++++++------------ 6 files changed, 223 insertions(+), 183 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdbc79fc66a2a..a24bb75fc421d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8461,8 +8461,10 @@ dependencies = [ name = "sp-tracing" version = "2.0.0-rc6" dependencies = [ + "lazy_static", "log", "parity-scale-codec", + "parking_lot 0.11.0", "sp-std", "tracing", "tracing-core", diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 78bacc1af9827..53f6a6ce7f9fc 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -43,7 +43,6 @@ use tracing::{ use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; -use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); @@ -286,9 +285,7 @@ fn parse_target(s: &str) -> (String, Level) { impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if metadata.target() == WASM_TRACE_IDENTIFIER - || self.check_target(metadata.target(), metadata.level()) - { + if self.check_target(metadata.target(), metadata.level()) { log::debug!(target: "tracing", "Enabled target: {:?}", metadata); true @@ -304,16 +301,6 @@ impl Subscriber for ProfilingSubscriber { let mut values = Values::default(); attrs.record(&mut values); - if attrs.metadata().target() == WASM_TRACE_IDENTIFIER { - // 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()) { - // returning as disabled - return Id::from_u64(0) - } - } - } - let span_datum = SpanDatum { id: id.clone(), parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), @@ -342,25 +329,11 @@ impl Subscriber for ProfilingSubscriber { fn event(&self, event: &Event<'_>) { let mut values = Values::default(); event.record(&mut values); - let target = { - if event.metadata().target() == WASM_TRACE_IDENTIFIER { - // 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, event.metadata().level()) { - return // nothing to be done, we ignore - } - wasm_target.to_owned() - } else { - event.metadata().target().to_owned() - } - } else { - event.metadata().target().to_owned() - } - }; + let trace_event = TraceEvent { name: event.metadata().name(), level: event.metadata().level().clone(), - target, + target: event.metadata().target().to_string(), values, parent_id: event.parent().cloned().or_else(|| self.current_span.id()), }; @@ -394,7 +367,7 @@ impl Subscriber for ProfilingSubscriber { } fn try_close(&self, span: Id) -> bool { - let mut span_datum = { + let span_datum = { let mut span_data = self.span_data.lock(); match span_data.entry(span).and_modify(|d| { d.ref_count = d.ref_count.saturating_sub(1); @@ -410,20 +383,8 @@ impl Subscriber for ProfilingSubscriber { } } }; - 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) { - span_datum.name = n; - } - if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { - span_datum.target = t; - } - if self.check_target(&span_datum.target, &span_datum.level) { - self.trace_handler.handle_span(span_datum); - } - } else { - self.trace_handler.handle_span(span_datum); - } + self.trace_handler.handle_span(span_datum); + true } } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index d6bdd9af41a57..be9e28aea04f2 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1041,7 +1041,7 @@ pub trait WasmTracing { /// cheap as it needs to jump the wasm-native-barrier, so caching the result wasm-side might be /// a useful addition. fn enabled(&mut self, metadata: Crossing) -> bool { - let metadata: &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); + let metadata: &tracing_core::metadata::Metadata<'static> = metadata.into_inner().into(); tracing::dispatcher::get_default(|d| { d.enabled(metadata) }) diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 5574a3f4db961..477e5c12a3fef 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -22,6 +22,8 @@ codec = { version = "1.3.1", package = "parity-scale-codec", default-features = tracing = { version = "0.1.19", default-features = false } tracing-core = { version = "0.1.16", default-features = false } log = { version = "0.4.8", optional = true } +lazy_static = { version = "1.4.0", optional = true } +parking_lot = { version = "0.11", optional = true } [features] default = [ "std" ] @@ -35,5 +37,7 @@ std = [ "tracing-core/std", "codec/std", "sp-std/std", + "lazy_static", + "parking_lot", "log", ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index f1aed0f0f27dc..ebadf33d807af 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -115,11 +115,6 @@ pub use crate::types::{ WasmMetadata, WasmEntryAttributes, WasmValuesSet, WasmValue, WasmFields, WasmLevel, WasmFieldName }; -#[cfg(feature = "std")] -pub use crate::types::{ - WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER -}; - /// Runs given code within a tracing span, measuring it's execution time. /// diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 8f6d603df85a2..d33165ef89c30 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -24,9 +24,11 @@ use sp_std::{ }; use sp_std::Writer; use codec::{Encode, Decode}; +use tracing_core::{Metadata, field::{FieldSet, Value}}; /// The Tracing Level – the user can filter by this #[derive(Clone, Encode, Decode, Debug)] +#[cfg_attr(feature = "std", derive(PartialEq, Eq, Hash))] pub enum WasmLevel { /// This is a fatal errors ERROR, @@ -79,6 +81,24 @@ pub enum WasmValue { Encoded(Vec), } +impl WasmValue { + fn as_value<'a>(&'a self) -> Option<&'a dyn Value> { + match self { + WasmValue::Bool(ref i) => { + Some(i as &dyn Value) + } + // WasmValue::Formatted(i) | WasmValue::Str(i) => { + // if let Ok(s) = std::str::from_utf8(&i) { + // Some(&s as &dyn Value) + // } else { + // None + // } + // } + _ => None + } + } +} + impl core::fmt::Debug for WasmValue { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { @@ -201,6 +221,32 @@ impl From for WasmValue { } } +// impl tracing_core::sealed::Sealed for WasmValue {} + +// impl Value for WasmValue { +// fn record(&self, key: &tracing_core::field::Field, v: &mut dyn tracing_core::field::Visit) { +// match self { +// WasmValue::U8(ref i) => v.record_u64(key, i as u64), +// WasmValue::I8(ref i) => v.record_u64(key, i as u64), +// WasmValue::U32(ref i) => v.record_u64(key, i as u64), +// WasmValue::I32(ref i) => v.record_u64(key, i as u64), +// WasmValue::I64(ref i) => v.record_u64(key, i as u64), +// WasmValue::U64(ref i) => v.record_u64(key, i as u64), +// WasmValue::Bool(ref i) => v.record_bool(key, i); +// WasmValue::Formatted(ref i) | WasmValue::Str(ref i) => { +// } +// _ => unreachable!() +// // WasmValue::Encoded(ref v) => { +// // f.write_str("Scale(")?; +// // for byte in v { +// // f.write_fmt(format_args!("{:02x}", byte))?; +// // } +// // f.write_str(")") +// // } +// } +// } +// } + /// The name of a field provided as the argument name when contstructing an /// `event!` or `span!`. /// Generally generated automaticaly via `stringify` from an `'static &str`. @@ -263,8 +309,8 @@ impl WasmFields { } } -impl From<&tracing_core::field::FieldSet> for WasmFields { - fn from(wm: &tracing_core::field::FieldSet) -> WasmFields { +impl From<&FieldSet> for WasmFields { + fn from(wm: &FieldSet) -> WasmFields { WasmFields(wm.iter().map(|s| s.name().into()).collect()) } } @@ -366,27 +412,18 @@ pub struct WasmMetadata { pub target: Vec, /// The level of this entry pub level: WasmLevel, - /// The file this was emitted from – useful for debugging; `&'static str` converted to bytes - pub file: Vec, - /// The specific line number in the file – useful for debugging - pub line: u32, - /// The module path; `&'static str` converted to bytes - pub module_path: Vec, /// Whether this is a call to `span!` or `event!` pub is_span: bool, /// The list of fields specified in the call pub fields: WasmFields, } -impl From<&tracing_core::Metadata<'_>> for WasmMetadata { - fn from(wm: &tracing_core::Metadata<'_>) -> WasmMetadata { +impl From<&Metadata<'_>> for WasmMetadata { + fn from(wm: &Metadata<'_>) -> WasmMetadata { WasmMetadata { name: wm.name().as_bytes().to_vec(), target: wm.target().as_bytes().to_vec(), level: wm.level().into(), - file: wm.file().map(|f| f.as_bytes().to_vec()).unwrap_or_default(), - line: wm.line().unwrap_or_default(), - module_path: wm.module_path().map(|m| m.as_bytes().to_vec()).unwrap_or_default(), is_span: wm.is_span(), fields: wm.fields().into() } @@ -399,9 +436,6 @@ impl core::fmt::Debug for WasmMetadata { .field("name", &decode_field(&self.name)) .field("target", &decode_field(&self.target)) .field("level", &self.level) - .field("file", &decode_field(&self.file)) - .field("line", &self.line) - .field("module_path", &decode_field(&self.module_path)) .field("is_span", &self.is_span) .field("fields", &self.fields) .finish() @@ -415,9 +449,6 @@ impl core::default::Default for WasmMetadata { target, name: Default::default(), level: Default::default(), - file: Default::default(), - line: Default::default(), - module_path: Default::default(), is_span: true, fields: WasmFields::empty() } @@ -477,141 +508,188 @@ impl core::default::Default for WasmEntryAttributes { #[cfg(feature = "std")] mod std_features { - use tracing_core::callsite; use tracing; + use tracing_core::{ + callsite, Level, + field::{Value, Field, FieldSet, ValueSet}, + metadata::{Kind, Metadata} + }; + use parking_lot::Mutex; + use super::WasmLevel; + use std::collections::hash_map::HashMap; + use lazy_static::lazy_static; + + // target, name, fieldset, level, kind + type MetadataId = (String, String, Vec, WasmLevel, bool); + + lazy_static! { + static ref METADATA: Mutex>> = Default::default(); + } + /// Static entry use for wasm-originated metadata. pub struct WasmCallsite; impl callsite::Callsite for WasmCallsite { fn set_interest(&self, _: tracing_core::Interest) { unimplemented!() } - fn metadata(&self) -> &tracing_core::Metadata { unimplemented!() } + fn metadata(&self) -> &Metadata { unimplemented!() } } static CALLSITE: WasmCallsite = WasmCallsite; + /// The identifier we are using to inject the wasm events in the generic `tracing` system - pub static WASM_TRACE_IDENTIFIER: &'static str = "wasm_tracing"; - /// The fieldname for the wasm-originated name - pub static WASM_NAME_KEY: &'static str = "name"; - /// The fieldname for the wasm-originated target - pub static WASM_TARGET_KEY: &'static str = "target"; - /// The the list of all static field names we construct from the given metadata - pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, - "file", "line", "module_path", "params"]; - - // Implementation Note: - // the original `tracing` crate generates these static metadata entries at every `span!` and - // `event!` location to allow for highly optimised filtering. For us to allow level-based emitting - // of wasm events we need these static metadata entries to inject into that system. We then provide - // generic `From`-implementations picking the right metadata to refer to. - - static SPAN_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::SPAN - ); - - static SPAN_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::SPAN - ); - static SPAN_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::SPAN - ); - - static SPAN_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::SPAN - ); - - static SPAN_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::SPAN - ); - - static EVENT_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::EVENT - ); - - static EVENT_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::EVENT - ); - - static EVENT_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::EVENT - ); - - static EVENT_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::EVENT - ); - - static EVENT_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( - WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, - tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), - tracing_core::metadata::Kind::EVENT - ); - - impl From<&crate::WasmMetadata> for &'static tracing_core::Metadata<'static> { - fn from(wm: &crate::WasmMetadata) -> &'static tracing_core::Metadata<'static> { - match (&wm.level, wm.is_span) { - (&crate::WasmLevel::ERROR, true) => &SPAN_ERROR_METADATA, - (&crate::WasmLevel::WARN, true) => &SPAN_WARN_METADATA, - (&crate::WasmLevel::INFO, true) => &SPAN_INFO_METADATA, - (&crate::WasmLevel::DEBUG, true) => &SPAN_DEBUG_METADATA, - (&crate::WasmLevel::TRACE, true) => &SPAN_TRACE_METADATA, - (&crate::WasmLevel::ERROR, false) => &EVENT_ERROR_METADATA, - (&crate::WasmLevel::WARN, false) => &EVENT_WARN_METADATA, - (&crate::WasmLevel::INFO, false) => &EVENT_INFO_METADATA, - (&crate::WasmLevel::DEBUG, false) => &EVENT_DEBUG_METADATA, - (&crate::WasmLevel::TRACE, false) => &EVENT_TRACE_METADATA, + pub static WASM_TRACE_FALLBACK: &'static str = "wasm_tracing"; + + fn mark_static_str<'a>(inp: &'a str) -> &'static str { + unsafe { + std::mem::transmute(inp) + } + } + + fn mark_static_slice<'a>(v : &'a[String]) -> &'static [&'static str] { + unsafe { + std::mem::transmute(v) + } + } + + fn get_metadata( + target: String, + name: String, + fields: Vec, + level: WasmLevel, + is_span: bool + ) -> &'static Metadata<'static> { + + let n = mark_static_str(name.as_str()); + let t = mark_static_str(target.as_str()); + let f = mark_static_slice(&fields[..]); + let kind = if is_span { Kind::SPAN } else { Kind::EVENT }; + let lvl = match level { + WasmLevel::ERROR => Level::ERROR, + WasmLevel::WARN => Level::WARN, + WasmLevel::INFO => Level::INFO, + WasmLevel::DEBUG => Level::DEBUG, + WasmLevel::TRACE => Level::TRACE, + }; + + let mut l = METADATA.lock(); + let r = l + .entry((target, name, fields, level, is_span)) + .or_insert_with(|| { + Metadata::new( + n, t, lvl, None, None, None, + FieldSet::new(f, tracing_core::identify_callsite!(&CALLSITE)), + kind + ) + }); + + let m : &'static Metadata<'static> = unsafe { + std::mem::transmute(r) + }; + m + } + + + macro_rules! slice_to_values { + ($fields:expr, $slice:expr, $len:expr ) => {{ + fn this_transmute<'a>(xs: &'a [(&'a Field, Option<&'a dyn Value>)]) -> &'a [(&'a Field, Option<&'a dyn Value>); $len] { + unsafe { + std::mem::transmute(xs.as_ptr()) + } } + + $fields.value_set(this_transmute($slice)) + }} + } + + fn run_converted(attrs: crate::WasmEntryAttributes, f: F) -> T + where F: Fn(&'static Metadata<'static>, &ValueSet) -> T + { + let metadata : &Metadata<'static> = attrs.metadata.into(); + let fields : HashMap<&str, Field> = metadata.fields() + .iter() + .map(|f| (f.name(), f)) + .collect(); + + let values = attrs.fields.0.iter().filter_map(|(f, v)| { + if let Ok(inner) = std::str::from_utf8(&f.0) { + if let Some(field) = fields.get(inner) { + return Some((field, v.as_ref().map(|d| d.as_value()).flatten())) + } + } + None + }).collect::>(); + + let values = match values.len() { + 0 => metadata.fields().value_set(&[]), + 1 => slice_to_values!(metadata.fields(), values.as_slice(), 1), + 2 => slice_to_values!(metadata.fields(), values.as_slice(), 2), + 3 => slice_to_values!(metadata.fields(), values.as_slice(), 3), + 4 => slice_to_values!(metadata.fields(), values.as_slice(), 4), + 5 => slice_to_values!(metadata.fields(), values.as_slice(), 5), + 6 => slice_to_values!(metadata.fields(), values.as_slice(), 6), + 7 => slice_to_values!(metadata.fields(), values.as_slice(), 7), + 8 => slice_to_values!(metadata.fields(), values.as_slice(), 8), + 9 => slice_to_values!(metadata.fields(), values.as_slice(), 9), + 10 => slice_to_values!(metadata.fields(), values.as_slice(), 10), + 11 => slice_to_values!(metadata.fields(), values.as_slice(), 11), + 12 => slice_to_values!(metadata.fields(), values.as_slice(), 12), + 13 => slice_to_values!(metadata.fields(), values.as_slice(), 13), + 14 => slice_to_values!(metadata.fields(), values.as_slice(), 14), + 15 => slice_to_values!(metadata.fields(), values.as_slice(), 15), + 16 => slice_to_values!(metadata.fields(), values.as_slice(), 16), + 17 => slice_to_values!(metadata.fields(), values.as_slice(), 17), + 18 => slice_to_values!(metadata.fields(), values.as_slice(), 18), + 19 => slice_to_values!(metadata.fields(), values.as_slice(), 19), + 20 => slice_to_values!(metadata.fields(), values.as_slice(), 20), + 21 => slice_to_values!(metadata.fields(), values.as_slice(), 21), + 22 => slice_to_values!(metadata.fields(), values.as_slice(), 22), + 23 => slice_to_values!(metadata.fields(), values.as_slice(), 23), + 24 => slice_to_values!(metadata.fields(), values.as_slice(), 24), + 25 => slice_to_values!(metadata.fields(), values.as_slice(), 25), + 26 => slice_to_values!(metadata.fields(), values.as_slice(), 26), + 27 => slice_to_values!(metadata.fields(), values.as_slice(), 27), + 28 => slice_to_values!(metadata.fields(), values.as_slice(), 28), + 29 => slice_to_values!(metadata.fields(), values.as_slice(), 29), + 30 => slice_to_values!(metadata.fields(), values.as_slice(), 30), + 31 => slice_to_values!(metadata.fields(), values.as_slice(), 31), + _ => slice_to_values!(metadata.fields(), &values[..32], 32), + }; + + f(metadata, &values) + } + + impl From for &'static Metadata<'static> { + fn from(wm: crate::WasmMetadata) -> &'static Metadata<'static> { + let name = String::from_utf8(wm.name).unwrap_or_else(|_|WASM_TRACE_FALLBACK.to_owned()); + let target = String::from_utf8(wm.target).unwrap_or_else(|_|WASM_TRACE_FALLBACK.to_owned()); + let fields = wm.fields.0.into_iter().filter_map(|s| String::from_utf8(s.0).ok()).collect(); + get_metadata(target, name, fields, wm.level, wm.is_span) } } impl From for tracing::Span { fn from(a: crate::WasmEntryAttributes) -> tracing::Span { - let name = std::str::from_utf8(&a.metadata.name).unwrap_or_default(); - let target = std::str::from_utf8(&a.metadata.target).unwrap_or_default(); - let file = std::str::from_utf8(&a.metadata.file).unwrap_or_default(); - let line = a.metadata.line; - let module_path = std::str::from_utf8(&a.metadata.module_path).unwrap_or_default(); - let params = a.fields; - let metadata : &tracing_core::metadata::Metadata<'static> = (&a.metadata).into(); - - tracing::span::Span::child_of( - a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), - &metadata, - &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } + let parent_id = a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)); + run_converted(a, move |metadata, values| + tracing::span::Span::child_of( + parent_id.clone(), + metadata, + values + ) ) } } + impl crate::WasmEntryAttributes { /// convert the given Attributes to an event and emit it using `tracing_core`. pub fn emit(self: crate::WasmEntryAttributes) { - let name = std::str::from_utf8(&self.metadata.name).unwrap_or_default(); - let target = std::str::from_utf8(&self.metadata.target).unwrap_or_default(); - let file = std::str::from_utf8(&self.metadata.file).unwrap_or_default(); - let line = self.metadata.line; - let module_path = std::str::from_utf8(&self.metadata.module_path).unwrap_or_default(); - let params = self.fields; - let metadata : &tracing_core::metadata::Metadata<'static> = (&self.metadata).into(); - - tracing_core::Event::child_of( - self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), - &metadata, - &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } + let parent_id = self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)); + run_converted(self, move |metadata, values| + tracing_core::Event::child_of( + parent_id.clone(), + metadata, + values + ) ) } } From 7b99c9c714d1dd2089f60083231591e0ed890a4c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 10 Sep 2020 15:44:05 +0200 Subject: [PATCH 103/113] implement more WasmValue types --- primitives/tracing/src/types.rs | 75 ++++----------------------------- 1 file changed, 9 insertions(+), 66 deletions(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index d33165ef89c30..bb281e3c90ec7 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -66,12 +66,8 @@ impl core::default::Default for WasmLevel { /// A paramter value provided to the span/event #[derive(Encode, Decode, Clone)] pub enum WasmValue { - U8(u8), - I8(i8), - U32(u32), - I32(i32), - I64(i64), U64(u64), + I64(i64), Bool(bool), Str(Vec), /// Debug or Display call, this is most-likely a print-able UTF8 String @@ -87,6 +83,12 @@ impl WasmValue { WasmValue::Bool(ref i) => { Some(i as &dyn Value) } + WasmValue::U64(ref i) => { + Some(i as &dyn Value) + } + WasmValue::I64(ref i) => { + Some(i as &dyn Value) + } // WasmValue::Formatted(i) | WasmValue::Str(i) => { // if let Ok(s) = std::str::from_utf8(&i) { // Some(&s as &dyn Value) @@ -102,24 +104,12 @@ impl WasmValue { impl core::fmt::Debug for WasmValue { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { - WasmValue::U8(ref i) => { - f.write_fmt(format_args!("{}_u8", i)) - } - WasmValue::I8(ref i) => { - f.write_fmt(format_args!("{}_i8", i)) - } - WasmValue::U32(ref i) => { - f.write_fmt(format_args!("{}_u32", i)) - } - WasmValue::I32(ref i) => { - f.write_fmt(format_args!("{}_i32", i)) + WasmValue::U64(ref i) => { + f.write_fmt(format_args!("{}_u64", i)) } WasmValue::I64(ref i) => { f.write_fmt(format_args!("{}_i64", i)) } - WasmValue::U64(ref i) => { - f.write_fmt(format_args!("{}_u64", i)) - } WasmValue::Bool(ref i) => { f.write_fmt(format_args!("{}_bool", i)) } @@ -141,29 +131,12 @@ impl core::fmt::Debug for WasmValue { } } -impl From for WasmValue { - fn from(u: u8) -> WasmValue { - WasmValue::U8(u) - } -} - -impl From<&i8> for WasmValue { - fn from(inp: &i8) -> WasmValue { - WasmValue::I8(inp.clone()) - } -} - impl From<&str> for WasmValue { fn from(inp: &str) -> WasmValue { WasmValue::Str(inp.as_bytes().to_vec()) } } -impl From<&&str> for WasmValue { - fn from(inp: &&str) -> WasmValue { - WasmValue::Str((*inp).as_bytes().to_vec()) - } -} impl From for WasmValue { fn from(inp: bool) -> WasmValue { @@ -179,36 +152,6 @@ impl From> for WasmValue { } } -impl From for WasmValue { - fn from(u: i8) -> WasmValue { - WasmValue::I8(u) - } -} - -impl From for WasmValue { - fn from(u: i32) -> WasmValue { - WasmValue::I32(u) - } -} - -impl From<&i32> for WasmValue { - fn from(u: &i32) -> WasmValue { - WasmValue::I32(*u) - } -} - -impl From for WasmValue { - fn from(u: u32) -> WasmValue { - WasmValue::U32(u) - } -} - -impl From<&u32> for WasmValue { - fn from(u: &u32) -> WasmValue { - WasmValue::U32(*u) - } -} - impl From for WasmValue { fn from(u: u64) -> WasmValue { WasmValue::U64(u) From 959c40124dff7150639e58bfc5e1ab59c9b17b2b Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 11 Sep 2020 09:49:14 +0200 Subject: [PATCH 104/113] adding support to convert str, debug and encoded values --- primitives/tracing/src/types.rs | 113 +++++++++++++++++--------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index bb281e3c90ec7..65b6880b4132d 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -75,30 +75,9 @@ pub enum WasmValue { /// SCALE CODEC encoded object – the name should allow the received to know /// how to decode this. Encoded(Vec), -} - -impl WasmValue { - fn as_value<'a>(&'a self) -> Option<&'a dyn Value> { - match self { - WasmValue::Bool(ref i) => { - Some(i as &dyn Value) - } - WasmValue::U64(ref i) => { - Some(i as &dyn Value) - } - WasmValue::I64(ref i) => { - Some(i as &dyn Value) - } - // WasmValue::Formatted(i) | WasmValue::Str(i) => { - // if let Ok(s) = std::str::from_utf8(&i) { - // Some(&s as &dyn Value) - // } else { - // None - // } - // } - _ => None - } - } + #[cfg(feature = "std")] + #[codec(skip)] + Extracted(tracing_core::field::DisplayValue), } impl core::fmt::Debug for WasmValue { @@ -120,6 +99,9 @@ impl core::fmt::Debug for WasmValue { f.write_fmt(format_args!("{:?}", i)) } } + WasmValue::Extracted(ref v) => { + f.write_fmt(format_args!("{}", v)) + } WasmValue::Encoded(ref v) => { f.write_str("Scale(")?; for byte in v { @@ -164,32 +146,6 @@ impl From for WasmValue { } } -// impl tracing_core::sealed::Sealed for WasmValue {} - -// impl Value for WasmValue { -// fn record(&self, key: &tracing_core::field::Field, v: &mut dyn tracing_core::field::Visit) { -// match self { -// WasmValue::U8(ref i) => v.record_u64(key, i as u64), -// WasmValue::I8(ref i) => v.record_u64(key, i as u64), -// WasmValue::U32(ref i) => v.record_u64(key, i as u64), -// WasmValue::I32(ref i) => v.record_u64(key, i as u64), -// WasmValue::I64(ref i) => v.record_u64(key, i as u64), -// WasmValue::U64(ref i) => v.record_u64(key, i as u64), -// WasmValue::Bool(ref i) => v.record_bool(key, i); -// WasmValue::Formatted(ref i) | WasmValue::Str(ref i) => { -// } -// _ => unreachable!() -// // WasmValue::Encoded(ref v) => { -// // f.write_str("Scale(")?; -// // for byte in v { -// // f.write_fmt(format_args!("{:02x}", byte))?; -// // } -// // f.write_str(")") -// // } -// } -// } -// } - /// The name of a field provided as the argument name when contstructing an /// `event!` or `span!`. /// Generally generated automaticaly via `stringify` from an `'static &str`. @@ -454,11 +410,11 @@ mod std_features { use tracing; use tracing_core::{ callsite, Level, - field::{Value, Field, FieldSet, ValueSet}, + field::{Value, Field, FieldSet, ValueSet, display}, metadata::{Kind, Metadata} }; use parking_lot::Mutex; - use super::WasmLevel; + use super::{WasmValue, WasmLevel}; use std::collections::hash_map::HashMap; use lazy_static::lazy_static; @@ -551,11 +507,17 @@ mod std_features { .iter() .map(|f| (f.name(), f)) .collect(); + let mut vl = attrs.fields.0; - let values = attrs.fields.0.iter().filter_map(|(f, v)| { + let values = vl.iter_mut().filter_map(|(f, v)| { if let Ok(inner) = std::str::from_utf8(&f.0) { if let Some(field) = fields.get(inner) { - return Some((field, v.as_ref().map(|d| d.as_value()).flatten())) + return Some((field, + match v { + Some(d) => d.as_value(), + None => None + } + )) } } None @@ -600,6 +562,49 @@ mod std_features { f(metadata, &values) } + fn make_hex(inp: &[u8]) -> String { + inp.iter().map(|c| format!("{:02x}", c)).collect::() + } + + impl WasmValue { + + fn as_value<'a>(&'a mut self) -> Option<&'a dyn Value> { + match self { + // We convert to String + WasmValue::Formatted(i) | WasmValue::Str(i) => { + if let Ok(s) = String::from_utf8(i.to_vec()) { + *self = WasmValue::Extracted(display(s)) + } else { + *self = WasmValue::Extracted(display(make_hex(&i))) + } + } + WasmValue::Encoded(i) => { + *self = WasmValue::Extracted(display(make_hex(&i))) + } + _ => {} + } + + match self { + WasmValue::Bool(ref i) => { + Some(i as &dyn Value) + } + WasmValue::U64(ref i) => { + Some(i as &dyn Value) + } + WasmValue::I64(ref i) => { + Some(i as &dyn Value) + } + WasmValue::Extracted(ref i) => { + Some(i as &dyn Value) + } + WasmValue::Encoded(_) | WasmValue::Formatted(_) | WasmValue::Str(_) => { + // already dealt with above + unreachable!() + } + } + } + } + impl From for &'static Metadata<'static> { fn from(wm: crate::WasmMetadata) -> &'static Metadata<'static> { let name = String::from_utf8(wm.name).unwrap_or_else(|_|WASM_TRACE_FALLBACK.to_owned()); From b9a865865bc2e551ea8e79e5a93598223628c326 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 11 Sep 2020 10:35:43 +0200 Subject: [PATCH 105/113] more minor fixes --- primitives/tracing/src/types.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 65b6880b4132d..9b1b5b600c43b 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -24,7 +24,7 @@ use sp_std::{ }; use sp_std::Writer; use codec::{Encode, Decode}; -use tracing_core::{Metadata, field::{FieldSet, Value}}; +use tracing_core::{Metadata, field::FieldSet}; /// The Tracing Level – the user can filter by this #[derive(Clone, Encode, Decode, Debug)] @@ -99,6 +99,7 @@ impl core::fmt::Debug for WasmValue { f.write_fmt(format_args!("{:?}", i)) } } + #[cfg(feature = "std")] WasmValue::Extracted(ref v) => { f.write_fmt(format_args!("{}", v)) } From 4530b81da7aee5217c31cd3cbbcdf9a39e3e6895 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 11 Sep 2020 11:52:44 +0200 Subject: [PATCH 106/113] revert unsafe 'static making --- Cargo.lock | 2 - client/tracing/src/lib.rs | 51 +++- primitives/io/src/lib.rs | 2 +- primitives/tracing/Cargo.toml | 4 - primitives/tracing/src/lib.rs | 5 + primitives/tracing/src/types.rs | 423 +++++++++++++++----------------- 6 files changed, 249 insertions(+), 238 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc86ed5a3389f..57c8f1005ad84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8459,10 +8459,8 @@ dependencies = [ name = "sp-tracing" version = "2.0.0-rc6" dependencies = [ - "lazy_static", "log", "parity-scale-codec", - "parking_lot 0.11.0", "sp-std", "tracing", "tracing-core", diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 53f6a6ce7f9fc..78bacc1af9827 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -43,6 +43,7 @@ use tracing::{ use tracing_subscriber::CurrentSpan; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; +use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; const ZERO_DURATION: Duration = Duration::from_nanos(0); @@ -285,7 +286,9 @@ fn parse_target(s: &str) -> (String, Level) { impl Subscriber for ProfilingSubscriber { fn enabled(&self, metadata: &Metadata<'_>) -> bool { - if self.check_target(metadata.target(), metadata.level()) { + if metadata.target() == WASM_TRACE_IDENTIFIER + || self.check_target(metadata.target(), metadata.level()) + { log::debug!(target: "tracing", "Enabled target: {:?}", metadata); true @@ -301,6 +304,16 @@ impl Subscriber for ProfilingSubscriber { let mut values = Values::default(); attrs.record(&mut values); + if attrs.metadata().target() == WASM_TRACE_IDENTIFIER { + // 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()) { + // returning as disabled + return Id::from_u64(0) + } + } + } + let span_datum = SpanDatum { id: id.clone(), parent_id: attrs.parent().cloned().or_else(|| self.current_span.id()), @@ -329,11 +342,25 @@ impl Subscriber for ProfilingSubscriber { fn event(&self, event: &Event<'_>) { let mut values = Values::default(); event.record(&mut values); - + let target = { + if event.metadata().target() == WASM_TRACE_IDENTIFIER { + // 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, event.metadata().level()) { + return // nothing to be done, we ignore + } + wasm_target.to_owned() + } else { + event.metadata().target().to_owned() + } + } else { + event.metadata().target().to_owned() + } + }; let trace_event = TraceEvent { name: event.metadata().name(), level: event.metadata().level().clone(), - target: event.metadata().target().to_string(), + target, values, parent_id: event.parent().cloned().or_else(|| self.current_span.id()), }; @@ -367,7 +394,7 @@ impl Subscriber for ProfilingSubscriber { } fn try_close(&self, span: Id) -> bool { - let span_datum = { + let mut span_datum = { let mut span_data = self.span_data.lock(); match span_data.entry(span).and_modify(|d| { d.ref_count = d.ref_count.saturating_sub(1); @@ -383,8 +410,20 @@ impl Subscriber for ProfilingSubscriber { } } }; - self.trace_handler.handle_span(span_datum); - + 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) { + span_datum.name = n; + } + if let Some(t) = span_datum.values.string_values.remove(WASM_TARGET_KEY) { + span_datum.target = t; + } + if self.check_target(&span_datum.target, &span_datum.level) { + self.trace_handler.handle_span(span_datum); + } + } else { + self.trace_handler.handle_span(span_datum); + } true } } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index fcdde2f5fd63f..af9c4a64b9761 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1048,7 +1048,7 @@ pub trait WasmTracing { /// cheap as it needs to jump the wasm-native-barrier, so caching the result wasm-side might be /// a useful addition. fn enabled(&mut self, metadata: Crossing) -> bool { - let metadata: &tracing_core::metadata::Metadata<'static> = metadata.into_inner().into(); + let metadata: &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); tracing::dispatcher::get_default(|d| { d.enabled(metadata) }) diff --git a/primitives/tracing/Cargo.toml b/primitives/tracing/Cargo.toml index 477e5c12a3fef..5574a3f4db961 100644 --- a/primitives/tracing/Cargo.toml +++ b/primitives/tracing/Cargo.toml @@ -22,8 +22,6 @@ codec = { version = "1.3.1", package = "parity-scale-codec", default-features = tracing = { version = "0.1.19", default-features = false } tracing-core = { version = "0.1.16", default-features = false } log = { version = "0.4.8", optional = true } -lazy_static = { version = "1.4.0", optional = true } -parking_lot = { version = "0.11", optional = true } [features] default = [ "std" ] @@ -37,7 +35,5 @@ std = [ "tracing-core/std", "codec/std", "sp-std/std", - "lazy_static", - "parking_lot", "log", ] diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index ebadf33d807af..f1aed0f0f27dc 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -115,6 +115,11 @@ pub use crate::types::{ WasmMetadata, WasmEntryAttributes, WasmValuesSet, WasmValue, WasmFields, WasmLevel, WasmFieldName }; +#[cfg(feature = "std")] +pub use crate::types::{ + WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER +}; + /// Runs given code within a tracing span, measuring it's execution time. /// diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 9b1b5b600c43b..8f6d603df85a2 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -24,11 +24,9 @@ use sp_std::{ }; use sp_std::Writer; use codec::{Encode, Decode}; -use tracing_core::{Metadata, field::FieldSet}; /// The Tracing Level – the user can filter by this #[derive(Clone, Encode, Decode, Debug)] -#[cfg_attr(feature = "std", derive(PartialEq, Eq, Hash))] pub enum WasmLevel { /// This is a fatal errors ERROR, @@ -66,8 +64,12 @@ impl core::default::Default for WasmLevel { /// A paramter value provided to the span/event #[derive(Encode, Decode, Clone)] pub enum WasmValue { - U64(u64), + U8(u8), + I8(i8), + U32(u32), + I32(i32), I64(i64), + U64(u64), Bool(bool), Str(Vec), /// Debug or Display call, this is most-likely a print-able UTF8 String @@ -75,20 +77,29 @@ pub enum WasmValue { /// SCALE CODEC encoded object – the name should allow the received to know /// how to decode this. Encoded(Vec), - #[cfg(feature = "std")] - #[codec(skip)] - Extracted(tracing_core::field::DisplayValue), } impl core::fmt::Debug for WasmValue { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { - WasmValue::U64(ref i) => { - f.write_fmt(format_args!("{}_u64", i)) + WasmValue::U8(ref i) => { + f.write_fmt(format_args!("{}_u8", i)) + } + WasmValue::I8(ref i) => { + f.write_fmt(format_args!("{}_i8", i)) + } + WasmValue::U32(ref i) => { + f.write_fmt(format_args!("{}_u32", i)) + } + WasmValue::I32(ref i) => { + f.write_fmt(format_args!("{}_i32", i)) } WasmValue::I64(ref i) => { f.write_fmt(format_args!("{}_i64", i)) } + WasmValue::U64(ref i) => { + f.write_fmt(format_args!("{}_u64", i)) + } WasmValue::Bool(ref i) => { f.write_fmt(format_args!("{}_bool", i)) } @@ -99,10 +110,6 @@ impl core::fmt::Debug for WasmValue { f.write_fmt(format_args!("{:?}", i)) } } - #[cfg(feature = "std")] - WasmValue::Extracted(ref v) => { - f.write_fmt(format_args!("{}", v)) - } WasmValue::Encoded(ref v) => { f.write_str("Scale(")?; for byte in v { @@ -114,12 +121,29 @@ impl core::fmt::Debug for WasmValue { } } +impl From for WasmValue { + fn from(u: u8) -> WasmValue { + WasmValue::U8(u) + } +} + +impl From<&i8> for WasmValue { + fn from(inp: &i8) -> WasmValue { + WasmValue::I8(inp.clone()) + } +} + impl From<&str> for WasmValue { fn from(inp: &str) -> WasmValue { WasmValue::Str(inp.as_bytes().to_vec()) } } +impl From<&&str> for WasmValue { + fn from(inp: &&str) -> WasmValue { + WasmValue::Str((*inp).as_bytes().to_vec()) + } +} impl From for WasmValue { fn from(inp: bool) -> WasmValue { @@ -135,6 +159,36 @@ impl From> for WasmValue { } } +impl From for WasmValue { + fn from(u: i8) -> WasmValue { + WasmValue::I8(u) + } +} + +impl From for WasmValue { + fn from(u: i32) -> WasmValue { + WasmValue::I32(u) + } +} + +impl From<&i32> for WasmValue { + fn from(u: &i32) -> WasmValue { + WasmValue::I32(*u) + } +} + +impl From for WasmValue { + fn from(u: u32) -> WasmValue { + WasmValue::U32(u) + } +} + +impl From<&u32> for WasmValue { + fn from(u: &u32) -> WasmValue { + WasmValue::U32(*u) + } +} + impl From for WasmValue { fn from(u: u64) -> WasmValue { WasmValue::U64(u) @@ -209,8 +263,8 @@ impl WasmFields { } } -impl From<&FieldSet> for WasmFields { - fn from(wm: &FieldSet) -> WasmFields { +impl From<&tracing_core::field::FieldSet> for WasmFields { + fn from(wm: &tracing_core::field::FieldSet) -> WasmFields { WasmFields(wm.iter().map(|s| s.name().into()).collect()) } } @@ -312,18 +366,27 @@ pub struct WasmMetadata { pub target: Vec, /// The level of this entry pub level: WasmLevel, + /// The file this was emitted from – useful for debugging; `&'static str` converted to bytes + pub file: Vec, + /// The specific line number in the file – useful for debugging + pub line: u32, + /// The module path; `&'static str` converted to bytes + pub module_path: Vec, /// Whether this is a call to `span!` or `event!` pub is_span: bool, /// The list of fields specified in the call pub fields: WasmFields, } -impl From<&Metadata<'_>> for WasmMetadata { - fn from(wm: &Metadata<'_>) -> WasmMetadata { +impl From<&tracing_core::Metadata<'_>> for WasmMetadata { + fn from(wm: &tracing_core::Metadata<'_>) -> WasmMetadata { WasmMetadata { name: wm.name().as_bytes().to_vec(), target: wm.target().as_bytes().to_vec(), level: wm.level().into(), + file: wm.file().map(|f| f.as_bytes().to_vec()).unwrap_or_default(), + line: wm.line().unwrap_or_default(), + module_path: wm.module_path().map(|m| m.as_bytes().to_vec()).unwrap_or_default(), is_span: wm.is_span(), fields: wm.fields().into() } @@ -336,6 +399,9 @@ impl core::fmt::Debug for WasmMetadata { .field("name", &decode_field(&self.name)) .field("target", &decode_field(&self.target)) .field("level", &self.level) + .field("file", &decode_field(&self.file)) + .field("line", &self.line) + .field("module_path", &decode_field(&self.module_path)) .field("is_span", &self.is_span) .field("fields", &self.fields) .finish() @@ -349,6 +415,9 @@ impl core::default::Default for WasmMetadata { target, name: Default::default(), level: Default::default(), + file: Default::default(), + line: Default::default(), + module_path: Default::default(), is_span: true, fields: WasmFields::empty() } @@ -408,237 +477,141 @@ impl core::default::Default for WasmEntryAttributes { #[cfg(feature = "std")] mod std_features { + use tracing_core::callsite; use tracing; - use tracing_core::{ - callsite, Level, - field::{Value, Field, FieldSet, ValueSet, display}, - metadata::{Kind, Metadata} - }; - use parking_lot::Mutex; - use super::{WasmValue, WasmLevel}; - use std::collections::hash_map::HashMap; - use lazy_static::lazy_static; - - // target, name, fieldset, level, kind - type MetadataId = (String, String, Vec, WasmLevel, bool); - - lazy_static! { - static ref METADATA: Mutex>> = Default::default(); - } - /// Static entry use for wasm-originated metadata. pub struct WasmCallsite; impl callsite::Callsite for WasmCallsite { fn set_interest(&self, _: tracing_core::Interest) { unimplemented!() } - fn metadata(&self) -> &Metadata { unimplemented!() } + fn metadata(&self) -> &tracing_core::Metadata { unimplemented!() } } static CALLSITE: WasmCallsite = WasmCallsite; - /// The identifier we are using to inject the wasm events in the generic `tracing` system - pub static WASM_TRACE_FALLBACK: &'static str = "wasm_tracing"; - - fn mark_static_str<'a>(inp: &'a str) -> &'static str { - unsafe { - std::mem::transmute(inp) - } - } - - fn mark_static_slice<'a>(v : &'a[String]) -> &'static [&'static str] { - unsafe { - std::mem::transmute(v) - } - } - - fn get_metadata( - target: String, - name: String, - fields: Vec, - level: WasmLevel, - is_span: bool - ) -> &'static Metadata<'static> { - - let n = mark_static_str(name.as_str()); - let t = mark_static_str(target.as_str()); - let f = mark_static_slice(&fields[..]); - let kind = if is_span { Kind::SPAN } else { Kind::EVENT }; - let lvl = match level { - WasmLevel::ERROR => Level::ERROR, - WasmLevel::WARN => Level::WARN, - WasmLevel::INFO => Level::INFO, - WasmLevel::DEBUG => Level::DEBUG, - WasmLevel::TRACE => Level::TRACE, - }; - - let mut l = METADATA.lock(); - let r = l - .entry((target, name, fields, level, is_span)) - .or_insert_with(|| { - Metadata::new( - n, t, lvl, None, None, None, - FieldSet::new(f, tracing_core::identify_callsite!(&CALLSITE)), - kind - ) - }); - - let m : &'static Metadata<'static> = unsafe { - std::mem::transmute(r) - }; - m - } - - - macro_rules! slice_to_values { - ($fields:expr, $slice:expr, $len:expr ) => {{ - fn this_transmute<'a>(xs: &'a [(&'a Field, Option<&'a dyn Value>)]) -> &'a [(&'a Field, Option<&'a dyn Value>); $len] { - unsafe { - std::mem::transmute(xs.as_ptr()) - } - } - - $fields.value_set(this_transmute($slice)) - }} - } - - fn run_converted(attrs: crate::WasmEntryAttributes, f: F) -> T - where F: Fn(&'static Metadata<'static>, &ValueSet) -> T - { - let metadata : &Metadata<'static> = attrs.metadata.into(); - let fields : HashMap<&str, Field> = metadata.fields() - .iter() - .map(|f| (f.name(), f)) - .collect(); - let mut vl = attrs.fields.0; - - let values = vl.iter_mut().filter_map(|(f, v)| { - if let Ok(inner) = std::str::from_utf8(&f.0) { - if let Some(field) = fields.get(inner) { - return Some((field, - match v { - Some(d) => d.as_value(), - None => None - } - )) - } - } - None - }).collect::>(); - - let values = match values.len() { - 0 => metadata.fields().value_set(&[]), - 1 => slice_to_values!(metadata.fields(), values.as_slice(), 1), - 2 => slice_to_values!(metadata.fields(), values.as_slice(), 2), - 3 => slice_to_values!(metadata.fields(), values.as_slice(), 3), - 4 => slice_to_values!(metadata.fields(), values.as_slice(), 4), - 5 => slice_to_values!(metadata.fields(), values.as_slice(), 5), - 6 => slice_to_values!(metadata.fields(), values.as_slice(), 6), - 7 => slice_to_values!(metadata.fields(), values.as_slice(), 7), - 8 => slice_to_values!(metadata.fields(), values.as_slice(), 8), - 9 => slice_to_values!(metadata.fields(), values.as_slice(), 9), - 10 => slice_to_values!(metadata.fields(), values.as_slice(), 10), - 11 => slice_to_values!(metadata.fields(), values.as_slice(), 11), - 12 => slice_to_values!(metadata.fields(), values.as_slice(), 12), - 13 => slice_to_values!(metadata.fields(), values.as_slice(), 13), - 14 => slice_to_values!(metadata.fields(), values.as_slice(), 14), - 15 => slice_to_values!(metadata.fields(), values.as_slice(), 15), - 16 => slice_to_values!(metadata.fields(), values.as_slice(), 16), - 17 => slice_to_values!(metadata.fields(), values.as_slice(), 17), - 18 => slice_to_values!(metadata.fields(), values.as_slice(), 18), - 19 => slice_to_values!(metadata.fields(), values.as_slice(), 19), - 20 => slice_to_values!(metadata.fields(), values.as_slice(), 20), - 21 => slice_to_values!(metadata.fields(), values.as_slice(), 21), - 22 => slice_to_values!(metadata.fields(), values.as_slice(), 22), - 23 => slice_to_values!(metadata.fields(), values.as_slice(), 23), - 24 => slice_to_values!(metadata.fields(), values.as_slice(), 24), - 25 => slice_to_values!(metadata.fields(), values.as_slice(), 25), - 26 => slice_to_values!(metadata.fields(), values.as_slice(), 26), - 27 => slice_to_values!(metadata.fields(), values.as_slice(), 27), - 28 => slice_to_values!(metadata.fields(), values.as_slice(), 28), - 29 => slice_to_values!(metadata.fields(), values.as_slice(), 29), - 30 => slice_to_values!(metadata.fields(), values.as_slice(), 30), - 31 => slice_to_values!(metadata.fields(), values.as_slice(), 31), - _ => slice_to_values!(metadata.fields(), &values[..32], 32), - }; - - f(metadata, &values) - } - - fn make_hex(inp: &[u8]) -> String { - inp.iter().map(|c| format!("{:02x}", c)).collect::() - } - - impl WasmValue { - - fn as_value<'a>(&'a mut self) -> Option<&'a dyn Value> { - match self { - // We convert to String - WasmValue::Formatted(i) | WasmValue::Str(i) => { - if let Ok(s) = String::from_utf8(i.to_vec()) { - *self = WasmValue::Extracted(display(s)) - } else { - *self = WasmValue::Extracted(display(make_hex(&i))) - } - } - WasmValue::Encoded(i) => { - *self = WasmValue::Extracted(display(make_hex(&i))) - } - _ => {} - } - - match self { - WasmValue::Bool(ref i) => { - Some(i as &dyn Value) - } - WasmValue::U64(ref i) => { - Some(i as &dyn Value) - } - WasmValue::I64(ref i) => { - Some(i as &dyn Value) - } - WasmValue::Extracted(ref i) => { - Some(i as &dyn Value) - } - WasmValue::Encoded(_) | WasmValue::Formatted(_) | WasmValue::Str(_) => { - // already dealt with above - unreachable!() - } + pub static WASM_TRACE_IDENTIFIER: &'static str = "wasm_tracing"; + /// The fieldname for the wasm-originated name + pub static WASM_NAME_KEY: &'static str = "name"; + /// The fieldname for the wasm-originated target + pub static WASM_TARGET_KEY: &'static str = "target"; + /// The the list of all static field names we construct from the given metadata + pub static GENERIC_FIELDS: &'static [&'static str] = &[WASM_TARGET_KEY, WASM_NAME_KEY, + "file", "line", "module_path", "params"]; + + // Implementation Note: + // the original `tracing` crate generates these static metadata entries at every `span!` and + // `event!` location to allow for highly optimised filtering. For us to allow level-based emitting + // of wasm events we need these static metadata entries to inject into that system. We then provide + // generic `From`-implementations picking the right metadata to refer to. + + static SPAN_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + static SPAN_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static SPAN_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::SPAN + ); + + static EVENT_ERROR_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::ERROR, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_WARN_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::WARN, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_INFO_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::INFO, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_DEBUG_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::DEBUG, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + static EVENT_TRACE_METADATA : tracing_core::Metadata<'static> = tracing::Metadata::new( + WASM_TRACE_IDENTIFIER, WASM_TRACE_IDENTIFIER, tracing::Level::TRACE, None, None, None, + tracing_core::field::FieldSet::new(GENERIC_FIELDS, tracing_core::identify_callsite!(&CALLSITE)), + tracing_core::metadata::Kind::EVENT + ); + + impl From<&crate::WasmMetadata> for &'static tracing_core::Metadata<'static> { + fn from(wm: &crate::WasmMetadata) -> &'static tracing_core::Metadata<'static> { + match (&wm.level, wm.is_span) { + (&crate::WasmLevel::ERROR, true) => &SPAN_ERROR_METADATA, + (&crate::WasmLevel::WARN, true) => &SPAN_WARN_METADATA, + (&crate::WasmLevel::INFO, true) => &SPAN_INFO_METADATA, + (&crate::WasmLevel::DEBUG, true) => &SPAN_DEBUG_METADATA, + (&crate::WasmLevel::TRACE, true) => &SPAN_TRACE_METADATA, + (&crate::WasmLevel::ERROR, false) => &EVENT_ERROR_METADATA, + (&crate::WasmLevel::WARN, false) => &EVENT_WARN_METADATA, + (&crate::WasmLevel::INFO, false) => &EVENT_INFO_METADATA, + (&crate::WasmLevel::DEBUG, false) => &EVENT_DEBUG_METADATA, + (&crate::WasmLevel::TRACE, false) => &EVENT_TRACE_METADATA, } } } - impl From for &'static Metadata<'static> { - fn from(wm: crate::WasmMetadata) -> &'static Metadata<'static> { - let name = String::from_utf8(wm.name).unwrap_or_else(|_|WASM_TRACE_FALLBACK.to_owned()); - let target = String::from_utf8(wm.target).unwrap_or_else(|_|WASM_TRACE_FALLBACK.to_owned()); - let fields = wm.fields.0.into_iter().filter_map(|s| String::from_utf8(s.0).ok()).collect(); - get_metadata(target, name, fields, wm.level, wm.is_span) - } - } - impl From for tracing::Span { fn from(a: crate::WasmEntryAttributes) -> tracing::Span { - let parent_id = a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)); - run_converted(a, move |metadata, values| - tracing::span::Span::child_of( - parent_id.clone(), - metadata, - values - ) + let name = std::str::from_utf8(&a.metadata.name).unwrap_or_default(); + let target = std::str::from_utf8(&a.metadata.target).unwrap_or_default(); + let file = std::str::from_utf8(&a.metadata.file).unwrap_or_default(); + let line = a.metadata.line; + let module_path = std::str::from_utf8(&a.metadata.module_path).unwrap_or_default(); + let params = a.fields; + let metadata : &tracing_core::metadata::Metadata<'static> = (&a.metadata).into(); + + tracing::span::Span::child_of( + a.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + &metadata, + &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } ) } } - impl crate::WasmEntryAttributes { /// convert the given Attributes to an event and emit it using `tracing_core`. pub fn emit(self: crate::WasmEntryAttributes) { - let parent_id = self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)); - run_converted(self, move |metadata, values| - tracing_core::Event::child_of( - parent_id.clone(), - metadata, - values - ) + let name = std::str::from_utf8(&self.metadata.name).unwrap_or_default(); + let target = std::str::from_utf8(&self.metadata.target).unwrap_or_default(); + let file = std::str::from_utf8(&self.metadata.file).unwrap_or_default(); + let line = self.metadata.line; + let module_path = std::str::from_utf8(&self.metadata.module_path).unwrap_or_default(); + let params = self.fields; + let metadata : &tracing_core::metadata::Metadata<'static> = (&self.metadata).into(); + + tracing_core::Event::child_of( + self.parent_id.map(|i|tracing_core::span::Id::from_u64(i)), + &metadata, + &tracing::valueset!{ metadata.fields(), target, name, file, line, module_path, ?params } ) } } From a7c92bfe9d424e8fd34c83e2b8efc74c54aeedb5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 14 Sep 2020 11:53:53 +0200 Subject: [PATCH 107/113] fix indentation --- .../runtime-interface/proc-macro/src/lib.rs | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/primitives/runtime-interface/proc-macro/src/lib.rs b/primitives/runtime-interface/proc-macro/src/lib.rs index 356de234c502f..df43551398a12 100644 --- a/primitives/runtime-interface/proc-macro/src/lib.rs +++ b/primitives/runtime-interface/proc-macro/src/lib.rs @@ -34,69 +34,69 @@ mod runtime_interface; mod utils; struct Options { - wasm_only: bool, - tracing: bool + wasm_only: bool, + tracing: bool } impl Options { - fn unpack(self) -> (bool, bool) { - (self.wasm_only, self.tracing) - } + fn unpack(self) -> (bool, bool) { + (self.wasm_only, self.tracing) + } } impl Default for Options { - fn default() -> Self { - Options { wasm_only: false, tracing: true } - } + fn default() -> Self { + Options { wasm_only: false, tracing: true } + } } impl Parse for Options { - fn parse(input: ParseStream) -> Result { - let mut res = Self::default(); - while !input.is_empty() { - let lookahead = input.lookahead1(); - if lookahead.peek(runtime_interface::keywords::wasm_only) { - let _ = input.parse::(); - res.wasm_only = true; - } else if lookahead.peek(runtime_interface::keywords::no_tracing) { - let _ = input.parse::(); - res.tracing = false; - } else if lookahead.peek(Token![,]) { - let _ = input.parse::(); - } else { - return Err(lookahead.error()) - } - } - Ok(res) - } + fn parse(input: ParseStream) -> Result { + let mut res = Self::default(); + while !input.is_empty() { + let lookahead = input.lookahead1(); + if lookahead.peek(runtime_interface::keywords::wasm_only) { + let _ = input.parse::(); + res.wasm_only = true; + } else if lookahead.peek(runtime_interface::keywords::no_tracing) { + let _ = input.parse::(); + res.tracing = false; + } else if lookahead.peek(Token![,]) { + let _ = input.parse::(); + } else { + return Err(lookahead.error()) + } + } + Ok(res) + } } #[proc_macro_attribute] pub fn runtime_interface( - attrs: proc_macro::TokenStream, - input: proc_macro::TokenStream, + attrs: proc_macro::TokenStream, + input: proc_macro::TokenStream, ) -> proc_macro::TokenStream { - let trait_def = parse_macro_input!(input as ItemTrait); - let (wasm_only, tracing) = parse_macro_input!(attrs as Options).unpack(); + let trait_def = parse_macro_input!(input as ItemTrait); + let (wasm_only, tracing) = parse_macro_input!(attrs as Options).unpack(); - runtime_interface::runtime_interface_impl(trait_def, wasm_only, tracing) - .unwrap_or_else(|e| e.to_compile_error()) - .into() + runtime_interface::runtime_interface_impl(trait_def, wasm_only, tracing) + .unwrap_or_else(|e| e.to_compile_error()) + .into() } #[proc_macro_derive(PassByCodec)] pub fn pass_by_codec(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::codec_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() + let input = parse_macro_input!(input as DeriveInput); + pass_by::codec_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() } #[proc_macro_derive(PassByInner)] pub fn pass_by_inner(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::inner_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() + let input = parse_macro_input!(input as DeriveInput); + pass_by::inner_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() } #[proc_macro_derive(PassByEnum)] pub fn pass_by_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = parse_macro_input!(input as DeriveInput); - pass_by::enum_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() -} + let input = parse_macro_input!(input as DeriveInput); + pass_by::enum_derive_impl(input).unwrap_or_else(|e| e.to_compile_error()).into() +} \ No newline at end of file From c83834bf9d30359e6ee884dff5360d12a0512bd2 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 14 Sep 2020 11:57:08 +0200 Subject: [PATCH 108/113] remove commented lines --- bin/node-template/runtime/build.rs | 2 -- bin/node/runtime/build.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/bin/node-template/runtime/build.rs b/bin/node-template/runtime/build.rs index 3625b3a4ab591..52705043a2019 100644 --- a/bin/node-template/runtime/build.rs +++ b/bin/node-template/runtime/build.rs @@ -6,7 +6,5 @@ fn main() { .with_wasm_builder_from_crates("2.0.0") .export_heap_base() .import_memory() - // Uncomment the following to activate tracing in WASM - // .append_to_rust_flags("--cfg feature=\\\"with-tracing\\\"") .build() } diff --git a/bin/node/runtime/build.rs b/bin/node/runtime/build.rs index bb33bf5867412..a2f09a460e69d 100644 --- a/bin/node/runtime/build.rs +++ b/bin/node/runtime/build.rs @@ -23,7 +23,5 @@ fn main() { .with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder") .export_heap_base() .import_memory() - // Uncomment the following to enable wasm-based tracing - // .append_to_rust_flags("--cfg feature=\\\"with-tracing\\\"") .build() } From 5381565565aa55aba8f7ca8a2535c0d5ec1456f9 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 14 Sep 2020 13:27:39 +0200 Subject: [PATCH 109/113] bump all them tracing versions --- bin/node/cli/Cargo.toml | 2 +- client/executor/Cargo.toml | 2 +- client/service/Cargo.toml | 2 +- client/tracing/Cargo.toml | 2 +- primitives/io/Cargo.toml | 2 +- primitives/runtime-interface/test/Cargo.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 92f223427a710..11e0568179f37 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -43,7 +43,7 @@ jsonrpc-pubsub = "14.2.0" 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 diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index 0b9829e6f342b..73ea5d71d6d08 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -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" [features] default = [ "std" ] diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index b4ecd837d83a3..f98a9b89202bc 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -74,7 +74,7 @@ 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" } sp-tracing = { version = "2.0.0-rc6", path = "../../primitives/tracing" } -tracing = "0.1.18" +tracing = "0.1.19" parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 977acdfe84201..cadb4cf812719 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -19,7 +19,7 @@ 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-rc2", path = "../../primitives/tracing" } diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 69a0add85e10a..06672190e7fe3 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -28,7 +28,7 @@ sp-tracing = { version = "2.0.0-rc6", default-features = false, path = "../traci log = { version = "0.4.8", optional = true } futures = { version = "0.3.1", features = ["thread-pool"], optional = true } parking_lot = { version = "0.10.0", optional = true } -tracing = { version = "0.1.18", default-features = false } +tracing = { version = "0.1.19", default-features = false } tracing-core = { version = "0.1.15", default-features = false} [features] diff --git a/primitives/runtime-interface/test/Cargo.toml b/primitives/runtime-interface/test/Cargo.toml index 121035c27415e..eb916da245a19 100644 --- a/primitives/runtime-interface/test/Cargo.toml +++ b/primitives/runtime-interface/test/Cargo.toml @@ -20,5 +20,5 @@ sp-state-machine = { version = "0.8.0-rc6", path = "../../../primitives/state-ma sp-runtime = { version = "2.0.0-rc6", path = "../../runtime" } sp-core = { version = "2.0.0-rc6", path = "../../core" } sp-io = { version = "2.0.0-rc6", path = "../../io" } -tracing = "0.1.18" +tracing = "0.1.19" tracing-core = "0.1.15" From 6e4e60ac9f0d6c255cc2e697709fea55cefa3e11 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 12:31:38 +0200 Subject: [PATCH 110/113] cleaning up docs and info --- primitives/tracing/src/lib.rs | 13 ------------- primitives/tracing/src/types.rs | 2 ++ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/primitives/tracing/src/lib.rs b/primitives/tracing/src/lib.rs index ece8550c1b77e..fb074d5579c82 100644 --- a/primitives/tracing/src/lib.rs +++ b/primitives/tracing/src/lib.rs @@ -87,22 +87,9 @@ /// the default subscriber is doing nothing, so any spans or events happening before /// will not be recorded! /// -/// **Note**: The subscriber eventually handling the global subscriptions *must* -/// implement `clone_span` and do ref-counting on the spans alive properly. Because -/// the regular `span` is being dropped when crossing the wasm-barrier, this -/// implementation informs the subscriber with `clone_span` that they are keeping -/// around a reference and thus, if the references are tracked correctly, should -/// not exit the span when the outer, native span is dropped too early. mod types; -// #[cfg(not(feature = "std"))] -// #[macro_export] -// mod wasm_tracing; - -// #[cfg(not(feature = "std"))] -// pub use wasm_tracing::Span; - #[cfg(feature = "std")] use tracing; diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 8f6d603df85a2..2121386fba8ca 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -562,6 +562,8 @@ mod std_features { tracing_core::metadata::Kind::EVENT ); + // FIXME: this could be done a lot in 0.2 if they opt for using `Cow` instead + // https://github.com/tokio-rs/tracing/issues/922 impl From<&crate::WasmMetadata> for &'static tracing_core::Metadata<'static> { fn from(wm: &crate::WasmMetadata) -> &'static tracing_core::Metadata<'static> { match (&wm.level, wm.is_span) { From ed6ec093138810bbc4b684667b021327c6011a38 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 12:47:11 +0200 Subject: [PATCH 111/113] document new flag --- primitives/runtime-interface/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/primitives/runtime-interface/src/lib.rs b/primitives/runtime-interface/src/lib.rs index 562f94b278efc..2273e453f104a 100644 --- a/primitives/runtime-interface/src/lib.rs +++ b/primitives/runtime-interface/src/lib.rs @@ -284,6 +284,14 @@ pub use sp_std; /// 1. The generated functions are not callable from the native side. /// 2. The trait as shown above is not implemented for `Externalities` and is instead implemented /// for `FunctionExecutor` (from `sp-wasm-interface`). +/// +/// # Disable tracing +/// By addding `no_tracing` to the list of options you can prevent the wasm-side interface from +/// generating the default `sp-tracing`-calls. Note that this is rarely needed but only meant for +/// the case when that would create a circular dependency. You usually _do not_ want to add this +/// flag, as tracing doesn't cost you anything by default anyways (it is added as a no-op) but is +/// super useful for debugging later. +/// pub use sp_runtime_interface_proc_macro::runtime_interface; #[doc(hidden)] From 0c17fd1b22dfe13728dc9023d63aee52c6fced0d Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 14:00:12 +0200 Subject: [PATCH 112/113] the new layered system handles span cloning better --- client/executor/src/integration_tests/mod.rs | 2 +- client/tracing/src/lib.rs | 13 ++++++------- primitives/io/src/lib.rs | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 973df2cb56248..3ff676fdbe61f 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -692,7 +692,7 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) { let span_id = call_in_wasm( "test_enter_span", - &[], + Default::default(), wasm_method, &mut ext, ).unwrap(); diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index a313269f69d21..19db40c41b1d6 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -320,18 +320,13 @@ impl Layer for ProfilingLayer { fn on_exit(&self, span: &Id, _ctx: Context) { 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) { 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 + span_datum.overall_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) { @@ -348,6 +343,10 @@ impl Layer for ProfilingLayer { } }; } + + fn on_close(&self, span: Id, ctx: Context) { + self.on_exit(&span, ctx) + } } /// TraceHandler for sending span data to the logger diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index c063d81d5907d..8cb6f2df72819 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1088,7 +1088,6 @@ pub trait WasmTracing { tracing::dispatcher::get_default(|d| { let id = tracing_core::span::Id::from_u64(span); d.exit(&id); - d.try_close(id); }); } } From e616c8110cb45d1bf2e33593836c2631d3c0e17c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 17 Sep 2020 22:28:10 +0200 Subject: [PATCH 113/113] Apply suggestions from code review Co-authored-by: David --- client/tracing/src/lib.rs | 2 +- primitives/io/src/lib.rs | 32 ++++++++++--------- .../bare_function_interface.rs | 2 +- primitives/tracing/src/types.rs | 4 +-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 19db40c41b1d6..6690f283464ea 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -326,7 +326,7 @@ impl Layer for ProfilingLayer { }; if let Some(mut span_datum) = span_datum { - span_datum.overall_time = end_time - span_datum.start_time + span_datum.overall_time; + 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) { diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 8cb6f2df72819..2e7cb3e7efad9 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1035,18 +1035,18 @@ impl core::default::Default for Crossing } -/// Interface to providing tracing facilities for wasm. Modeled after tokios `tracing`-crate +/// Interface to provide tracing facilities for wasm. Modelled after tokios `tracing`-crate /// interfaces. See `sp-tracing` for more information. #[runtime_interface(wasm_only, no_tracing)] pub trait WasmTracing { - /// Given the crossing over `WasmMetadata`, return whether this should be handled or not. + /// Whether the span described in `WasmMetadata` should be traced wasm-side /// On the host converts into a static Metadata and checks against the global `tracing` dispatcher. /// /// When returning false the calling code should skip any tracing-related execution. In general - /// within the same block execution this is not expected to change and there doesn't have to be + /// within the same block execution this is not expected to change and it doesn't have to be /// checked more than once per metadata. This exists for optimisation purposes but is still not - /// cheap as it needs to jump the wasm-native-barrier, so caching the result wasm-side might be - /// a useful addition. + /// cheap as it will jump the wasm-native-barrier every time it is called. So an implementation might + /// chose to cache the result for the execution of the entire block. fn enabled(&mut self, metadata: Crossing) -> bool { let metadata: &tracing_core::metadata::Metadata<'static> = (&metadata.into_inner()).into(); tracing::dispatcher::get_default(|d| { @@ -1054,8 +1054,7 @@ pub trait WasmTracing { }) } - /// Open a new span with the given attributes. Return the u64 reference of the span. Where `0` - /// means no span was created or will be tracked. + /// Open a new span with the given attributes. Return the u64 Id of the span. /// /// On the native side this goes through the default `tracing` dispatcher to register the span /// and then calls `clone_span` with the ID to signal that we are keeping it around on the wasm- @@ -1083,7 +1082,7 @@ pub trait WasmTracing { } /// Signal that a given span-id has been exited. On native, this directly - /// proxies this to the global dispatcher. + /// proxies the span to the global dispatcher. fn exit(&mut self, span: u64) { tracing::dispatcher::get_default(|d| { let id = tracing_core::span::Id::from_u64(span); @@ -1106,7 +1105,7 @@ mod tracing_setup { /// The PassingTracingSubscriber implements `tracing_core::Subscriber` - /// and pushes the information accross the runtime interface to the host + /// and pushes the information across the runtime interface to the host struct PassingTracingSubsciber; impl tracing_core::Subscriber for PassingTracingSubsciber { @@ -1117,14 +1116,17 @@ mod tracing_setup { Id::from_u64(wasm_tracing::enter_span(Crossing(attrs.into()))) } fn enter(&self, span: &Id) { - // We are already entered in the API here - todo! {} + // Do nothing, we already entered the span previously } + /// Not implemented! We do not support recording values later + /// Will panic when used. fn record(&self, span: &Id, values: &Record<'_>) { - todo!{} + unimplemented!{} // this usage is not supported } + /// Not implemented! We do not support recording values later + /// Will panic when used. fn record_follows_from(&self, span: &Id, follows: &Id) { - todo!{ } + unimplemented!{ } // this usage is not supported } fn event(&self, event: &Event<'_>) { wasm_tracing::event(Crossing(event.into())) @@ -1136,8 +1138,8 @@ mod tracing_setup { /// Initialize tracing of sp_tracing on wasm with `with-tracing` enabled. - /// Can be called multiple times from within the same process will only - /// set the global bridgin subscriber once. + /// Can be called multiple times from within the same process and will only + /// set the global bridging subscriber once. pub fn init_tracing() { if TRACING_SET.load(Ordering::Relaxed) == false { set_global_default(Dispatch::new(PassingTracingSubsciber {})) diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs index e93548f7ae550..2725bd2c89ce5 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs @@ -169,7 +169,7 @@ fn function_std_impl( let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version")); // Don't make the function public accessible when this is a wasm only interface. let call_to_trait = generate_call_to_trait(trait_name, method, version, is_wasm_only); - let call_to_trait = if ! tracing { + let call_to_trait = if !tracing { call_to_trait } else { parse_quote!( diff --git a/primitives/tracing/src/types.rs b/primitives/tracing/src/types.rs index 2121386fba8ca..050ac4c314166 100644 --- a/primitives/tracing/src/types.rs +++ b/primitives/tracing/src/types.rs @@ -563,7 +563,7 @@ mod std_features { ); // FIXME: this could be done a lot in 0.2 if they opt for using `Cow` instead - // https://github.com/tokio-rs/tracing/issues/922 + // https://github.com/paritytech/substrate/issues/7134 impl From<&crate::WasmMetadata> for &'static tracing_core::Metadata<'static> { fn from(wm: &crate::WasmMetadata) -> &'static tracing_core::Metadata<'static> { match (&wm.level, wm.is_span) { @@ -620,4 +620,4 @@ mod std_features { } #[cfg(feature = "std")] -pub use std_features::*; \ No newline at end of file +pub use std_features::*;