From 4120a752211836c61a758ddd3452bf600de66ae1 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 7 Jul 2023 12:06:51 +0200 Subject: [PATCH 1/5] Document that you need to call flush_blocking when using memory sink --- crates/re_sdk/src/log_sink.rs | 4 ++-- crates/re_sdk/src/recording_stream.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/re_sdk/src/log_sink.rs b/crates/re_sdk/src/log_sink.rs index 9e105364d48d..037edf26a541 100644 --- a/crates/re_sdk/src/log_sink.rs +++ b/crates/re_sdk/src/log_sink.rs @@ -120,13 +120,13 @@ impl MemorySinkStorage { } /// Consumes and returns the inner array of [`LogMsg`]. + /// + /// You should make sure to call [`RecordingStream::flush_blocking`] before calling this. #[inline] pub fn take(&self) -> Vec { std::mem::take(&mut *self.0.write()) } -} -impl MemorySinkStorage { /// Convert the stored messages into an in-memory Rerun log file. #[inline] pub fn concat_memory_sinks_as_bytes( diff --git a/crates/re_sdk/src/recording_stream.rs b/crates/re_sdk/src/recording_stream.rs index 21b57297b529..872b4f8ba4a4 100644 --- a/crates/re_sdk/src/recording_stream.rs +++ b/crates/re_sdk/src/recording_stream.rs @@ -153,7 +153,7 @@ impl RecordingStreamBuilder { /// /// ## Example /// - /// ```no_run + /// ``` /// let rec_stream = re_sdk::RecordingStreamBuilder::new("my_app").buffered()?; /// # Ok::<(), Box>(()) /// ``` @@ -176,8 +176,16 @@ impl RecordingStreamBuilder { /// /// ## Example /// - /// ```no_run + /// ``` + /// # fn log_data(_: &re_sdk::RecordingStream) { } + /// /// let (rec_stream, storage) = re_sdk::RecordingStreamBuilder::new("my_app").memory()?; + /// + /// log_data(&rec_stream); + /// + /// rec_stream.flush_blocking(); // Important! + /// let data = storage.take(); + /// /// # Ok::<(), Box>(()) /// ``` pub fn memory( From b41b9c3c2eebb72740f74919c310b44f0204600f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 7 Jul 2023 12:07:12 +0200 Subject: [PATCH 2/5] SDK: Log warnings when user data is beeing dropped --- crates/re_log_types/src/data_table_batcher.rs | 6 +++++- crates/re_sdk/src/log_sink.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/re_log_types/src/data_table_batcher.rs b/crates/re_log_types/src/data_table_batcher.rs index a2a0a01a8ccf..824ec66d8067 100644 --- a/crates/re_log_types/src/data_table_batcher.rs +++ b/crates/re_log_types/src/data_table_batcher.rs @@ -223,7 +223,11 @@ impl Drop for DataTableBatcherInner { fn drop(&mut self) { // Drop the receiving end of the table stream first and foremost, so that we don't block // even if the output channel is bounded and currently full. - drop(self.rx_tables.take()); + if let Some(rx_tables) = self.rx_tables.take() { + if !rx_tables.is_empty() { + re_log::warn!("Dropping data"); + } + } // NOTE: The command channel is private, if we're here, nothing is currently capable of // sending data down the pipeline. diff --git a/crates/re_sdk/src/log_sink.rs b/crates/re_sdk/src/log_sink.rs index 037edf26a541..b98dd7ebd0a5 100644 --- a/crates/re_sdk/src/log_sink.rs +++ b/crates/re_sdk/src/log_sink.rs @@ -106,6 +106,14 @@ impl LogSink for MemorySink { #[derive(Default, Clone)] pub struct MemorySinkStorage(Arc>>); +impl Drop for MemorySinkStorage { + fn drop(&mut self) { + if !self.0.read().is_empty() { + re_log::warn!("Dropping data in MemorySink - did you forget to flush?"); + } + } +} + impl MemorySinkStorage { /// Write access to the inner array of [`LogMsg`]. #[inline] From d648cca47f974122b9e413129537784a5c9107ec Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 7 Jul 2023 12:36:17 +0200 Subject: [PATCH 3/5] adjust message --- crates/re_sdk/src/log_sink.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/re_sdk/src/log_sink.rs b/crates/re_sdk/src/log_sink.rs index b98dd7ebd0a5..82df6785d176 100644 --- a/crates/re_sdk/src/log_sink.rs +++ b/crates/re_sdk/src/log_sink.rs @@ -109,7 +109,7 @@ pub struct MemorySinkStorage(Arc>>); impl Drop for MemorySinkStorage { fn drop(&mut self) { if !self.0.read().is_empty() { - re_log::warn!("Dropping data in MemorySink - did you forget to flush?"); + re_log::warn!("Dropping data in MemorySink"); } } } From 3230cb7cbd1367e4947fcb98ebd25da6920ebb11 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 10 Jul 2023 09:22:27 +0200 Subject: [PATCH 4/5] No need to call flush_blocking --- crates/re_sdk/src/recording_stream.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/re_sdk/src/recording_stream.rs b/crates/re_sdk/src/recording_stream.rs index 6f32813008ab..07f0fad9a5f5 100644 --- a/crates/re_sdk/src/recording_stream.rs +++ b/crates/re_sdk/src/recording_stream.rs @@ -183,7 +183,6 @@ impl RecordingStreamBuilder { /// /// log_data(&rec_stream); /// - /// rec_stream.flush_blocking(); // Important! /// let data = storage.take(); /// /// # Ok::<(), Box>(()) From cee6e2d1ad5b3ddbe0226bc069715166f1d6917f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 10 Jul 2023 09:37:17 +0200 Subject: [PATCH 5/5] build fix --- crates/re_sdk/src/log_sink.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/re_sdk/src/log_sink.rs b/crates/re_sdk/src/log_sink.rs index afe7036e32c8..eb8ef7d22a61 100644 --- a/crates/re_sdk/src/log_sink.rs +++ b/crates/re_sdk/src/log_sink.rs @@ -111,7 +111,7 @@ pub struct MemorySinkStorage { impl Drop for MemorySinkStorage { fn drop(&mut self) { - if !self.0.read().is_empty() { + if !self.msgs.read().is_empty() { re_log::warn!("Dropping data in MemorySink"); } }