Skip to content

Commit 2400f8b

Browse files
committed
Add CLI execution profiling
1 parent 7fb07cb commit 2400f8b

6 files changed

Lines changed: 1152 additions & 497 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/kin-cli/src/backend.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ fn is_transient_lock_error(message: &str) -> bool {
3333
pub fn open_kindb_snapshot(
3434
layout: &kin_core::KinLayout,
3535
) -> std::result::Result<kin_db::SnapshotManager, kin_db::KinDbError> {
36+
let _span = tracing::info_span!(
37+
"kindb.open_snapshot",
38+
path = %kindb_snapshot_path(layout).display()
39+
)
40+
.entered();
3641
let path = kindb_snapshot_path(layout);
3742
let mut attempts = 0usize;
3843
let mut delay = Duration::from_millis(SNAPSHOT_OPEN_INITIAL_DELAY_MS);
@@ -72,6 +77,11 @@ pub fn vector_index_path(layout: &kin_core::KinLayout) -> PathBuf {
7277
pub async fn open_snapshot_daemon_first(
7378
layout: &kin_core::KinLayout,
7479
) -> std::result::Result<kin_db::SnapshotManager, kin_db::KinDbError> {
80+
let _span = tracing::info_span!(
81+
"kin.backend.open_snapshot_daemon_first",
82+
snapshot = %kindb_snapshot_path(layout).display()
83+
)
84+
.entered();
7585
// Respect explicit offline mode
7686
if std::env::var("KIN_OFFLINE").is_ok() {
7787
return open_kindb_snapshot(layout);
@@ -93,6 +103,11 @@ pub async fn open_snapshot_daemon_first(
93103
/// Non-fatal: if the file doesn't exist or fails to load, semantic search
94104
/// gracefully returns empty results.
95105
fn load_vector_index_if_exists(snap: &kin_db::SnapshotManager, layout: &kin_core::KinLayout) {
106+
let _span = tracing::info_span!(
107+
"kindb.load_vector_index_if_exists",
108+
path = %vector_index_path(layout).display()
109+
)
110+
.entered();
96111
let path = vector_index_path(layout);
97112
if path.exists() {
98113
let graph = snap.graph();
@@ -112,6 +127,7 @@ fn load_vector_index_if_exists(snap: &kin_db::SnapshotManager, layout: &kin_core
112127
/// Fetch the graph from the daemon's `/graph/bootstrap` endpoint.
113128
/// Returns `None` if the daemon is unreachable or returns an error.
114129
async fn fetch_daemon_graph() -> Option<kin_db::InMemoryGraph> {
130+
let _span = tracing::info_span!("kin.backend.fetch_daemon_graph").entered();
115131
let base_url =
116132
std::env::var("KIN_DAEMON_URL").unwrap_or_else(|_| "http://127.0.0.1:4219".to_string());
117133

crates/kin-cli/src/commands/embed.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ pub(crate) fn drain_pending_embeddings(
1717
graph: &kin_db::InMemoryGraph,
1818
batch_size: usize,
1919
) -> Result<usize> {
20+
let _span = tracing::info_span!(
21+
"kin.embed.drain_pending_embeddings",
22+
batch_size = batch_size
23+
)
24+
.entered();
2025
Ok(graph.process_all_pending_embeddings(batch_size)?)
2126
}
2227

@@ -36,6 +41,7 @@ fn should_queue_full_embedding_pass(status: &kin_db::engine::EmbeddingStatus) ->
3641
/// Opens the graph snapshot, queues all entities for embedding, processes
3742
/// the queue in batches, and persists the HNSW vector index to disk.
3843
pub async fn run(batch_size: usize, json: bool) -> Result<()> {
44+
let _span = tracing::info_span!("kin.embed", batch_size = batch_size, json = json).entered();
3945
let layout = kin_core::KinLayout::discover(&std::env::current_dir()?)
4046
.ok_or_else(|| anyhow::anyhow!("not a Kin repository (no .kin/ found)"))?;
4147

crates/kin-cli/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
pub mod backend;
55
pub mod commands;
6+
pub mod profile;
67
pub mod provenance;

0 commit comments

Comments
 (0)