-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[FRAME] Custom log level for the runtime benchmarks #8857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
451e0fe
[FRAME] Custom log level for the runtime benchmarks
ggwpez e51fe3c
undo wip changes
ggwpez 52a2ab9
Merge branch 'master' into oty-omni-bencher-custom-level
ggwpez f53d6bd
Fix instance space in filename
ggwpez 9f9136e
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] c66da5a
Beauty and clippy
ggwpez b2875c1
Merge remote-tracking branch 'origin/oty-omni-bencher-custom-level' i…
ggwpez 0b1b3c8
PRdoc
ggwpez e104a29
prdoc
ggwpez fda8e36
prdoc
ggwpez 07057d7
Update substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs
ggwpez 0f632a5
Merge branch 'master' into oty-omni-bencher-custom-level
ggwpez a859efb
Add Runtime log filtering
ggwpez 78b5fb5
Merge remote-tracking branch 'origin/master' into oty-omni-bencher-cu…
bkchr 581849a
Update from github-actions[bot] running command 'fmt'
github-actions[bot] 979df13
Merge branch 'master' into oty-omni-bencher-custom-level
bkontur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| title: "[FRAME] Custom log level for the runtime benchmarks" | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: |- | ||
| Changes: | ||
| - Add `--runtime-log` option to omni-bencher CLI | ||
| - Read env var `RUNTIME_LOG` as fallback to the `--runtime-log` option | ||
| - Set custom log level for runtime benchmarks that can be different form CLI level | ||
| - Fix issue where old runtimes have a space in the pallet or instance name from breaking change in `quote` macro | ||
| crates: | ||
| - name: frame-benchmarking-cli | ||
| bump: minor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
substrate/utils/frame/benchmarking-cli/src/pallet/logging.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 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. | ||
|
|
||
| use super::LOG_TARGET; | ||
| use sp_core::{LogLevelFilter, RuntimeInterfaceLogLevel}; | ||
| use sp_runtime_interface::{ | ||
| pass_by::{PassAs, PassFatPointerAndRead, ReturnAs}, | ||
| runtime_interface, | ||
| }; | ||
| use std::cell::OnceCell; | ||
|
|
||
| thread_local! { | ||
| /// Log level filter that the runtime will use. | ||
| /// | ||
| /// Must be initialized by the host before invoking the runtime executor. You may use `init` for | ||
| /// this or set it manually. The that can be set are either levels directly or filter like | ||
| // `warn,runtime=info`. | ||
| pub static RUNTIME_LOG: OnceCell<env_filter::Filter> = OnceCell::new(); | ||
| } | ||
|
|
||
| /// Init runtime logger with the following priority (high to low): | ||
| /// - CLI argument | ||
| /// - Environment variable | ||
| /// - Default logger settings | ||
| pub fn init(arg: Option<String>) { | ||
| let filter_str = arg.unwrap_or_else(|| { | ||
| if let Ok(env) = std::env::var("RUNTIME_LOG") { | ||
| env | ||
| } else { | ||
| log::max_level().to_string() | ||
| } | ||
| }); | ||
|
|
||
| let filter = env_filter::Builder::new() | ||
| .try_parse(&filter_str) | ||
| .expect("Invalid runtime log filter") | ||
| .build(); | ||
|
|
||
| RUNTIME_LOG.with(|cell| { | ||
| cell.set(filter).expect("Can be set by host"); | ||
| log::info!(target: LOG_TARGET, "Initialized runtime log filter to '{}'", filter_str); | ||
| }); | ||
| } | ||
|
|
||
| /// Alternative implementation to `sp_runtime_interface::logging::HostFunctions` for benchmarking. | ||
| #[runtime_interface] | ||
| pub trait Logging { | ||
| #[allow(dead_code)] | ||
| fn log( | ||
| level: PassAs<RuntimeInterfaceLogLevel, u8>, | ||
| target: PassFatPointerAndRead<&str>, | ||
| message: PassFatPointerAndRead<&[u8]>, | ||
| ) { | ||
| let Ok(message) = core::str::from_utf8(message) else { | ||
| log::error!(target: LOG_TARGET, "Runtime tried to log invalid UTF-8 data"); | ||
| return; | ||
| }; | ||
|
|
||
| let level = log::Level::from(level); | ||
| let metadata = log::MetadataBuilder::new().level(level).target(target).build(); | ||
|
|
||
| if RUNTIME_LOG.with(|filter| filter.get().expect("Must be set by host").enabled(&metadata)) | ||
| { | ||
| log::log!(target: target, level, "{}", message); | ||
| } | ||
| } | ||
|
|
||
| #[allow(dead_code)] | ||
| fn max_level() -> ReturnAs<LogLevelFilter, u8> { | ||
| RUNTIME_LOG | ||
| // .filter() gives us the max level of this filter | ||
| .with(|filter| filter.get().expect("Must be set by host").filter()) | ||
| .into() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you tried this? From the code, it seems that
FromStrforLevelFilteris only for parsingDebugetc and notsomething=debug?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it now to be a filter in the last commit a859efb
Not sure if its worth the additional complexity though, since I only added this feature to turn the annoying logs off 😆
Also the runtime filter can never have a level greater than the node filter, since it is still limited by that.