Skip to main content

CallTraceConfig

Struct CallTraceConfig 

Source
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

  1. Environment Variables (primary source, read at startup)
  2. Default Values (fallback when environment variables are not set)
  3. 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 -g flag

§output_file: Option<String>

Path where JSON trace output will be written.

  • Environment: CALLTRACE_OUTPUT
  • Default: {executable_name}.json in 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 = false for minimal overhead
  • Development: Enable capture_arguments = true for detailed debugging
  • Deep Recursion: Increase max_call_depth if needed, but monitor memory usage
  • File Size: Set pretty_json = false for 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: bool

Trait Implementations§

Source§

impl Clone for CallTraceConfig

Source§

fn clone(&self) -> CallTraceConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CallTraceConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CallTraceConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.