pub struct CallTraceConfig {
pub enabled: bool,
pub capture_arguments: bool,
pub output_file: Option<String>,
pub max_call_depth: usize,
pub pretty_json: bool,
}Expand description
CallTrace runtime configuration
This structure holds all configuration options that control CallTrace behavior. Configuration is typically loaded from environment variables during initialization, but can be modified programmatically if needed.
§Configuration Sources
- Environment Variables (primary source, read at startup)
- Default Values (fallback when environment variables are not set)
- Programmatic (can be modified via unsafe access to CONFIG static)
§Fields
§enabled: bool
Master enable/disable switch for all tracing functionality.
- Environment:
CALLTRACE_ENABLED(1/true to enable) - Default:
true - Performance Impact: When disabled, overhead is <5ns per function call
§capture_arguments: bool
Enable expensive argument capture using DWARF debugging information.
- Environment:
CALLTRACE_CAPTURE_ARGS(1/true to enable) - Default:
false - Performance Impact: 10-50x overhead when enabled, depending on argument complexity
- Requirements: Target program must be compiled with
-gflag
§output_file: Option<String>
Path where JSON trace output will be written.
- Environment:
CALLTRACE_OUTPUT - Default:
{executable_name}.jsonin the same directory as the executable - Special Values:
None: No output generated"stderr": Output to stderr (not implemented)"stdout": Output to stdout (not implemented)
§max_call_depth: usize
Maximum depth of function call nesting to trace.
- Environment:
CALLTRACE_MAX_DEPTH - Default:
100 - Purpose: Prevents infinite recursion and limits memory usage
- Behavior: Calls deeper than this limit are ignored
§pretty_json: bool
Whether to format JSON output with indentation and newlines.
- Environment:
CALLTRACE_PRETTY_JSON(1/true to enable) - Default:
true - Trade-off: Readable output vs. smaller file size
§Examples
§Reading Current Configuration
// Note: This requires unsafe access to the CONFIG static
use calltrace::CallTraceConfig;
// This is how configuration is accessed internally
// (Not recommended for external use)§Environment Variable Configuration
# Minimal configuration - basic tracing only
CALLTRACE_OUTPUT=trace.json ./your_program
# Full featured configuration
CALLTRACE_OUTPUT=full_trace.json \
CALLTRACE_CAPTURE_ARGS=1 \
CALLTRACE_MAX_DEPTH=50 \
CALLTRACE_DEBUG=1 \
CALLTRACE_PRETTY_JSON=1 \
./your_program
# Performance-optimized configuration
CALLTRACE_OUTPUT=perf_trace.json \
CALLTRACE_CAPTURE_ARGS=0 \
CALLTRACE_MAX_DEPTH=200 \
CALLTRACE_PRETTY_JSON=0 \
./your_program§Performance Guidelines
- Production: Set
capture_arguments = falsefor minimal overhead - Development: Enable
capture_arguments = truefor detailed debugging - Deep Recursion: Increase
max_call_depthif needed, but monitor memory usage - File Size: Set
pretty_json = falsefor smaller output files
§Thread Safety
Configuration is read once during initialization and then considered immutable. All fields can be safely accessed concurrently from multiple threads.
Fields§
§enabled: bool§capture_arguments: bool§output_file: Option<String>§max_call_depth: usize§pretty_json: boolTrait Implementations§
Source§impl Clone for CallTraceConfig
impl Clone for CallTraceConfig
Source§fn clone(&self) -> CallTraceConfig
fn clone(&self) -> CallTraceConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CallTraceConfig
impl Debug for CallTraceConfig
Auto Trait Implementations§
impl Freeze for CallTraceConfig
impl RefUnwindSafe for CallTraceConfig
impl Send for CallTraceConfig
impl Sync for CallTraceConfig
impl Unpin for CallTraceConfig
impl UnsafeUnpin for CallTraceConfig
impl UnwindSafe for CallTraceConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more