RustMeter Beacon
The embedded instrumentation library for the RustMeter profiling system.
rustmeter-beacon is a lightweight tracing library designed for embedded Rust applications. It serves as the device-side component that captures runtime events, performance metrics, and task transitions.
It is built to integrate seamlessly with the Embassy async executor and uses defmt for highly efficient, low-overhead logging.
✨ Features
- Embassy Integration: Hooks into
embassy-executorto trace task states (Spawn, Run, Wait, Idle). - Function Monitoring: Easily instrument critical functions with the
#[monitor_fn]attribute. - Scoped Tracing: Measure execution time of specific blocks or loops with
monitor_scoped!. - Custom Metrics: Log sensor data or internal state variables to visualize them over time.
- Multi-Core Ready: Identifies which core code is running on (currently supports ESP32 Xtensa & RISC-V).
📦 Installation
Add the crate to your embedded project's Cargo.toml.
Note: To enable embassy task tracing, you must also enable the trace feature of the embassy-executor.
Attention: Defmt must be configured properly with timestamp enabled (See defmt documentation for more details). Else, the tracing will not work correctly because of missing timestamps.
[]
= "X"
= "X"
# Important: Enable the 'trace' feature!
= { = "X", = ["trace", ... ] }
🛠️ Usage
- Setup
Simply import the crate in your application entry point. This ensures the linker includes the necessary trace hooks.
use *;
- Instrument Functions
Use the #[monitor_fn] attribute to trace the start and end of a function. This works for both async and sync functions.
async
// Override the name shown in the trace
- Trace Scopes
For more granular control, use the monitor_scoped! macro to measure specific code blocks.
- Record Metrics
Visualize values over time (like battery voltage, memory usage, or temperature) using event_metric!. These appear as counter graphs in the trace viewer.
let temp = temp_sensor.read;
event_metric!;
🚀 Collecting Data
This library produces defmt logs. To capture and visualize them, you need the host-side tool rustmeter.
-
Install the CLI:
cargo install rustmeter -
Run your project:
rustmeter(instead of cargo run) -
Open the generated trace file in ui.perfetto.dev.
⚙️ Architecture Support
Currently, rustmeter-beacon includes automatic core ID detection for:
- Espressif ESP32 (Xtensa & RISC-V variants via esp-hal)
Support for other platforms (e.g., STM32, RP2040) is planned.
📄 License
This project is licensed under the MIT License.