Feat/stage profiling phase1 3#108
Merged
Merged
Conversation
…ink stages - Introduced `profiling` feature to enable automatic timing of execution stages. - Added `duration_as_nanos` method to `TimeOps` trait for runtime-agnostic duration representation. - Implemented `RecordProfilingMetrics` to track metrics for each stage, including call counts and timing statistics. - Enhanced `Producer` and `Consumer` structs to support profiling state. - Added `with_name` method to `RecordRegistrar` for naming stages in profiling output. - Created tests to validate profiling functionality and ensure metrics are recorded correctly.
…table-atomic/fallback
32 tasks
Co-authored-by: Copilot <copilot@github.com>
…ADME Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, runtime-agnostic stage profiling feature across AimDB (core + adapters) and surfaces it via new MCP tools, along with an updated demo and tests to exercise the feature end-to-end.
Changes:
- Introduces
aimdb-corestage profiling (profilingfeature): per-stage metrics collection, naming via.with_name(..), metadata snapshotting, and a reset API/RPC. - Extends
aimdb-executor::TimeOpswithduration_as_nanos()and implements it in Tokio/Embassy/WASM adapters. - Adds
aimdb-mcptools (get_stage_profiling,reset_stage_profiling) plus demo, docs, changelogs, and CI Makefile gates.
Reviewed changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/aimdb-mcp/src/tools/profiling.rs | New MCP tool implementations for stage profiling query/reset |
| tools/aimdb-mcp/src/tools/mod.rs | Exposes the new profiling tools module and re-exports handlers |
| tools/aimdb-mcp/src/server.rs | Registers/dispatches the new MCP tools and schemas |
| tools/aimdb-mcp/README.md | Documents new MCP tools and expected outputs |
| tools/aimdb-mcp/CHANGELOG.md | Changelog entry for added profiling tools |
| tools/aimdb-mcp/Cargo.toml | Enables aimdb-core/profiling in MCP server dependency |
| Makefile | Adds build/test matrix entries for profiling (incl. embedded check) |
| examples/remote-access-demo/src/server.rs | Refactors demo to use .source()/.tap() with stage names and a deliberate bottleneck |
| examples/remote-access-demo/README.md | Adds “Stage Profiling” section and usage instructions |
| examples/remote-access-demo/Cargo.toml | Enables profiling features for core + tokio adapter |
| docs/design/014-M6-stage-profiling.md | Updates RFC status and adds implementation notes |
| CHANGELOG.md | Top-level changelog entries for the profiling feature and demo updates |
| Cargo.lock | Updates lockfile for new/updated dependencies |
| aimdb-wasm-adapter/src/time.rs | Implements TimeOps::duration_as_nanos for WASM duration type |
| aimdb-wasm-adapter/CHANGELOG.md | Notes the new duration_as_nanos implementation |
| aimdb-tokio-adapter/tests/stage_profiling.rs | New integration test for profiling instrumentation and naming |
| aimdb-tokio-adapter/src/runtime.rs | Implements TimeOps::duration_as_nanos for Tokio Duration |
| aimdb-tokio-adapter/CHANGELOG.md | Documents profiling feature + TimeOps update + integration test |
| aimdb-tokio-adapter/Cargo.toml | Adds profiling feature forwarding to aimdb-core/profiling |
| aimdb-executor/src/lib.rs | Adds required TimeOps::duration_as_nanos method |
| aimdb-executor/CHANGELOG.md | Documents the new required TimeOps method |
| aimdb-embassy-adapter/src/runtime.rs | Implements duration_as_nanos with microsecond granularity conversion |
| aimdb-embassy-adapter/CHANGELOG.md | Documents profiling feature and embedded compile gate |
| aimdb-embassy-adapter/Cargo.toml | Adds adapter-level profiling feature forwarding |
| aimdb-core/src/typed_record.rs | Stores per-record profiling metrics, injects instrumentation, and attaches metadata snapshots |
| aimdb-core/src/typed_api.rs | Adds stage naming (with_name) plumbing and wraps Consumer::subscribe() when profiling enabled |
| aimdb-core/src/remote/metadata.rs | Adds optional stage_profiling metadata field + helper |
| aimdb-core/src/remote/handler.rs | Adds profiling.reset RPC handler (write-permission gated) |
| aimdb-core/src/profiling/stage_metrics.rs | New atomic StageMetrics implementation + tests |
| aimdb-core/src/profiling/record_profiling.rs | New per-record container for per-stage metrics + naming + reset |
| aimdb-core/src/profiling/mod.rs | New instrumentation primitives (Clock, producer state, profiling buffer reader) |
| aimdb-core/src/profiling/info.rs | New serializable snapshot type (StageProfilingInfo) and snapshot builder |
| aimdb-core/src/lib.rs | Exposes profiling module/exports and adds RuntimeForProfiling marker trait |
| aimdb-core/src/context.rs | Exposes Time::duration_as_nanos() convenience accessor |
| aimdb-core/src/builder.rs | Wires a shared profiling clock into AimDb and adds reset method |
| aimdb-core/CHANGELOG.md | Core changelog entry for profiling feature |
| aimdb-core/Cargo.toml | Adds profiling feature and portable-atomic feature flags |
| aimdb-client/src/connection.rs | Adds AimxClient::reset_stage_profiling() RPC helper |
| aimdb-client/CHANGELOG.md | Documents new client reset method |
| .vscode/mcp.json | Adds a local MCP server entry for running aimdb-mcp via cargo run |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…pdate snapshot documentation Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements automatic per-stage wall-clock timing for
.source()/.tap()/.link()callbacks. The feature is off by default and zero-cost when disabled;alloc+ a runtime clock is enough, so it works onno_std + alloc(includingthumbv7em-none-eabihfviaportable-atomic'scritical-sectionfallback).What's new
Core (
aimdb-core, featureprofiling)profilingmodule:StageMetrics(atomiccall_count/total/avg/min/max),RecordProfilingMetricsper-record container, serializableStageProfilingInfosnapshot.ProducerProfilingStatetimes the interval between successiveProducer::produce()calls;ProfilingBufferReaderwraps the buffer reader returned byConsumer::subscribe()and times the interval between successiverecv()yields. No change to the whole-task closure shape of.source()/.tap().RecordRegistrar::with_name("...")names the most recently registered source/tap/link (always callable; no-op when feature is off).RecordMetadata.stage_profilingfield, attached automatically byTypedRecord::collect_metadata.AimDb::reset_stage_profiling()and newprofiling.resetAimX RPC (write-permission gated).RuntimeForProfilingmarker trait keeps the public builder API unchanged when the feature is off.Executor (
aimdb-executor)TimeOpstrait gains a requiredduration_as_nanos(duration) -> u64method (runtime-agnostic numeric representation of elapsed time). Implemented in the tokio, embassy, and wasm adapters.Adapters
aimdb-tokio-adapter:profilingfeature forwards to core;duration_as_nanosimpl saturatesu128 → u64.aimdb-embassy-adapter:profilingfeature pullsportable-atomic/{fallback,critical-section}(via core) for 64-bit-atomic emulation onthumbv7em;duration_as_nanosuses microsecond granularity (portable lower bound). Newmake test-embeddedcross-compile gate.aimdb-wasm-adapter:duration_as_nanosforWasmDuration(ms → ns, saturating).Tools
aimdb-client:AimxClient::reset_stage_profiling().aimdb-mcp: two new tools —get_stage_profiling(per-stage metrics + bottleneck detection with recommendation string) andreset_stage_profiling. The MCP server now depends onaimdb-corewithprofilingenabled.Example demo (
examples/remote-access-demo)TemperatureandSystemStatusare now driven by in-AimDB.source()+.tap()tasks with.with_name("...")labels.slow_status_processordeliberately sleeps 100 ms per value soget_stage_profiling record_key="SystemStatus"flags it as the bottleneck. README documents how to query and reset profiling via MCP andsocat.Tests
StageMetrics(record, reset, accessors, concurrent record understd).RecordProfilingMetrics(sequential indices,set_stage_name,reset_all).aimdb-tokio-adapter/tests/stage_profiling.rs: drives a source/tap pipeline, assertsmin ≤ avg ≤ max, verifies.with_name(...)lands on the registered stages, and thatreset_all()clears counters.make build/make testgainprofilingfeature combinations foraimdb-core(stdandno_std + alloc) andaimdb-tokio-adapter.make test-embeddedgainscargo check --target thumbv7em-none-eabihf --features "embassy-runtime,profiling".Test plan
make checkpassesmake allpassescargo run --package remote-access-demo --bin serverstarts cleanly;get_stage_profiling record_key="SystemStatus"via MCP returns ~100 msavg_time_nsforslow_status_processorand flags it as the bottleneckCloses #58.