-
Notifications
You must be signed in to change notification settings - Fork 209
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
feat(esp-alloc): Add heap usage stats #2137
base: main
Are you sure you want to change the base?
Conversation
Fancy, but it should also support defmt, not everybody uses esp-println and making the user add Display2Format makes this somewhat less elegant. |
Looks nice. Given this runs a small amount of code every time allloc/dealloc is called would it make sense to have that feature gated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks lovely! I agree with @bjoernQ though that this should be an opt-in feature.
@bugadani won't this work with defmt? |
I was thinking about feature gating the whole The trade-off is that we have a feature that will change the amount of fields returned by the struct, if a user calls I also found a chip that has PSRAM, so I tested with using an internal heap and a PSRAM heap, and the output looks like the following:
|
I'm not used to defmt, can you tell what changes are required to make it work with defmt? The following was suggested by @okhsunrog in #2137 (comment): The examples aren't set up to use defmt so I'll have to create a project that uses defmt. |
… extra computation. - Introduce the `internal-heap-stats` feature for `esp-alloc`. - Add `esp_alloc::get_info!()` to `psram_quad` example to show usage and ensure coverage of the feature in tests.
c37f62b
to
3132b98
Compare
With the obvious syntax error, I believe the compiler would just complain about "HeapStats does not implement Format". This would also need to be feature gated, similar to how the rest of the crates have a |
@bugadani yeah, that was a typo, sorry. For some reason I also thought that core Debug can also be used for defmt's println. Seems like it's not the case.. After stydying the docs a bit I think now I get it right |
…ing `HEAP.stats()`
e58ee54
to
e9da803
Compare
esp_alloc::get_info!()
macroThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM!
#[cfg(feature = "defmt")] | ||
impl defmt::Format for HeapStats { | ||
fn format(&self, fmt: defmt::Formatter) { | ||
defmt::write!(fmt, "{}", defmt::Display2Format(self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst convenient, this will end up pulling in core::fmt
for defmt users, could you just duplicate the fmt impl using the defmt::write!
macro instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, not quite, we should manually impl defmt to avoid pulling in core::fmt
machinery for end users
@MabezDev maybe we can merge it as it is and I'll implement defmt correctly in a follow up PR? |
@okhsunrog Could you prepare the PR based on Anthony's branch? Once both are ready I'll merge them. |
@MabezDev Sure, I'm create the PR tomorrow based on this branch |
I'm converting this to a draft for now, no rush with this of course. Please let us know if you'd like any help wrapping this up. |
I got a trauma in the end of September and had a surgery on my elbow. I still intend to work on this as soon as I recover |
Sorry to hear, get well soon :) |
Any update here? It would be nice to get this merged :). |
@MabezDev I'll create a new PR this weekend, Saturday or Sunday and finish the defmt part |
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
This PR provides a way to easily see the current heap usage of
esp_alloc
. This addsHeapRegion::stats()
andEspHeap::stats()
, to returnRegionStats
andHeapStats
respectively.Both also implement
core::fmt::Display
to easily pretty-print the heap usage as following:Testing
I have tested with a few examples locally and with
esp-mbedtls
, and everything works fine.I haven't tested with PSRAM as I don't have any.