Unverified Commit ccd76872 authored by ticki's avatar ticki

Enable optional stacktraces for `conc` debug mode.

parent 20644013
......@@ -13,3 +13,10 @@ exclude = ["target", "Cargo.lock"]
lazy_static = "0.2"
rand = "0.3"
spin = "0.4"
[dependencies.backtrace]
version = "0.3"
optional = true
[features]
debug-tools = ["backtrace"]
//! Runtime debugging tools.
#[cfg(feature = "debug-tools")]
extern crate backtrace;
/// Execute closure when the environment variable, `CONC_DEBUG_MODE`, is set.
///
/// When compiled in release mode, this is a NOP.
#[cfg(debug_assertions)]
#[cfg(feature = "debug-tools")]
pub fn exec<F: FnOnce()>(f: F) {
use self::backtrace::Backtrace;
use std::env;
thread_local! {
/// Is `CONC_DEBUG_MODE` set?
///
/// This is cached to avoid expensive repeated syscalls or similar things.
static IS_ENABLED: bool = env::var("CONC_DEBUG_MODE").is_ok();
static DEBUG_MODE_ENABLED: bool = env::var("CONC_DEBUG_MODE").is_ok();
/// Is `CONC_DEBUG_STACKTRACE` set?
///
/// This is cached to avoid expensive repeated syscalls or similar things.
static STACK_TRACE_ENABLED: bool = env::var("CONC_DEBUG_STACKTRACE").is_ok();
}
// If enabled, run the closure.
if IS_ENABLED.with(|&x| x) {
if DEBUG_MODE_ENABLED.with(|&x| x) {
f();
if STACK_TRACE_ENABLED.with(|&x| x) {
println!("{:?}", Backtrace::new());
}
}
}
......@@ -25,5 +36,5 @@ pub fn exec<F: FnOnce()>(f: F) {
/// When compiled in debug mode, this will execute the closure when envvar `CONC_DEBUG_MODE` is
/// set.
#[inline]
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "debug-tools"))]
pub fn exec<F: FnOnce()>(_: F) {}
......@@ -35,7 +35,9 @@
//!
//! ### Debugging
//!
//! Set `CONC_DEBUG_MODE`. For example, `CONC_DEBUG_MODE=1 cargo test`.
//! Enable feature `debug-tools` and set environment variable `CONC_DEBUG_MODE`. For example,
//! `CONC_DEBUG_MODE=1 cargo test --features debug-tools`. To get stacktraces after each message,
//! set environment variable `CONC_DEBUG_STACKTRACE`.
//!
//! ## Why not crossbeam/epochs?
//!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment