Skip to content
Draft
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
23 changes: 23 additions & 0 deletions crates/tracedecay-runtime-core/src/db/connection/facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl DatabaseWriterConnection<'_> {
}

impl DatabaseEngineWriteConnection {
#[hotpath::measure(label = "runtime_core.db.write_conn.query")]
pub async fn query<P>(
&self,
sql: &str,
Expand All @@ -58,17 +59,20 @@ impl DatabaseEngineWriteConnection {
self.conn.query(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_conn.execute")]
pub async fn execute<P>(&self, sql: &str, params: P) -> crate::db::engine::Result<u64>
where
P: crate::db::engine::IntoParams,
{
self.conn.execute(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_conn.execute_batch")]
pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> {
self.conn.execute_batch(sql).await
}

#[hotpath::measure(label = "runtime_core.db.write_conn.long_lease_begin")]
pub(crate) async fn authorized_long_lease_transaction(
&self,
) -> crate::db::engine::Result<DatabaseEngineLongLeaseTransaction> {
Expand Down Expand Up @@ -109,6 +113,7 @@ impl crate::db::engine::Executor for DatabaseEngineWriteConnection {
}

impl DatabaseEngineReadConnection {
#[hotpath::measure(label = "runtime_core.db.read_conn.query")]
pub async fn query<P>(
&self,
sql: &str,
Expand All @@ -129,6 +134,7 @@ impl DatabaseEngineReadConnection {
}
}

#[hotpath::measure(label = "runtime_core.db.read_conn.snapshot_begin")]
pub async fn read_snapshot(&self) -> crate::db::engine::Result<DatabaseEngineReadSnapshot> {
self.conn
.read_snapshot()
Expand Down Expand Up @@ -162,6 +168,7 @@ impl crate::db::engine::QueryExecutor for DatabaseEngineReadConnection {
}

impl DatabaseEngineReadSnapshot {
#[hotpath::measure(label = "runtime_core.db.snapshot.query")]
pub async fn query<P>(
&self,
sql: &str,
Expand Down Expand Up @@ -198,6 +205,7 @@ impl crate::db::engine::QueryExecutor for DatabaseEngineReadSnapshot {
}

impl DatabaseEngineLongLeaseTransaction {
#[hotpath::measure(label = "runtime_core.db.long_lease.batch")]
pub(crate) async fn execute_authority_revalidated_batch(
&self,
sql: &str,
Expand All @@ -207,10 +215,12 @@ impl DatabaseEngineLongLeaseTransaction {
.await
}

#[hotpath::measure(label = "runtime_core.db.long_lease.commit")]
pub(crate) async fn commit(self) -> crate::db::engine::Result<()> {
self.transaction.commit().await
}

#[hotpath::measure(label = "runtime_core.db.long_lease.rollback")]
pub(crate) async fn rollback(self) -> crate::db::engine::Result<()> {
self.transaction.rollback().await
}
Expand Down Expand Up @@ -251,6 +261,7 @@ impl<'a> DatabaseMemoryTransaction<'a> {
Self::Write(transaction)
}

#[hotpath::measure(label = "runtime_core.db.memory_txn.query")]
pub async fn query<P>(
&self,
sql: &str,
Expand All @@ -265,6 +276,7 @@ impl<'a> DatabaseMemoryTransaction<'a> {
}
}

#[hotpath::measure(label = "runtime_core.db.memory_txn.execute")]
pub async fn execute<P>(&self, sql: &str, params: P) -> crate::db::engine::Result<u64>
where
P: crate::db::engine::IntoParams,
Expand All @@ -277,6 +289,7 @@ impl<'a> DatabaseMemoryTransaction<'a> {
}
}

#[hotpath::measure(label = "runtime_core.db.memory_txn.execute_batch")]
pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> {
match self {
Self::Read(_) => Err(crate::db::engine::Error::Runtime(
Expand All @@ -286,6 +299,7 @@ impl<'a> DatabaseMemoryTransaction<'a> {
}
}

#[hotpath::measure(label = "runtime_core.db.memory_txn.commit")]
pub async fn commit(self) -> Result<()> {
match self {
Self::Read(snapshot) => {
Expand All @@ -301,6 +315,7 @@ impl<'a> DatabaseMemoryTransaction<'a> {
}
}

#[hotpath::measure(label = "runtime_core.db.memory_txn.rollback")]
pub async fn rollback(self) -> Result<()> {
match self {
Self::Read(snapshot) => {
Expand Down Expand Up @@ -364,13 +379,15 @@ impl crate::db::engine::DatabaseAttachmentExecutor for DatabaseMemoryTransaction
}

impl DatabaseWriteTransaction<'_> {
#[hotpath::measure(label = "runtime_core.db.write_txn.execute")]
pub async fn execute<P>(&self, sql: &str, params: P) -> crate::db::engine::Result<u64>
where
P: crate::db::engine::IntoParams,
{
self.transaction.execute(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.query")]
pub async fn query<P>(
&self,
sql: &str,
Expand All @@ -382,21 +399,25 @@ impl DatabaseWriteTransaction<'_> {
self.transaction.query(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.execute_batch")]
pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> {
self.transaction.execute_batch(sql).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.execute_batch")]
pub async fn execute_batch_engine(&self, sql: &str) -> crate::db::engine::Result<()> {
self.transaction.execute_batch(sql).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.execute")]
pub async fn execute_engine<P>(&self, sql: &str, params: P) -> crate::db::engine::Result<u64>
where
P: crate::db::engine::IntoParams,
{
self.transaction.execute(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.query")]
pub async fn query_engine<P>(
&self,
sql: &str,
Expand All @@ -408,6 +429,7 @@ impl DatabaseWriteTransaction<'_> {
self.transaction.query(sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.write_txn.commit")]
pub async fn commit(self) -> Result<()> {
let Self {
transaction,
Expand Down Expand Up @@ -498,6 +520,7 @@ impl DatabaseWriteTransaction<'_> {
})
}

#[hotpath::measure(label = "runtime_core.db.write_txn.rollback")]
pub async fn rollback(self) -> Result<()> {
let Self {
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{
impl Database {
/// Runs a bounded scalar inspection on the retained runtime, projecting the
/// first column of the first row.
#[hotpath::measure(label = "runtime_core.db.query_scalar")]
async fn query_scalar<T, P>(&self, operation: &str, sql: &str, params: P) -> Result<T>
where
T: crate::db::engine::FromValue,
Expand Down Expand Up @@ -79,6 +80,7 @@ impl Database {
self.execute_write_engine(operation, sql, params).await
}

#[hotpath::measure(label = "runtime_core.db.execute_write")]
pub async fn execute_write_engine<P>(
&self,
operation: &str,
Expand All @@ -102,6 +104,7 @@ impl Database {

/// Executes a SQL batch atomically through the canonical writer broker.
#[doc(hidden)]
#[hotpath::measure(label = "runtime_core.db.execute_write_batch")]
pub async fn execute_write_batch(&self, operation: &str, sql: &str) -> Result<()> {
let transaction = self.begin_write_transaction(operation).await?;
transaction
Expand All @@ -120,6 +123,7 @@ impl Database {
/// The retained client guard stays alive for the entire transaction, and
/// the exact write authority is checked before writer admission and again
/// continuously by the runtime's authority-revalidated batch execution.
#[hotpath::measure(label = "runtime_core.db.authority_batch")]
pub async fn execute_authority_revalidated_batch(
&self,
operation: &str,
Expand Down Expand Up @@ -165,6 +169,7 @@ impl Database {
///
/// Writable handles opened for the same database share one `DatabaseInner`,
/// so this guard coordinates MCP, dashboard, and automation mutations.
#[hotpath::measure(label = "runtime_core.db.writer.lane_wait")]
pub async fn writer(&self) -> tokio::sync::MutexGuard<'_, ()> {
self.inner.writer.lock().await
}
Expand Down Expand Up @@ -198,6 +203,7 @@ impl Database {
/// Opens an isolated writer while holding the process-local writer lane.
/// The handle cannot escape the guard, preventing raw DML from bypassing
/// serialization or joining a transaction on the retained reader.
#[hotpath::measure(label = "runtime_core.db.writer.open")]
pub async fn writer_connection(&self, operation: &str) -> Result<DatabaseWriterConnection<'_>> {
let guard = self.writer().await;
let conn = self.open_writer_connection_unguarded(operation).await?;
Expand All @@ -210,6 +216,7 @@ impl Database {

/// Starts a query-only snapshot on a separate connection that cannot join
/// a transaction running on the retained writable connection.
#[hotpath::measure(label = "runtime_core.db.snapshot.begin")]
pub(crate) async fn begin_isolated_read_snapshot(
&self,
operation: &str,
Expand Down Expand Up @@ -247,6 +254,7 @@ impl Database {

/// Starts an immediate transaction that owns the canonical writer lane.
/// Dropping the returned capability rolls back before releasing the lane.
#[hotpath::measure(label = "runtime_core.db.write_txn.begin")]
pub async fn begin_write_transaction(
&self,
operation: &str,
Expand Down Expand Up @@ -274,6 +282,7 @@ impl Database {
/// transaction lease while continuously making progress. The runtime's
/// long-lease policy renews that lease only after successful commands;
/// idle transactions, revoked authority, and shutdown still cancel it.
#[hotpath::measure(label = "runtime_core.db.write_txn.begin_bulk")]
pub async fn begin_bulk_write_transaction(
&self,
operation: &str,
Expand Down
2 changes: 2 additions & 0 deletions crates/tracedecay-runtime-core/src/store/memory/crud/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn classification_similarity(
Ok(project_memory_millionths(similarity))
}

#[hotpath::measure(label = "runtime_core.memory.add_candidates")]
async fn candidates_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -136,6 +137,7 @@ async fn candidates_tx(
Ok(candidates)
}

#[hotpath::measure(label = "runtime_core.memory.add_classify")]
pub(super) async fn classify_project_memory_add_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub(super) fn project_memory_feedback_delta(action: ProjectMemoryFactFeedbackAct
}
}

#[hotpath::measure(label = "runtime_core.memory.feedback_projection")]
pub(super) async fn project_memory_update_feedback_projection_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -198,6 +199,7 @@ pub(super) fn commit_receipt_json(outcome: &'static str, receipt: &FactCommitRec
})
}

#[hotpath::measure(label = "runtime_core.memory.commit_receipt")]
pub(super) async fn project_memory_commit_receipt_from_operation_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -304,6 +306,7 @@ pub(in crate::store::memory) async fn load_mutable_project_memory_fact_tx(
}
}

#[hotpath::measure(label = "runtime_core.memory.replay_add")]
async fn project_memory_replay_add_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -527,6 +530,7 @@ pub(in crate::store::memory) async fn add_project_memory_fact_tx(
ProjectMemoryFactAddOutcomeV1::added(fact, canonical_receipt, replayed)
}

#[hotpath::measure(label = "runtime_core.memory.replay_update")]
async fn project_memory_replay_update_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -677,6 +681,7 @@ pub(in crate::store::memory) async fn update_project_memory_fact_tx(
)
}

#[hotpath::measure(label = "runtime_core.memory.replay_remove")]
async fn project_memory_replay_remove_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn assertion_header_json(assertion: &FactAssertionV1) -> FactStoreResult<String>
)
}

#[hotpath::measure(label = "runtime_core.memory.commit_fact")]
pub(super) async fn commit_fact_tx(
transaction: &Transaction<'_>,
batch: &FactWriteBatch,
Expand Down Expand Up @@ -115,6 +116,7 @@ pub(super) async fn commit_fact_tx(
})
}

#[hotpath::measure(label = "runtime_core.memory.last_event")]
pub(super) async fn current_last_event(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -142,6 +144,7 @@ pub(super) async fn current_last_event(
)?)?))
}

#[hotpath::measure(label = "runtime_core.memory.append_order_check")]
async fn ensure_append_order(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -181,6 +184,7 @@ async fn ensure_append_order(
Ok(())
}

#[hotpath::measure(label = "runtime_core.memory.replay_check")]
async fn batch_is_exact_replay(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -211,6 +215,7 @@ async fn batch_is_exact_replay(
Ok(true)
}

#[hotpath::measure(label = "runtime_core.memory.collision_check")]
async fn batch_identity_collision(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -302,6 +307,7 @@ async fn fact_identity_matches(
/// probe binds, kept clear of `SQLite`'s default variable ceiling.
const REFERENCED_ANCHOR_BATCH: usize = 500;

#[hotpath::measure(label = "runtime_core.memory.anchors_ensure")]
async fn ensure_referenced_anchors(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -354,6 +360,7 @@ async fn ensure_referenced_anchors(
Ok(())
}

#[hotpath::measure(label = "runtime_core.memory.anchor_upsert")]
async fn insert_or_verify_anchor(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down Expand Up @@ -472,6 +479,7 @@ pub(super) async fn anchor_matches(
Ok(stored == expected)
}

#[hotpath::measure(label = "runtime_core.memory.assertion_insert")]
async fn insert_assertion(
transaction: &Transaction<'_>,
owner: &OwnerKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fn project_memory_feedback_action(
}

#[allow(clippy::too_many_arguments)]
#[hotpath::measure(label = "runtime_core.memory.feedback_history")]
async fn project_memory_record_feedback_history_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -227,6 +228,7 @@ async fn project_memory_record_feedback_history_tx(
Ok(())
}

#[hotpath::measure(label = "runtime_core.memory.replay_feedback")]
async fn project_memory_replay_feedback_tx(
transaction: &Transaction<'_>,
owner: &FactOwnerV1,
Expand Down Expand Up @@ -484,6 +486,7 @@ pub(in crate::store::memory) async fn inspect_project_memory_fact_controlled_tx(
inspect_project_memory_fact_inner_tx(transaction, target, Some(read_control)).await
}

#[hotpath::measure(label = "runtime_core.memory.fact_inspect")]
async fn inspect_project_memory_fact_inner_tx(
transaction: &Transaction<'_>,
target: &ProjectMemoryFactIdV1,
Expand Down
Loading
Loading