It's cool to see things like interrupt.memfault.com/blog/trice (and zephyr's version) becoming common for C folks as well.
As far as I can tell, the "deferred logging revolution" seems to have all started with ' #knurling defmt tool, but there's always SOME prior art :)
Conversation
Cool! I went through a similar process. Eventually decided that adding complexity of an extra build step was not worth it so I started converting the performance sensitive statements to binary logs.
1
I do wonder though. Is this an actual parser, or a regexp hack?
1
No idea how the TRACE library works. defmt works by placing the interned strings into an unused linker section, and decodes it automatically when you give it an ELF file and a stream of logs.
1
Oh nice. I tried something like that for C but couldn't figure it out how to do it for const strings.
1
At least in Rust, with the benefit of macros, defmt is pretty well documented, even in impl details:
defmt.ferrous-systems.com/interning.html
1
1
Thanks.
The issue I had is how to annotate a const string without first binding it to a variable like answer here:
1
But it might be possible to wrap it with a C expression statement in a macro, do a variable binding in that expression statement and add the annotation.
Yeah, something like that might work. I think defmt relies on the linker to gc all the strings out, after creating it as a static string in the specific section.
I think the defmt section is expressly excluded from the final binary.
1
(Rust procedural macros are also much more powerful, basically compiler plugins, so doing shenanigans like generating random identifiers for each string and encoding as JSON is much easier)
1
Show replies
#define STR(str) ({ __attribute__((section(".fmtstring"))) static const char _str[] = str; _str;})
Then wrap every literal string with STR() macro.

