use crate::TheoryConstraint;
#[cfg(feature = "profiling")]
mod imp {
use super::TheoryConstraint;
use std::time::{Duration, Instant};
pub(crate) type Timer = Instant;
#[derive(Clone, Copy)]
pub(crate) enum TheoryKind {
Lra,
Enum,
Other,
}
impl TheoryKind {
#[inline]
pub(crate) fn of(c: &TheoryConstraint) -> Self {
match c {
TheoryConstraint::LraLb(..) | TheoryConstraint::LraUb(..) => Self::Lra,
TheoryConstraint::EnumEq(..) => Self::Enum,
_ => Self::Other,
}
}
}
#[derive(Default)]
pub(crate) struct SmtProf {
prop_calls: usize,
sat_conflicts: usize,
lra_bound_conflicts: usize,
lra_check_conflicts: usize,
enum_conflicts: usize,
t_sat_prop: Duration,
t_lra_bound: Duration,
t_enum: Duration,
t_lra_check: Duration,
t_analyze: Duration,
t_cancel: Duration,
}
impl SmtProf {
#[inline(always)]
pub(crate) fn start() -> Timer {
Instant::now()
}
#[inline(always)]
pub(crate) fn on_prop_call(&mut self) {
self.prop_calls += 1;
}
#[inline(always)]
pub(crate) fn stop_sat_prop(&mut self, t: Timer) {
self.t_sat_prop += t.elapsed();
}
#[inline(always)]
pub(crate) fn on_sat_conflict(&mut self) {
self.sat_conflicts += 1;
}
#[inline(always)]
pub(crate) fn stop_notify(&mut self, t: Timer, kind: TheoryKind) {
match kind {
TheoryKind::Lra => self.t_lra_bound += t.elapsed(),
TheoryKind::Enum => self.t_enum += t.elapsed(),
TheoryKind::Other => {}
}
}
#[inline(always)]
pub(crate) fn on_notify_conflict(&mut self, kind: TheoryKind) {
match kind {
TheoryKind::Lra => self.lra_bound_conflicts += 1,
TheoryKind::Enum => self.enum_conflicts += 1,
TheoryKind::Other => {}
}
}
#[inline(always)]
pub(crate) fn stop_lra_check(&mut self, t: Timer) {
self.t_lra_check += t.elapsed();
}
#[inline(always)]
pub(crate) fn on_lra_check_conflict(&mut self) {
self.lra_check_conflicts += 1;
}
#[inline(always)]
pub(crate) fn stop_analyze(&mut self, t: Timer) {
self.t_analyze += t.elapsed();
}
#[inline(always)]
pub(crate) fn stop_cancel(&mut self, t: Timer) {
self.t_cancel += t.elapsed();
}
pub(crate) fn format_stats(&self, vars: usize, pivots: usize, (rows, nnz, max_len): (usize, usize, usize)) -> String {
format!(
"calls={} vars={vars} sat_c={} lra_b_c={} lra_chk_c={} enum_c={} | pivots={pivots} rows={rows} nnz={nnz} max_row={max_len} | sat={:.2?} lra_b={:.2?} enum={:.2?} lra_chk={:.2?} analyze={:.2?} cancel={:.2?}",
self.prop_calls,
self.sat_conflicts,
self.lra_bound_conflicts,
self.lra_check_conflicts,
self.enum_conflicts,
self.t_sat_prop,
self.t_lra_bound,
self.t_enum,
self.t_lra_check,
self.t_analyze,
self.t_cancel,
)
}
}
}
#[cfg(not(feature = "profiling"))]
mod imp {
use super::TheoryConstraint;
pub(crate) type Timer = ();
#[derive(Clone, Copy)]
pub(crate) struct TheoryKind;
impl TheoryKind {
#[inline(always)]
pub(crate) fn of(_: &TheoryConstraint) -> Self {
Self
}
}
#[derive(Default)]
pub(crate) struct SmtProf;
impl SmtProf {
#[inline(always)]
pub(crate) fn start() -> Timer {}
#[inline(always)]
pub(crate) fn on_prop_call(&mut self) {}
#[inline(always)]
pub(crate) fn stop_sat_prop(&mut self, _: Timer) {}
#[inline(always)]
pub(crate) fn on_sat_conflict(&mut self) {}
#[inline(always)]
pub(crate) fn stop_notify(&mut self, _: Timer, _: TheoryKind) {}
#[inline(always)]
pub(crate) fn on_notify_conflict(&mut self, _: TheoryKind) {}
#[inline(always)]
pub(crate) fn stop_lra_check(&mut self, _: Timer) {}
#[inline(always)]
pub(crate) fn on_lra_check_conflict(&mut self) {}
#[inline(always)]
pub(crate) fn stop_analyze(&mut self, _: Timer) {}
#[inline(always)]
pub(crate) fn stop_cancel(&mut self, _: Timer) {}
}
}
pub(crate) use imp::{SmtProf, TheoryKind};