From 0654d6096ce501125ad0b43cbd3366b8bb6d4896 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 9 Mar 2021 23:22:47 +0100 Subject: [PATCH 1/4] span in hooks --- frame/support/procedural/src/pallet/expand/hooks.rs | 10 ++++++++++ frame/support/src/lib.rs | 2 ++ 2 files changed, 12 insertions(+) diff --git a/frame/support/procedural/src/pallet/expand/hooks.rs b/frame/support/procedural/src/pallet/expand/hooks.rs index d55a74209d053..b0323d41714e4 100644 --- a/frame/support/procedural/src/pallet/expand/hooks.rs +++ b/frame/support/procedural/src/pallet/expand/hooks.rs @@ -55,6 +55,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { for #pallet_ident<#type_use_gen> #where_clause { fn on_finalize(n: ::BlockNumber) { + #frame_support::sp_tracing::enter_span!( + #frame_support::sp_tracing::trace_span!("on_finalize") + ); < Self as #frame_support::traits::Hooks< ::BlockNumber @@ -70,6 +73,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { fn on_initialize( n: ::BlockNumber ) -> #frame_support::weights::Weight { + #frame_support::sp_tracing::enter_span!( + #frame_support::sp_tracing::trace_span!("on_initialize") + ); < Self as #frame_support::traits::Hooks< ::BlockNumber @@ -83,6 +89,10 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { for #pallet_ident<#type_use_gen> #where_clause { fn on_runtime_upgrade() -> #frame_support::weights::Weight { + #frame_support::sp_tracing::enter_span!( + #frame_support::sp_tracing::trace_span!("on_runtime_update") + ); + // log info about the upgrade. let new_storage_version = #frame_support::crate_to_pallet_version!(); let pallet_name = < diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 3c3fc20a530d1..8c0107cc658b6 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1229,6 +1229,8 @@ pub mod pallet_prelude { /// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional /// logic. E.g. logic to write pallet version into storage. /// +/// NOTE: The macro also add some tracing logic when implementing above traits. +/// /// # Call: `#[pallet::call]` mandatory /// /// Implementation of pallet dispatchables. From 007d0ff7c1f3b50c71a4e4f74df0e53f4c5028bb Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 9 Mar 2021 23:34:35 +0100 Subject: [PATCH 2/4] add span for dispatchable --- frame/support/procedural/src/pallet/expand/call.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 137e055405a38..295cf14d37f04 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -162,9 +162,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { ) -> #frame_support::dispatch::DispatchResultWithPostInfo { match self { #( - Self::#fn_name( #( #args_name, )* ) => + Self::#fn_name( #( #args_name, )* ) => { + #frame_support::sp_tracing::enter_span!( + #frame_support::sp_tracing::trace_span!(stringify!(#fn_name)) + ); <#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* ) - .map(Into::into).map_err(Into::into), + .map(Into::into).map_err(Into::into) + }, )* Self::__Ignore(_, _) => { let _ = origin; // Use origin for empty Call enum From cad32b4cd3240fc4a32657a9e6e0063f20c30705 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 15 Mar 2021 17:21:33 -0400 Subject: [PATCH 3/4] Update frame/support/src/lib.rs --- frame/support/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 8c0107cc658b6..68d6d4db69f19 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1229,7 +1229,7 @@ pub mod pallet_prelude { /// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional /// logic. E.g. logic to write pallet version into storage. /// -/// NOTE: The macro also add some tracing logic when implementing above traits. +/// NOTE: The macro also adds some tracing logic when implementing the above traits. /// /// # Call: `#[pallet::call]` mandatory /// From 79e47653dbe712fa6905c7cc3e687ca25b353b16 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Tue, 16 Mar 2021 17:34:04 +0100 Subject: [PATCH 4/4] Update frame/support/src/lib.rs Co-authored-by: David --- frame/support/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 790297dffac01..220e7a06bdf31 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1229,7 +1229,8 @@ pub mod pallet_prelude { /// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional /// logic. E.g. logic to write pallet version into storage. /// -/// NOTE: The macro also adds some tracing logic when implementing the above traits. +/// NOTE: The macro also adds some tracing logic when implementing the above traits. The following +/// hooks emit traces: `on_initialize`, `on_finalize` and `on_runtime_upgrade`. /// /// # Call: `#[pallet::call]` mandatory ///