nornir 0.4.42

Companion to cargo: dependency tracking, release gating, deploy, benchmarks, and documentation assembly. Project-agnostic.
//! One-shot profiler for EPIC #44: the viz callgraph/dep-graph for the **njord**
//! workspace takes ~10s. This times the two costs the user actually pays:
//!
//!   1. the `Warehouse.Scan` RPC for `symbol_facts` + `call_edges` (server-side
//!      Iceberg read of njord's 15 GB / ~6 k data-file tables), and
//!   2. the on-UI-thread graph layout (`build_graph` → force + the chosen 3D
//!      layout) over the scanned rows.
//!
//! Run against the live server:
//!   NORNIR_SERVER=http://oden:7878 \
//!   NORNIR_TOKEN=$(sudo grep TOKEN /etc/nornir/nornir.env | cut -d= -f2) \
//!   cargo run --example profile_callgraph --features viz,server -- njord
//!
//! Prints column/row counts and millisecond timings so the bottleneck is
//! MEASURED, not guessed.

use std::time::Instant;

fn main() -> anyhow::Result<()> {
    let ws = std::env::args().nth(1).unwrap_or_else(|| "njord".into());
    let endpoint = std::env::var("NORNIR_SERVER").unwrap_or_else(|_| "http://oden:7878".into());
    let token = std::env::var("NORNIR_TOKEN")
        .or_else(|_| std::fs::read_to_string(nornir::config::nornir_home().join("token")))
        .map(|s| s.trim().to_string())
        .unwrap_or_default();
    let limit: u32 = std::env::var("LIMIT").ok().and_then(|s| s.parse().ok()).unwrap_or(8000);

    eprintln!("== profile_callgraph ws={ws} endpoint={endpoint} limit={limit} ==");

    // Mode A: live remote RPC (uses whatever code the running server has).
    if std::env::var("LOCAL_ROOT").is_err() {
        for table in ["symbol_facts", "call_edges"] {
            let t0 = Instant::now();
            let preview = nornir::viz::remote::scan_table(&endpoint, &token, table, limit, &ws)?;
            let dt = t0.elapsed();
            eprintln!(
                "REMOTE SCAN  {table:14} {:>5} cols  {:>6} rows   {:>8.1} ms",
                preview.columns.len(),
                preview.rows.len(),
                dt.as_secs_f64() * 1000.0
            );
        }
    }

    // Mode B: direct local scan against a warehouse root (the NEW scan_limited
    // code in-process). LOCAL_ROOT must contain `warehouse/` + `catalog.redb`.
    if let Ok(root) = std::env::var("LOCAL_ROOT") {
        use nornir::warehouse::iceberg::IcebergWarehouse;
        let wh = IcebergWarehouse::open_read_only(std::path::Path::new(&root))?;
        for table in ["symbol_facts", "call_edges"] {
            let t0 = Instant::now();
            let preview = wh.scan_preview(table, limit as usize)?;
            let dt = t0.elapsed();
            eprintln!(
                "LOCAL  SCAN  {table:14} {:>5} cols  {:>6} rows   {:>8.1} ms",
                preview.columns.len(),
                preview.rows.len(),
                dt.as_secs_f64() * 1000.0
            );
        }
    }
    Ok(())
}