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(trace): host-controlled tracing #92
Conversation
the TRACE level no longer hangs the board!
✅ Deploy Preview for merry-scone-cc7a60 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
In a subsequent branch, I intend to also add a host -> target heartbeat, so that the target can detect when |
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.
Overall looks fine to me to merge! Left some comments, most are "some day maybe tweak this", take them or leave them :)
max_level: LevelFilter, | ||
max_level: AtomicU8, | ||
|
||
/// Tracks whether we are inside of the collector's `send_event` method, so |
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.
Love it
|
||
// we probably won't use 256 whole bytes of cobs yet since all the host | ||
// -> target messages are quite small | ||
let mut cobs_buf: CobsAccumulator<16> = CobsAccumulator::new(); |
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.
We're gunna want some kind of config soon.
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.
definitely, yeah
return tracing_core_02::Interest::never(); | ||
} | ||
|
||
// Due to the fact that the collector uses `bbq` internally, we must |
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 feels a little icky, because this is a platform-specific impl detail - melpo doesn't use bbqueue for the tracing collection.
Might be worth instead to::
- Provide bbqueue methods that don't emit traces (and use them in lichee-rv)
- Start an "integration guide" that tells people to use something that doesn't emit traces when implementing tracing
I don't think this is a today blocker, but if we merge this as-is it might be good to throw up an issue to fix this someday.
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.
Well, this collector does use bbqueue
--- so tif we are ever using the collector in this file, we are using bbqueue.
} | ||
} | ||
|
||
const fn u8_to_level(level: u8) -> LevelFilter { |
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.
It might be good to have an invalid level be an error (and ignore the "change log level command" instead), otherwise if we receive a garbage message that HAPPENS to look like a command, we have a 251/256 chance of just shutting off all logging. Tho I guess we don't really need to log at all to a connection that is sending us garbage. Hm.
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.
these functions are used internally for converting the AtomicU8
to/from a LevelFilter
, not for parsing the log level sent to us from the host. that gets deserialized using postcard
, so if we get an invalid value, we will error.
}; | ||
|
||
#[derive(serde::Serialize, serde::Deserialize)] | ||
pub enum TraceEvent<'a> { | ||
/// Sent by the target periodically when not actively tracing, to indicate |
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.
We might want to mark this non-exhaustive and add things to the end instead, to avoid breaking wire format, once we care about that.
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.
yeah, i figured we didn't currently care about stability for the crate API or for the wire format, but we can do that in the future.
Currently, the
tracing
collector in the Allwinner D1 platform impl ishardcoded 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 hassubscribed 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 ahost to target message to select a
tracing
level. Now, the board canstart up with all tracing disabled, and
crowtty
can send the desiredtracing level once it connects. This way, we don't collect or format
traces at all when
crowtty
isn't connected. In order to ensurecrowtty
waits to send the tracing level message only once the board'stracing 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
'scallsite 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 thatare 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 aCollect::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 disablebbq
tracing. This is because the collector's use of
bbq
creates aninfinite loop when the TRACE level is enabled.
Check this out: