mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Dont output logs when benchmarking
In 11ab302087
we accidentally removed
the `not(ldk_bench)` bound before outputting logs to stderr, which
we restore here. Instead of simply ignoring logs in benchmarks,
which we did previously, we instead format logs (in a way that LLVM
will not optimize out).
This commit is contained in:
parent
cdcab1ce1b
commit
ac4815abb6
1 changed files with 19 additions and 4 deletions
|
@ -1174,10 +1174,25 @@ impl TestLogger {
|
|||
|
||||
impl Logger for TestLogger {
|
||||
fn log(&self, record: Record) {
|
||||
*self.lines.lock().unwrap().entry((record.module_path, format!("{}", record.args))).or_insert(0) += 1;
|
||||
*self.context.lock().unwrap().entry((record.module_path, record.peer_id, record.channel_id)).or_insert(0) += 1;
|
||||
let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line);
|
||||
println!("{:<55}{}", pfx, record.args);
|
||||
let s = format!("{:<55} {}",
|
||||
format_args!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line),
|
||||
record.args
|
||||
);
|
||||
#[cfg(ldk_bench)] {
|
||||
// When benchmarking, we don't actually want to print logs, but we do want to format
|
||||
// them. To make sure LLVM doesn't skip the above entirely we push it through a
|
||||
// volitile read. This may not be super fast, but it shouldn't be worse than anything a
|
||||
// user actually does with a log
|
||||
let s_bytes = s.as_bytes();
|
||||
for i in 0..s.len() {
|
||||
let _ = unsafe { core::ptr::read_volatile(&s_bytes[i]) };
|
||||
}
|
||||
}
|
||||
#[cfg(not(ldk_bench))] {
|
||||
*self.lines.lock().unwrap().entry((record.module_path, format!("{}", record.args))).or_insert(0) += 1;
|
||||
*self.context.lock().unwrap().entry((record.module_path, record.peer_id, record.channel_id)).or_insert(0) += 1;
|
||||
println!("{}", s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue