Memfault's Firmware SDK now includes support for what we are calling "Compact Logs". It is similar to Zephyr's dictionary-based-logging and a few other implementations in other RTOS's, but we think we've hit the perfect balance of performance, features, ease-of-use, and size compression.
Let's walk through a quick example of what compact logs are. Here is a log line that a user of the Memfault SDK could write:
With a generic formatted string implementation such as
printf, we would need
to include the entire string contents in our log buffer or storage. In total,
this requires 41 bytes.
Once developers run out of firmware code space, a common pattern is to start shortening log lines or removing them entirely. We believe this is a bad practice! We should be able to keep our useful log lines and make the messages as long as necessary!
This is why we created compact logs. With compact logs, every log "string" is placed in a special section in the ELF file and we just need to reference each log line with an index, or ID.
For a compact log, we just need to encode an integer ID for the string portion and the arguments to be serialized. In this example, this information requires just 5 bytes.
In this example, we can reduce the storage occupied by 88%! For a firmware that contains 100-1000 log lines, these savings are dramatic.
Check out our documentation for more information on how to enable compact logs in your firmware.
Along with compact logs, we've been busy adding more ways to filter and slice the data in our application and building up some exciting features related to Custom Events and State. More news to come next month.