From 290758d2034164c14b30a510a73e10463cb63879 Mon Sep 17 00:00:00 2001 From: rhetenor Date: Sun, 30 Aug 2026 20:57:35 +0200 Subject: [PATCH] add executer tracing for debug --- Cargo.lock | 1 + Cargo.toml | 3 ++- src/lib.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f915330..28f7071 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,6 +368,7 @@ dependencies = [ "esp-bootloader-esp-idf", "esp-hal", "esp-hal-wifimanager", + "esp-nvs", "esp-println", "esp-rtos", "esp-storage", diff --git a/Cargo.toml b/Cargo.toml index b2f26eb..711a407 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ log = "0.4.27" critical-section = "1.2.0" embedded-io = "0.7.1" -embassy-executor = { version = "0.10.0", features = [] } +embassy-executor = { version = "0.10.0", features = ["trace", "metadata-name"] } embassy-time = { version = "0.5.1", default-features = false } embassy-futures = "0.1.2" esp-alloc = "0.10.0" @@ -55,6 +55,7 @@ embedded-storage = "0.3.1" binary_serde = "1.0.25" static_assertions = { version = "1.1.0", default-features = false } embedded-text = "0.7.3" +esp-nvs = { version = "0.5.0", features = ["esp32s3"] } [build-dependencies] log = "0.4.27" diff --git a/src/lib.rs b/src/lib.rs index 301be94..93384ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,3 +12,69 @@ pub mod navigation; pub mod network; pub mod peripherals; pub mod views; + +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_poll_start(executor_id: u32) {} + +/// This callback is called AFTER a task is initialized/allocated, and BEFORE +/// it is enqueued to run for the first time. If the task ends (and does not +/// loop "forever"), there will be a matching call to `_embassy_trace_task_end`. +/// +/// Tasks start life in the SPAWNED state. +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_task_new(executor_id: u32, task_id: u32) { + log::debug!("Started new task on executer 0x{executor_id:x} with id 0x{task_id:x}") +} + +/// This callback is called AFTER a task is destructed/freed. This will always +/// have a prior matching call to `_embassy_trace_task_new`. +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_task_end(executor_id: u32, task_id: u32) { + log::debug!("Ended task on executer 0x{executor_id:x} with id 0x{task_id:x}") +} + +/// This callback is called AFTER a task has been dequeued from the runqueue, +/// and BEFORE the task is polled. There will always be a matching call to +/// `_embassy_trace_task_exec_end`. +/// +/// This marks the TASK state transition from WAITING -> RUNNING +/// This marks the EXECUTOR state transition from SCHEDULING -> POLLING +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_task_exec_begin(executor_id: u32, task_id: u32) {} + +/// This callback is called AFTER a task has completed polling. There will +/// always be a matching call to `_embassy_trace_task_exec_begin`. +/// +/// This marks the TASK state transition from either: +/// * RUNNING -> IDLE - if there were no `_embassy_trace_task_ready_begin` events +/// for this task since the last `_embassy_trace_task_exec_begin` for THIS task +/// * RUNNING -> WAITING - if there WAS a `_embassy_trace_task_ready_begin` event +/// for this task since the last `_embassy_trace_task_exec_begin` for THIS task +/// +/// This marks the EXECUTOR state transition from POLLING -> SCHEDULING +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_task_exec_end(excutor_id: u32, task_id: u32) {} + +/// This callback is called AFTER the waker for a task is awoken, and BEFORE it +/// is added to the run queue. +/// +/// If the given task is currently RUNNING, this marks no state change, BUT the +/// RUNNING task will then move to the WAITING stage when polling is complete. +/// +/// If the given task is currently IDLE, this marks the TASK state transition +/// from IDLE -> WAITING. +/// +/// NOTE: This may be called from an interrupt, outside the contpub ext of the current +/// task or executor. +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_task_ready_begin(executor_id: u32, task_id: u32) {} + +/// This callback is called AFTER all dequeued tasks in a single call to poll +/// have been processed. This will always be paired with a call to +/// `_embassy_trace_executor_idle`. +/// +/// +/// This marks the EXECUTOR state transition from SCHEDULING -> IDLE +/// +#[unsafe(no_mangle)] +pub extern "Rust" fn _embassy_trace_executor_idle(executor_id: u32) {}