eyre/examples/debug_perf.rs
Jane Lusby 9e6a349c8e
port color-eyre to new eyre with global hook (#29)
* port color-eyre to new eyre with global hook

* add a singular hook configuration

* add panic handler to globally installed hook

* getting near the end

* remove unused module

* temp: working on capture consistency

* walk back changes that make porting to new release harder

* merge main into hooked

* switch to github color-spantrace and copy from htmlgit status

* move spantrace capture default mode into hook

* rename and reorg section stuff

* switch to released deps

* copy changes from lib.rs to readme

* update snippets and revert to images for readme

* remove extremely fragile format tests
2020-07-05 19:22:57 -07:00

57 lines
1.3 KiB
Rust

//! example for manually testing the perf of color-eyre in debug vs release
use color_eyre::{
eyre::Report,
eyre::{eyre, WrapErr},
Section,
};
use tracing::instrument;
fn main() -> Result<(), Report> {
#[cfg(feature = "capture-spantrace")]
install_tracing();
color_eyre::install()?;
time_report();
Ok(())
}
#[instrument]
fn time_report() {
time_report_inner()
}
#[instrument]
fn time_report_inner() {
let start = std::time::Instant::now();
let report = Err::<(), Report>(eyre!("fake error"))
.wrap_err("wrapped error")
.suggestion("try using a file that exists next time")
.unwrap_err();
println!("Error: {:?}", report);
drop(report);
let end = std::time::Instant::now();
dbg!(end - start);
}
#[cfg(feature = "capture-spantrace")]
fn install_tracing() {
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};
let fmt_layer = fmt::layer().with_target(false);
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.with(ErrorLayer::default())
.init();
}