8

I am implementing benchmark to calculate weight in my pallet and need to print some data I was trying to use if_std println! but got nothing. What the best way to make printouts for debugging benchmarks.rs?

benchmarks! {
    create_xyz {
        let index = <NextXYZIndex<T>>::get();
        println!("index:{}", index);
        let caller: T::AccountId = whitelisted_caller();
    }: _(RawOrigin::Signed(caller), index)
}
3
  • 2
    You want to log from the extrinsic that your benchmark calls or from the benchmarks! closure? Mar 21, 2022 at 15:47
  • Please add more details and context - what are you trying to do and why? This can help us help you :)
    – Nuke
    Mar 21, 2022 at 15:54
  • added code sample Mar 21, 2022 at 16:47

2 Answers 2

8

You can use the info! macro or similar from frame_support::log as such:

use frame_support::log::info;

benchmarks! {
    something {

        info!("Logging works!");

    }: _(args...)
}

This is only helpful for debugging though.

7

I would probably not put logs in your production benchmarks, but if you are trying to debug things, you can add a println! statement and then run the benchmark tests:

cargo test -p pallet-name --features runtime-benchmarks

This will work as long as you have included the:

impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.