Hi Everyone
I am encountering an issue where none of the printing statements seem to work within canbench
bench functions. I have tried the following:
eprintln!("Error occurred: {:?}", error);
ic_cdk::println!("Starting register_user benchmark");
println!("Starting register_user benchmark");
However, none of these statements produce any output in the logs or the debug console. Could you please help me understand why this is happening and suggest a way to enable logging or debugging for bench functions in canbench
?
here is a simple bench function
#[bench]
fn process_numbers_bench() {
ic_cdk::println!("Benchmark started..");
let count = 10_000;
let result = process_numbers(count);
ic_cdk::println!("Benchmark result: {:?}", result);
}
1 Like
canbench currently hides all output from the canister and only outputs its own report with the benchmarking results. Can you elaborate on your use-case?
1 Like
Actually, I think @ielashiās information might be outdated. There was a PR some time ago that added an option to allow the output of canisters to be exposed if needed. I think if you use canbench 0.1.8 and above it should allow you to get the logs.
2 Likes
Is this documented somewhere? It not, would it make sense to add it to make it easy for people to find it? I wonder if exposing it as an explicit arg to canbench would be clearer than setting an environment variable.
1 Like
Yeah I think we should document it for easier access.
I think we just went with the easiest change back then. I donāt know if an explicit arg is that much better, as long as things are documented it should be fine. The only marginal benefit I find is that the help message of canbench could be self-documentation if we used an explicit arg.
Exactly, I see that as a big benefit, as then it becomes easier to discover such features.
I noticed that the GitHub PR contains code that hasnāt been documented for use in projects yet. Iām currently in the middle of my project and need to integrate that function. Would it be possible to share the implementation of that specific function for now, so I can use it in my codebase?
Hey folks,
Iām planning to add a āDebuggingā section to the documentation for better clarity.
Also, what if we enable ic_cdk::println!
output by default, and suppress it with canbench --less-verbose
? What do you think?
1 Like
I would be in favor of not enabling it by default, since it would be make the output of the reports less readable (the println output would be inter-mixed with the canbench output). Iām not still not clear on what the benefit of this output would be. Benchmarks are not tests that you debug. Am I missing something?
1 Like
I thought the purpose of canbench --less-verbose
was to produce a very readable reportā¦ Ok, so we add a --show-canister-output
option to enable the output then?
On second thought, I agree with your original suggestion (I totally forgot we already have the less-verbose
option), so enabling logs by default makes sense in that case.
1 Like
My personal opinion is that if we enable logs by default it could be quite noisy and usually when people run canbench
theyāre interested in the benchmark results (canbench is first and foremost a benchmarking not a debugging tool), so it makes sense for the tool to output only that by default. I would go with the default we have now and add an option to allow showing more logs for anyone whoās interested.
1 Like
Hey Vicky,
Itās implemented and released in canbench v0.1.11. Now, both ic_cdk::println!()
and ic_cdk::eprintln!()
will appear in the console when canbench is run with the --show-canister-output
argument.
1 Like
hey @berestovskyy ,
Thank you for the update! I appreciate the implementation in canbench v0.1.11. The addition of ic_cdk::println!()
and ic_cdk::eprintln!()
to the console output with --show-canister-output
is really helpful.
Apologies for the delayed responseāI had moved on to another task and saw your message today. Thanks again for addressing this!
1 Like