pub struct RuleExecutionProfiler {
pub profiles: HashMap<u64, RuleProfile>,
pub hotspot_threshold_us: u64,
}Expand description
Profiles individual rule execution performance.
Tracks invocation counts, latencies, hit rates, and hotspot detection for
every rule that passes through record_invocation.
§Example
use ipfrs_tensorlogic::rule_profiler::RuleExecutionProfiler;
let mut profiler = RuleExecutionProfiler::new(1_000);
profiler.record_invocation(1, "ancestor", 500, true);
profiler.record_invocation(1, "ancestor", 1_500, false);
let hotspots = profiler.hotspots();
// avg = (500 + 1500) / 2 = 1000, threshold = 1000 → NOT > threshold
assert!(hotspots.is_empty());Fields§
§profiles: HashMap<u64, RuleProfile>Per-rule profiles indexed by rule_id.
hotspot_threshold_us: u64Average time above which a rule is considered a hotspot (microseconds).
Implementations§
Source§impl RuleExecutionProfiler
impl RuleExecutionProfiler
Sourcepub fn new(hotspot_threshold_us: u64) -> Self
pub fn new(hotspot_threshold_us: u64) -> Self
Creates a new profiler with the specified hotspot threshold.
A rule is a hotspot when its avg_time_us() strictly exceeds
hotspot_threshold_us.
Sourcepub fn record_invocation(
&mut self,
rule_id: u64,
rule_name: &str,
time_us: u64,
success: bool,
)
pub fn record_invocation( &mut self, rule_id: u64, rule_name: &str, time_us: u64, success: bool, )
Records a single rule invocation.
§Parameters
rule_id— stable numeric identifier for the rulerule_name— human-readable label (used only on first insertion)time_us— wall-clock duration of this invocation in microsecondssuccess—trueif the rule produced at least one binding
Sourcepub fn hotspots(&self) -> Vec<&RuleProfile>
pub fn hotspots(&self) -> Vec<&RuleProfile>
Returns all rules whose average invocation time exceeds the hotspot
threshold, sorted by avg_time_us in descending order.
Sourcepub fn top_rules_by_invocations(&self, n: usize) -> Vec<&RuleProfile>
pub fn top_rules_by_invocations(&self, n: usize) -> Vec<&RuleProfile>
Returns up to n rules ordered by total invocation count (highest first).
Sourcepub fn slowest_rules(&self, n: usize) -> Vec<&RuleProfile>
pub fn slowest_rules(&self, n: usize) -> Vec<&RuleProfile>
Returns up to n rules ordered by average time per invocation (highest first).
Sourcepub fn reset_rule(&mut self, rule_id: u64) -> bool
pub fn reset_rule(&mut self, rule_id: u64) -> bool
Removes the profile for rule_id.
Returns true if the rule was present and has been removed, false
if no profile existed for that id.
Sourcepub fn stats(&self) -> ProfilerStats
pub fn stats(&self) -> ProfilerStats
Returns aggregate statistics for all currently tracked rules.
Auto Trait Implementations§
impl Freeze for RuleExecutionProfiler
impl RefUnwindSafe for RuleExecutionProfiler
impl Send for RuleExecutionProfiler
impl Sync for RuleExecutionProfiler
impl Unpin for RuleExecutionProfiler
impl UnsafeUnpin for RuleExecutionProfiler
impl UnwindSafe for RuleExecutionProfiler
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more