Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Observability #3924

Open
kat-perez opened this issue Feb 26, 2025 · 5 comments
Open

Performance Observability #3924

kat-perez opened this issue Feb 26, 2025 · 5 comments

Comments

@kat-perez
Copy link

What are the best practices for measuring performance? Are there any tools or crates that can provide event-based diagnostic information like a trace? I'm looking for something that can measure whether tasks are being blocked or not.

@lulf
Copy link
Member

lulf commented Feb 27, 2025

You can enable the trace feature in the executor which will involve some callbacks when scheduling tasks etc. (See the trace rs in the executor source for more info). As an extension of that there is the rtos-trace feature which integrates with System view of youre using that

@kat-perez
Copy link
Author

Thanks! Do you know of any options that are not RTOS-based?

@kat-perez
Copy link
Author

@lulf Could you help walk me through how to use trace.rs? I have enabled it via the feature flag cargo add embassy-executor --features trace but i'm getting an "undefined reference" error and I can't find them defined anywhere else in the repo? I'm running the std tick example (cargo run --bin tick) with trace feature enabled

/home/X/embassy/embassy-executor/src/raw/trace.rs:17:(.text._ZN16embassy_executor3raw5trace8task_new17h04e7ee5e821644b7E+0x25): undefined reference to `_embassy_trace_task_new'

@lulf
Copy link
Member

lulf commented Mar 6, 2025

You need to define the functions that gets called by the executor, it is quite low level. I can publish some more code on that later, but for now:

#[unsafe(no_mangle)]
unsafe extern "Rust" fn _embassy_trace_task_exec_begin(executor: u32, task: u32) {
   
}

#[unsafe(no_mangle)]
unsafe extern "Rust" fn _embassy_trace_task_exec_end(executor: u32, task: u32) {
   
}

#[unsafe(no_mangle)]
unsafe extern "C" fn _embassy_trace_executor_idle(executor: u32) {
   
}

#[unsafe(no_mangle)]
unsafe extern "C" fn _embassy_trace_task_ready_begin(executor: u32, task: u32) {}

#[unsafe(no_mangle)]
unsafe extern "C" fn _embassy_trace_task_new(executor: u32, task: u32) {}

So, you can for instance check how long time a task runs by measuring the time between exec_end and exec_begin for a given executor id and task id.

I have some code to generate a trace, but you could also just defmt::info!("{} {} {}", executor, task, Instant::now().as_ticks()); and you should get the ticks when each of these events happen in the log and you can process the information later.

@kat-perez
Copy link
Author

@lulf thanks for clarifying. I'm getting the same undefined symbol error when I enable rtos-trace (undefined symbol: _rtos_trace_system_idle) Does the RTOS automatically define those functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants