Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trace): host-controlled tracing (#92)
Currently, the `tracing` collector in the Allwinner D1 platform impl is hardcoded to the DEBUG level. This is unfortunate, as it means that we will always do the work of collecting and formatting DEBUG traces, even when no one is listening on the UART tracing port. It would be more efficient if we only formatted traces when a `crowtty` instance has subscribed to the UART tracing port. Additionally, because trace metadata is sent when the callsite is initially registered, a `crowtty` instance that attaches after the board has started running may miss some trace metadata. Finally, there is no way to change the trace level on the fly, as it's hard-coded in the kernel. This branch changes the `mnemos-trace-proto` wire protocol to include a host to target message to select a `tracing` level. Now, the board can start up with all tracing disabled, and `crowtty` can send the desired tracing level once it connects. This way, we don't collect or format traces at all when `crowtty` isn't connected. In order to ensure `crowtty` waits to send the tracing level message only once the board's tracing code has been initialized, we add a periodic "heartbeat" message sent by the board on the tracing port while tracing is idle. This is used by the host which is listening for traces to detect the presence of the tracing collector on the debug target. The same message is used to ack a successful request to select the tracing level. When the tracing level is selected, the target rebuilds `tracing`'s callsite cache, which means all metadata for callsites which have previously been hit will be sent to the host. This ensures that `crowtty` always has the metadata for all tracing spans and events that are enabled, even if the target encountered them before `crowtty` connected. Making this work required fixing an upstream `tracing` bug, tokio-rs/tracing#2634, where calling into code that includes `tracing` diagnostics from inside a `Collect::register_callsite` method would cause a deadlock. Additionally, I had to add code to the collector for tracking whether it's inside its own `send` method, in order to temporarily disable `bbq` tracing. This is because the collector's use of `bbq` creates an infinite loop when the TRACE level is enabled. Check this out: ![image](https://github.com/tosc-rs/mnemos/assets/2796466/9a527c27-a5c4-422f-b2b3-bd0a46ba4794)
- Loading branch information
Showing
10 changed files
with
307 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.