Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions crates/core/src/fold_db_core/event_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
//! with a single component that can see all system activity.

use std::sync::{Arc, Mutex};
use std::time::{SystemTime, UNIX_EPOCH};

use tracing::info;

use super::event_statistics::now_secs;
pub use super::event_statistics::{EventStatistics, MutationStats, QueryStats};
use crate::messaging::{AsyncMessageBus, Event};

Expand All @@ -21,10 +21,7 @@ impl EventMonitor {
/// Create a new EventMonitor that subscribes to all event types
pub async fn new(message_bus: Arc<AsyncMessageBus>) -> Self {
let statistics = Arc::new(Mutex::new(EventStatistics {
monitoring_start_time: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
monitoring_start_time: now_secs(),
..Default::default()
}));

Expand Down Expand Up @@ -124,11 +121,7 @@ impl EventMonitor {
/// Log a summary of all activity since monitoring started
pub fn log_summary(&self) {
let stats = self.get_statistics();
let runtime = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
- stats.monitoring_start_time;
let runtime = now_secs() - stats.monitoring_start_time;

info!("📊 EventMonitor Summary ({}s runtime):", runtime);
info!(" 📝 Field Value Sets: {}", stats.field_value_sets);
Expand Down
17 changes: 9 additions & 8 deletions crates/core/src/fold_db_core/event_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

use std::time::{SystemTime, UNIX_EPOCH};

pub(super) fn now_secs() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
}

/// Statistics about system activity tracked by the event monitor
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct EventStatistics {
Expand Down Expand Up @@ -77,10 +84,7 @@ impl EventStatistics {
stats.total_execution_time_ms as f64 / stats.executions as f64;
stats.total_results += result_count;
stats.avg_result_count = stats.total_results as f64 / stats.executions as f64;
stats.last_execution_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
stats.last_execution_time = now_secs();
}

pub fn increment_mutation_executions(
Expand All @@ -102,9 +106,6 @@ impl EventStatistics {
stats.total_execution_time_ms as f64 / stats.executions as f64;
stats.total_fields_affected += fields_affected;
stats.avg_fields_affected = stats.total_fields_affected as f64 / stats.executions as f64;
stats.last_execution_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
stats.last_execution_time = now_secs();
}
}
Loading