mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 06:31:09 +00:00
Improve tracing (#5698)
* Improve tracing implementation * Enable tracing in runtime interfaces * Switch to `TRACE` level
This commit is contained in:
@@ -19,6 +19,7 @@ frame-metadata = { version = "11.0.0-dev", default-features = false, path = "../
|
||||
sp-std = { version = "2.0.0-dev", default-features = false, path = "../../primitives/std" }
|
||||
sp-io = { version = "2.0.0-dev", default-features = false, path = "../../primitives/io" }
|
||||
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../primitives/runtime" }
|
||||
sp-tracing = { version = "2.0.0-dev", default-features = false, path = "../../primitives/tracing" }
|
||||
sp-core = { version = "2.0.0-dev", default-features = false, path = "../../primitives/core" }
|
||||
sp-arithmetic = { version = "2.0.0-dev", default-features = false, path = "../../primitives/arithmetic" }
|
||||
sp-inherents = { version = "2.0.0-dev", default-features = false, path = "../../primitives/inherents" }
|
||||
@@ -28,7 +29,6 @@ once_cell = { version = "1", default-features = false, optional = true }
|
||||
sp-state-machine = { version = "0.8.0-dev", optional = true, path = "../../primitives/state-machine" }
|
||||
bitmask = { version = "0.5.0", default-features = false }
|
||||
impl-trait-for-tuples = "0.1.3"
|
||||
tracing = { version = "0.1.10", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
@@ -37,7 +37,6 @@ frame-system = { version = "2.0.0-dev", path = "../system" }
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"tracing",
|
||||
"once_cell",
|
||||
"bitmask/std",
|
||||
"serde",
|
||||
@@ -45,6 +44,7 @@ std = [
|
||||
"codec/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"sp-tracing/std",
|
||||
"sp-arithmetic/std",
|
||||
"frame-metadata/std",
|
||||
"sp-inherents/std",
|
||||
|
||||
@@ -1030,12 +1030,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 {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "on_initialize");
|
||||
let _enter = span.enter();
|
||||
}
|
||||
$crate::sp_tracing::enter_span!("on_initialize");
|
||||
{ $( $impl )* }
|
||||
}
|
||||
}
|
||||
@@ -1051,12 +1046,7 @@ macro_rules! decl_module {
|
||||
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_initialize($param: $param_ty) -> $return {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "on_initialize");
|
||||
let _enter = span.enter();
|
||||
}
|
||||
$crate::sp_tracing::enter_span!("on_initialize");
|
||||
{ $( $impl )* }
|
||||
}
|
||||
}
|
||||
@@ -1082,12 +1072,7 @@ macro_rules! decl_module {
|
||||
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_runtime_upgrade() -> $return {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "on_runtime_upgrade");
|
||||
let _enter = span.enter();
|
||||
}
|
||||
$crate::sp_tracing::enter_span!("on_runtime_upgrade");
|
||||
{ $( $impl )* }
|
||||
}
|
||||
}
|
||||
@@ -1114,12 +1099,7 @@ macro_rules! decl_module {
|
||||
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "on_finalize");
|
||||
let _enter = span.enter();
|
||||
}
|
||||
$crate::sp_tracing::enter_span!("on_finalize");
|
||||
{ $( $impl )* }
|
||||
}
|
||||
}
|
||||
@@ -1135,12 +1115,7 @@ macro_rules! decl_module {
|
||||
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_finalize($param: $param_ty) {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "on_finalize");
|
||||
let _enter = span.enter();
|
||||
}
|
||||
$crate::sp_tracing::enter_span!("on_finalize");
|
||||
{ $( $impl )* }
|
||||
}
|
||||
}
|
||||
@@ -1209,15 +1184,9 @@ macro_rules! decl_module {
|
||||
$vis fn $name(
|
||||
$origin: $origin_ty $(, $param: $param_ty )*
|
||||
) -> $crate::dispatch::DispatchResult {
|
||||
$crate::sp_std::if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, stringify!($name));
|
||||
let _enter = span.enter();
|
||||
}
|
||||
{
|
||||
{ $( $impl )* }
|
||||
Ok(())
|
||||
}
|
||||
$crate::sp_tracing::enter_span!(stringify!($name));
|
||||
{ $( $impl )* }
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1234,13 +1203,8 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
$(#[doc = $doc_attr])*
|
||||
$vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result {
|
||||
use $crate::sp_std::if_std;
|
||||
if_std! {
|
||||
use $crate::tracing;
|
||||
let span = tracing::span!(tracing::Level::DEBUG, stringify!($name));
|
||||
let _enter = span.enter();
|
||||
}
|
||||
{ $( $impl )* }
|
||||
$crate::sp_tracing::enter_span!(stringify!($name));
|
||||
$( $impl )*
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -23,8 +23,9 @@ extern crate self as frame_support;
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitmask;
|
||||
#[cfg(feature = "std")]
|
||||
pub extern crate tracing;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use sp_tracing;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use serde;
|
||||
@@ -222,38 +223,6 @@ macro_rules! assert_ok {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs given code within a tracing span, measuring it's execution time.
|
||||
///
|
||||
/// Has effect only when running in native environment. In WASM, it simply inserts the
|
||||
/// code in-place, without any metrics added.
|
||||
#[macro_export]
|
||||
macro_rules! tracing_span {
|
||||
($name:expr; $( $code:tt )*) => {
|
||||
let span = $crate::if_tracing!(
|
||||
$crate::tracing::span!($crate::tracing::Level::TRACE, $name)
|
||||
,
|
||||
()
|
||||
);
|
||||
let guard = $crate::if_tracing!(span.enter(), ());
|
||||
$( $code )*
|
||||
|
||||
$crate::sp_std::mem::drop(guard);
|
||||
$crate::sp_std::mem::drop(span);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[cfg(feature = "tracing")]
|
||||
macro_rules! if_tracing {
|
||||
( $if:expr, $else:expr ) => {{ $if }}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "tracing"))]
|
||||
macro_rules! if_tracing {
|
||||
( $if:expr, $else:expr ) => {{ $else }}
|
||||
}
|
||||
|
||||
/// The void type - it cannot exist.
|
||||
// Oh rust, you crack me up...
|
||||
#[derive(Clone, Eq, PartialEq, RuntimeDebug)]
|
||||
|
||||
Reference in New Issue
Block a user