From 545ac4cf5083308a6c815c2779c8110b22a05550 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Fri, 4 Mar 2022 20:20:19 +0000 Subject: [PATCH] add block usage logs to system pallet (#10940) * add block usage logs to system pallet * add Debug * use % instead of default Debug impl * change formatting * revert --- substrate/frame/system/src/lib.rs | 34 +++++++++++++++++++ .../primitives/arithmetic/src/per_things.rs | 7 ++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 3b4de0c472..9b30e7b452 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -1272,6 +1272,40 @@ impl Pallet { /// Remove temporary "environment" entries in storage, compute the storage root and return the /// resulting header for this block. pub fn finalize() -> T::Header { + log::debug!( + target: "runtime::system", + "[{:?}] length: {} (normal {}%, op: {}%, mandatory {}%) / normal weight: {} ({}%) \ + / op weight {} ({}%) / mandatory weight {} ({}%)", + Self::block_number(), + Self::all_extrinsics_len(), + sp_runtime::Percent::from_rational( + Self::all_extrinsics_len(), + *T::BlockLength::get().max.get(DispatchClass::Normal) + ).deconstruct(), + sp_runtime::Percent::from_rational( + Self::all_extrinsics_len(), + *T::BlockLength::get().max.get(DispatchClass::Operational) + ).deconstruct(), + sp_runtime::Percent::from_rational( + Self::all_extrinsics_len(), + *T::BlockLength::get().max.get(DispatchClass::Mandatory) + ).deconstruct(), + Self::block_weight().get(DispatchClass::Normal), + sp_runtime::Percent::from_rational( + *Self::block_weight().get(DispatchClass::Normal), + T::BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap_or(Bounded::max_value()) + ).deconstruct(), + Self::block_weight().get(DispatchClass::Operational), + sp_runtime::Percent::from_rational( + *Self::block_weight().get(DispatchClass::Operational), + T::BlockWeights::get().get(DispatchClass::Operational).max_total.unwrap_or(Bounded::max_value()) + ).deconstruct(), + Self::block_weight().get(DispatchClass::Mandatory), + sp_runtime::Percent::from_rational( + *Self::block_weight().get(DispatchClass::Mandatory), + T::BlockWeights::get().get(DispatchClass::Mandatory).max_total.unwrap_or(Bounded::max_value()) + ).deconstruct(), + ); ExecutionPhase::::kill(); AllExtrinsicsLen::::kill(); diff --git a/substrate/primitives/arithmetic/src/per_things.rs b/substrate/primitives/arithmetic/src/per_things.rs index fbd45bb693..c3ccca56ca 100644 --- a/substrate/primitives/arithmetic/src/per_things.rs +++ b/substrate/primitives/arithmetic/src/per_things.rs @@ -24,7 +24,6 @@ use crate::traits::{ }; use codec::{CompactAs, Encode}; use num_traits::{Pow, SaturatingAdd, SaturatingSub}; -use sp_debug_derive::RuntimeDebug; use sp_std::{ convert::{TryFrom, TryInto}, fmt, ops, @@ -425,7 +424,7 @@ macro_rules! implement_per_thing { /// #[doc = $title] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive(Encode, Copy, Clone, PartialEq, Eq, codec::MaxEncodedLen, PartialOrd, Ord, RuntimeDebug, scale_info::TypeInfo)] + #[derive(Encode, Copy, Clone, PartialEq, Eq, codec::MaxEncodedLen, PartialOrd, Ord, sp_std::fmt::Debug, scale_info::TypeInfo)] pub struct $name($type); /// Implementation makes any compact encoding of `PerThing::Inner` valid, @@ -847,7 +846,7 @@ macro_rules! implement_per_thing { #[cfg(test)] mod $test_mod { use codec::{Encode, Decode}; - use super::{$name, Saturating, RuntimeDebug, PerThing}; + use super::{$name, Saturating, PerThing}; use crate::traits::Zero; #[test] @@ -871,7 +870,7 @@ macro_rules! implement_per_thing { assert!(<$upper_type>::from($max) * <$upper_type>::from($max) < <$upper_type>::max_value()); } - #[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)] + #[derive(Encode, Decode, PartialEq, Eq, Debug)] struct WithCompact { data: T, }