Skip to main content

Overview

Z3 provides detailed statistics about solver execution, including conflict counts, decision counts, memory usage, and theory-specific metrics. These statistics are essential for performance analysis, debugging, and optimization.

Collecting Statistics

Basic Statistics Retrieval

Reading Statistics

Iterating Through All Statistics

Formatted Statistics Output

Example output:

Key Statistics Categories

Core Solver Statistics

Memory Statistics

Resource Limits

Theory-Specific Statistics

SAT Solver Statistics

Arithmetic Theory Statistics

Array Theory Statistics

Performance Analysis

Identifying Bottlenecks

Comparing Solver Configurations

Global Memory Statistics

Estimated Allocation Size

This function returns an estimate of total memory allocated by Z3, useful for monitoring memory consumption across multiple solvers and contexts.

Best Practices

When to Collect Statistics

Collect statistics to:
  • Profile solver performance on benchmarks
  • Debug timeout or memory issues
  • Compare different solving strategies
  • Monitor production system health
  • Identify theory-specific bottlenecks

Interpreting Statistics

  1. High conflict count: Problem is complex, consider preprocessing or simplification
  2. Low decision count: Problem is easy or well-structured
  3. High restart count: SAT solver is struggling, try different restart strategies
  4. Memory growth: Problem size is large, consider incremental solving or memory limits
  5. Long solving time with low conflicts: Theory solver may be slow, try different theory options

Statistical Logging

Common Statistics Keys

Universal Statistics

  • time - Total solving time in seconds
  • memory - Current memory usage in MB
  • max-memory - Peak memory usage in MB
  • rlimit-count - Resource limit counter
  • num-allocs - Number of allocations

SAT Statistics

  • conflicts - Number of conflicts
  • decisions - Number of decisions
  • propagations - Number of propagations
  • restarts - Number of restarts
  • mk-bool-var - Boolean variables created

Theory Statistics

  • arith-conflicts - Arithmetic conflicts
  • arith-bound-propagations - Bound propagations
  • array-axiom1 - Array select-store axioms
  • bv-conflicts - Bit-vector conflicts

API Reference

Statistics Management

  • Z3_solver_get_statistics - Get statistics from solver (api_solver.cpp:789)
  • Z3_stats_inc_ref - Increment reference counter (api_stats.cpp:39)
  • Z3_stats_dec_ref - Decrement reference counter (api_stats.cpp:47)
  • Z3_stats_to_string - Convert to string (api_stats.cpp:25)

Reading Statistics

  • Z3_stats_size - Get number of statistics (api_stats.cpp:56)
  • Z3_stats_get_key - Get statistic key name (api_stats.cpp:64)
  • Z3_stats_is_uint - Check if unsigned integer (api_stats.cpp:76)
  • Z3_stats_is_double - Check if double (api_stats.cpp:88)
  • Z3_stats_get_uint_value - Get unsigned value (api_stats.cpp:100)
  • Z3_stats_get_double_value - Get double value (api_stats.cpp:116)

Global Statistics

  • Z3_get_estimated_alloc_size - Get global memory estimate (api_stats.cpp:132)

See Also