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

sys/native: Set timestamp clock correctly in generated packets #12

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/layer/src/native_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ where
// extension
struct DelayedSliceBegin {
timestamp_ns: u64,
timestamp_clock_id: u32,
meta: &'static tracing::Metadata<'static>,
track_uuid: ids::TrackUuid,
sequence_id: ids::SequenceId,
Expand Down Expand Up @@ -255,6 +256,7 @@ where
) {
let packet = self.create_slice_begin_track_event_packet(
ffi::trace_time_ns(),
ffi::trace_clock_id(),
meta,
track_uuid,
sequence_id,
Expand Down Expand Up @@ -287,6 +289,7 @@ where
if let Some(delayed_slice_begin) = extensions.get::<DelayedSliceBegin>() {
let slice_begin_packet = self.create_slice_begin_track_event_packet(
delayed_slice_begin.timestamp_ns,
delayed_slice_begin.timestamp_clock_id,
delayed_slice_begin.meta,
delayed_slice_begin.track_uuid,
delayed_slice_begin.sequence_id,
Expand All @@ -298,6 +301,7 @@ where

let packet = self.create_slice_end_track_event_packet(
ffi::trace_time_ns(),
ffi::trace_clock_id(),
meta,
track_uuid,
sequence_id,
Expand All @@ -316,6 +320,7 @@ where
) {
let packet = self.create_event_track_event_packet(
ffi::trace_time_ns(),
ffi::trace_clock_id(),
meta,
debug_annotations,
track_uuid,
Expand All @@ -328,9 +333,14 @@ where
fn report_counters(&self, meta: &tracing::Metadata, counters: Vec<debug_annotations::Counter>) {
if !counters.is_empty() {
let timestamp_ns = ffi::trace_time_ns();
let timestamp_clock_id = ffi::trace_clock_id();
self.ensure_counters_known(meta, &counters);
for counter in counters {
let packet = self.create_counter_track_event_packet(timestamp_ns, counter);
let packet = self.create_counter_track_event_packet(
timestamp_ns,
timestamp_clock_id,
counter,
);
self.write_packet(meta, packet);
}
}
Expand Down Expand Up @@ -558,13 +568,15 @@ where
fn create_slice_begin_track_event_packet(
&self,
timestamp_ns: u64,
timestamp_clock_id: u32,
meta: &tracing::Metadata,
track_uuid: ids::TrackUuid,
sequence_id: ids::SequenceId,
debug_annotations: debug_annotations::ProtoDebugAnnotations,
) -> schema::TracePacket {
schema::TracePacket {
timestamp: Some(timestamp_ns),
timestamp_clock_id: Some(timestamp_clock_id),
optional_trusted_packet_sequence_id: Some(
trace_packet::OptionalTrustedPacketSequenceId::TrustedPacketSequenceId(
sequence_id.as_raw(),
Expand All @@ -586,13 +598,15 @@ where
fn create_slice_end_track_event_packet(
&self,
timestamp_ns: u64,
timestamp_clock_id: u32,
meta: &tracing::Metadata,
track_uuid: ids::TrackUuid,
sequence_id: ids::SequenceId,
debug_annotations: debug_annotations::ProtoDebugAnnotations,
) -> schema::TracePacket {
schema::TracePacket {
timestamp: Some(timestamp_ns),
timestamp_clock_id: Some(timestamp_clock_id),
optional_trusted_packet_sequence_id: Some(
trace_packet::OptionalTrustedPacketSequenceId::TrustedPacketSequenceId(
sequence_id.as_raw(),
Expand All @@ -614,13 +628,15 @@ where
fn create_event_track_event_packet(
&self,
timestamp_ns: u64,
timestamp_clock_id: u32,
meta: &tracing::Metadata,
debug_annotations: debug_annotations::ProtoDebugAnnotations,
track_uuid: ids::TrackUuid,
sequence_id: ids::SequenceId,
) -> schema::TracePacket {
schema::TracePacket {
timestamp: Some(timestamp_ns),
timestamp_clock_id: Some(timestamp_clock_id),
optional_trusted_packet_sequence_id: Some(
trace_packet::OptionalTrustedPacketSequenceId::TrustedPacketSequenceId(
sequence_id.as_raw(),
Expand All @@ -642,10 +658,12 @@ where
fn create_counter_track_event_packet(
&self,
timestamp_ns: u64,
timestamp_clock_id: u32,
counter: debug_annotations::Counter,
) -> schema::TracePacket {
schema::TracePacket {
timestamp: Some(timestamp_ns),
timestamp_clock_id: Some(timestamp_clock_id),
optional_trusted_packet_sequence_id: Some(
trace_packet::OptionalTrustedPacketSequenceId::TrustedPacketSequenceId(
ids::SequenceId::for_counter(counter.name).as_raw(),
Expand Down Expand Up @@ -750,6 +768,7 @@ where
if self.inner.delay_slice_begin {
span.extensions_mut().insert(DelayedSliceBegin {
timestamp_ns: ffi::trace_time_ns(),
timestamp_clock_id: ffi::trace_clock_id(),
meta,
track_uuid,
sequence_id,
Expand Down
6 changes: 6 additions & 0 deletions crates/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ pub mod ffi {
/// clock(s).
fn trace_time_ns() -> u64;

/// Get the id of the clock that is used by `trace_time_ns`.
///
/// Valid values correspond to enum variants of the `BuiltinClock`
/// protobuf enum.
fn trace_clock_id() -> u32;

/// Start collecting traces from all data sources.
fn start(self: Pin<&mut PerfettoTracingSession>);

Expand Down
2 changes: 2 additions & 0 deletions crates/sys/src/perfetto-bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,5 @@ void trace_track_descriptor_thread(uint64_t parent_uuid, uint64_t track_uuid,
}

uint64_t trace_time_ns() { return perfetto::TrackEvent::GetTraceTimeNs(); }

uint32_t trace_clock_id() { return perfetto::TrackEvent::GetTraceClockId(); }
2 changes: 2 additions & 0 deletions crates/sys/src/perfetto-bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ void trace_track_descriptor_thread(uint64_t parent_uuid, uint64_t track_uuid,
uint32_t thread_tid);

uint64_t trace_time_ns();

uint32_t trace_clock_id();
Loading