-
Notifications
You must be signed in to change notification settings - Fork 6
Exporting app description during compliation for tracing purposes? #51
Description
Yesterday I met with @perlindgren to discuss the state of RTIC Scope now that a v0.2.0 release is approaching. The topic of how RTIC Scope associates ITM packets with RTIC tasks was discussed. Currently, in a preparatory information recovery step before the target is flashed and traced, the source code of the RTIC application is parsed so that the #[app(...)] mod app { ... } module can be extraced and forwarded to rtic_syntax::parse2. From the returned structures, the hardware tasks and their binds are read and thus all necesarry information required to associate ITM packets (relating to interrupts) to RTIC tasks have been recovered.
This approach is not stable. Among other reasons,rtic_scope is not meant to be used as a library and it has yet to reach a stable release. Using it for information recovery will be a game of catch-up which I'd like to avoid. I believe it is of interest that RTIC Scope does not succumb to entropy (too quickly) after my thesis is done later this year. This will require off-loading some work to upstream RTIC instead.
During the meeting the possibility of extracting a description of the RTIC app during compilation came up. For example, a JSON description that the tracer (RTIC Scope, or something else) catches and deserializes. This description would, for example, contain a list of all the tasks and what interrupts they are bound to. This description could be locked behind some #[rtic::app(export_json_description=true)] argument flag.
Pros
- Information structures are already available.
#[rtic::app]just needs to export it to JSON. An initial implementation can probably derive these structures fromserde. - Less source code parsing required for tracers; easier implementations.
rtic_syntaxwill only be used for theseserdestructures unless moved to some other crate.
Cons
- More to maintain in RTIC.
Possible pitfalls
For software task, an auxiliary cortex-m-rtic-trace crate can be used for its setup functions and #[trace] macro. During recovery the source code is parsed again so that these can be counted and associated unique IDs and task names. #[trace] is a simple macro that wraps the decorated function with two statements: one for when the task enters, and one for then it exits. E.g.
#[trace]
fn some_task() {
let _x = 42;
#[trace]
fn nested() {}
nested()
}
#[trace]
fn some_other_task() {
let _y = 42;
}expands to
fn some_task() {
cortex_m_rtic_trace::__software_task_enter(0);
let _x = 42;
fn nested() {
cortex_m_rtic_trace::__software_task_enter(1);
cortex_m_rtic_trace::__software_task_enter(1);
}
nested();
cortex_m_rtic_trace::__software_task_exit(0);
}
fn some_other_task() {
cortex_m_rtic_trace::__software_task_enter(2);
let _x = 42;
cortex_m_rtic_trace::__software_task_exit(2);
}Can #[rtic::app] find the #[trace] macros and record it as some "unknown" macro to the associated function and add it to the JSON description?
I'll let this simmer a bit and bring it up in a later weekly RTIC meeting. Afterwards I'll draft up an RFC if we decide to go ahead with this.
Anything to amend, @perlindgren?