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

RecordingStream: automatic log_tick timeline #2072

Merged
merged 6 commits into from
May 9, 2023
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
2 changes: 1 addition & 1 deletion crates/re_arrow_store/tests/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn data_store_dump_filtered() {

fn data_store_dump_filtered_impl(store1: &mut DataStore, store2: &mut DataStore) {
let timeline_frame_nr = Timeline::new_sequence("frame_nr");
let timeline_log_time = Timeline::new_temporal("log_time");
let timeline_log_time = Timeline::log_time();
let frame1: TimeInt = 1.into();
let frame2: TimeInt = 2.into();
let frame3: TimeInt = 3.into();
Expand Down
12 changes: 8 additions & 4 deletions crates/re_log_types/src/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,15 +1071,19 @@ impl DataTable {

let table_id = TableId::random();

let timepoint = |frame_nr: i64| {
if timeless {
let mut tick = 0i64;
let mut timepoint = |frame_nr: i64| {
let tp = if timeless {
TimePoint::timeless()
} else {
TimePoint::from([
(Timeline::new_temporal("log_time"), Time::now().into()),
(Timeline::log_time(), Time::now().into()),
(Timeline::log_tick(), tick.into()),
(Timeline::new_sequence("frame_nr"), frame_nr.into()),
])
}
};
tick += 1;
tp
};

let row0 = {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_log_types/src/data_table_batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ mod tests {

let timepoint = |frame_nr: i64| {
TimePoint::from([
(Timeline::new_temporal("log_time"), Time::now().into()),
(Timeline::log_time(), Time::now().into()),
(Timeline::new_sequence("frame_nr"), frame_nr.into()),
])
};
Expand Down
14 changes: 14 additions & 0 deletions crates/re_log_types/src/time_point/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,25 @@ impl Timeline {
}

/// The log time timeline to which all API functions will always log.
///
/// This timeline is automatically maintained by the SDKs and captures the wall-clock time at
/// which point the data was logged (according to the client's wall-clock).
#[inline]
pub fn log_time() -> Self {
Timeline::new("log_time", TimeType::Time)
}

/// The log tick timeline to which all API functions will always log.
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved
///
/// This timeline is automatically maintained by the SDKs and captures the logging tick at
/// which point the data was logged.
/// The logging tick is monotically incremented each time the client calls one of the logging
/// methods on a `RecordingStream`.
#[inline]
pub fn log_tick() -> Self {
Timeline::new("log_tick", TimeType::Sequence)
}

/// Returns a formatted string of `time_range` on this `Timeline`.
#[inline]
pub fn format_time_range(&self, time_range: &TimeRange) -> String {
Expand Down
16 changes: 14 additions & 2 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{atomic::AtomicI64, Arc};

use ahash::HashMap;
use crossbeam::channel::{Receiver, Sender};
Expand Down Expand Up @@ -319,6 +319,7 @@ pub struct RecordingStream {

struct RecordingStreamInner {
info: RecordingInfo,
tick: AtomicI64,

/// The one and only entrypoint into the pipeline: this is _never_ cloned nor publicly exposed,
/// therefore the `Drop` implementation is guaranteed that no more data can come in while it's
Expand Down Expand Up @@ -385,6 +386,7 @@ impl RecordingStreamInner {

Ok(RecordingStreamInner {
info,
tick: AtomicI64::new(0),
cmds_tx,
batcher,
batcher_to_sink_handle: Some(batcher_to_sink_handle),
Expand Down Expand Up @@ -580,6 +582,7 @@ impl RecordingStream {
// fail.

this.cmds_tx.send(Command::RecordMsg(msg)).ok();
this.tick.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}

/// Records a [`re_log_types::PathOp`].
Expand Down Expand Up @@ -611,12 +614,21 @@ impl RecordingStream {
/// Internally, incoming [`DataRow`]s are automatically coalesced into larger [`DataTable`]s to
/// optimize for transport.
#[inline]
pub fn record_row(&self, row: DataRow) {
pub fn record_row(&self, mut row: DataRow) {
let Some(this) = &*self.inner else {
re_log::warn_once!("Recording disabled - call to record_row() ignored");
return;
};

// TODO(#2074): Adding a timeline to something timeless would suddenly make it not
// timeless... so for now it cannot even have a tick :/
//
// NOTE: We're incrementing the current tick still.
let tick = this.tick.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
if !row.timepoint().is_timeless() {
row.timepoint.insert(Timeline::log_tick(), tick.into());
}

this.batcher.push_row(row);
}

Expand Down
8 changes: 4 additions & 4 deletions crates/re_viewer_context/src/time_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl TimeControl {
return; // it's valid
}
}
if let Some(timeline) = default_time_line(times_per_timeline.timelines()) {
if let Some(timeline) = default_timeline(times_per_timeline.timelines()) {
self.timeline = *timeline;
} else {
self.timeline = Default::default();
Expand Down Expand Up @@ -519,13 +519,13 @@ fn range(values: &BTreeSet<TimeInt>) -> TimeRange {
}

/// Pick the timeline that should be the default, prioritizing user-defined ones.
fn default_time_line<'a>(timelines: impl Iterator<Item = &'a Timeline>) -> Option<&'a Timeline> {
fn default_timeline<'a>(timelines: impl Iterator<Item = &'a Timeline>) -> Option<&'a Timeline> {
let mut log_time_timeline = None;

for timeline in timelines {
if timeline.name().as_str() == "log_time" {
if timeline == &Timeline::log_time() {
log_time_timeline = Some(timeline);
} else {
} else if timeline != &Timeline::log_tick() {
return Some(timeline); // user timeline - always prefer!
}
}
Expand Down
Loading