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

Customizable timestamps #343

Merged
merged 5 commits into from
Jan 15, 2021
Merged

Customizable timestamps #343

merged 5 commits into from
Jan 15, 2021

Conversation

jonas-schievink
Copy link
Contributor

@jonas-schievink jonas-schievink commented Jan 14, 2021

Closes #106

Based on #342, since that was needed to fix the test in here.

This changes the defmt::timestamp proc macro to work just like the logging macros, but in item scope. This allows full customization of the timestamp, as well as "real" omission if no timestamp is used (currently we just always have a timestamp of 0).

Summary of changes

  • Add a dummy section to the linker script, whose purpose is just to hold symbols we want to retain but don't otherwise use. This is used to make the linker retain the timestamp format string, since we wouldn't otherwise use its address.
  • #[defmt::timestamp] is now a regular proc macro instead of an attribute.
  • A new timestamp tag was added to identify the format string used in defmt::timestamp!.
  • The default timestamp is not present instead of being 0. elf2table just won't find a format string with timestamp tag and omit it accordingly.
  • A new µs display hint was added to retain the previous time formatting. It interprets an integer as a time in microseconds and formats it like X.XXXXXX. We could potentially be more fancy here and allow arbitrary scaling of fixed-point decimal and binary values, but that seemed fairly complex, so I did this instead.

Limitations

  • If you want to use the old timestamp format, you'd use {=u64:µs}. However that is no longer LEB-encoded, so it takes up more space if it's a small number (eg. a monotonic counter). We could fix this by encoding integers with LEB128, or by adding a new leb128 format type.

I probably still need to update the book and other docs. Done!

@jonas-schievink jonas-schievink marked this pull request as ready for review January 15, 2021 13:08
@Lotterleben
Copy link
Contributor

regarding the book update, whst's left to do there? would it make sense to open an issue about that so it's transparent and we don't forget?

@jonas-schievink
Copy link
Contributor Author

I think that's all done now

Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

@jonas-schievink
Copy link
Contributor Author

bors r=japaric

@bors
Copy link
Contributor

bors bot commented Jan 15, 2021

Build succeeded:

@bors bors bot merged commit eb8c3b1 into main Jan 15, 2021
@bors bors bot deleted the timestamp branch January 15, 2021 14:32
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

Successfully merging this pull request may close these issues.

Allow customizing/omitting the timestamp from the stream
3 participants