Rerun C++ SDK
Loading...
Searching...
No Matches
recording_stream.hpp
1#pragma once
2
3#include <chrono>
4#include <cstdint> // uint32_t etc.
5#include <filesystem>
6#include <optional>
7#include <string_view>
8#include <vector>
9
10#include "as_components.hpp"
11#include "error.hpp"
12#include "spawn_options.hpp"
13
14namespace rerun {
15 struct DataCell;
16
17 enum class StoreKind {
18 Recording,
19 Blueprint,
20 };
21
22 /// A `RecordingStream` handles everything related to logging data into Rerun.
23 ///
24 /// ## Multithreading and ordering
25 ///
26 /// A `RecordingStream` is thread-safe.
27 ///
28 /// Internally, all operations are linearized into a pipeline:
29 /// - All operations sent by a given thread will take effect in the same exact order as that
30 /// thread originally sent them in, from its point of view.
31 /// - There isn't any well defined global order across multiple threads.
32 ///
33 /// This means that e.g. flushing the pipeline (`flush_blocking`) guarantees that all
34 /// previous data sent by the calling thread has been recorded; no more, no less.
35 /// (e.g. it does not mean that all file caches are flushed)
36 ///
37 /// ## Shutdown
38 ///
39 /// The `RecordingStream` can only be shutdown by dropping all instances of it, at which point
40 /// it will automatically take care of flushing any pending data that might remain in the
41 /// pipeline.
42 ///
43 /// TODO(andreas): The only way of having two instances of a `RecordingStream` is currently to
44 /// set it as a the global.
45 ///
46 /// Shutting down cannot ever block.
47 ///
48 /// ## Logging
49 ///
50 /// Internally, the stream will automatically micro-batch multiple log calls to optimize
51 /// transport.
52 /// See [SDK Micro Batching](https://www.rerun.io/docs/reference/sdk-micro-batching) for
53 /// more information.
54 ///
55 /// The data will be timestamped automatically based on the `RecordingStream`'s
56 /// internal clock.
58 public:
59 /// Creates a new recording stream to log to.
60 ///
61 /// \param app_id The user-chosen name of the application doing the logging.
62 /// \param recording_id The user-chosen name of the recording being logged to.
63 /// \param store_kind Whether to log to the recording store or the blueprint store.
65 std::string_view app_id, std::string_view recording_id = std::string_view(),
66 StoreKind store_kind = StoreKind::Recording
67 );
69
70 /// \private
72
73 // TODO(andreas): We could easily make the recording stream trivial to copy by bumping Rusts
74 // ref counter by adding a copy of the recording stream to the list of C recording streams.
75 // Doing it this way would likely yield the most consistent behavior when interacting with
76 // global streams (and especially when interacting with different languages in the same
77 // application).
78 /// \private
79 RecordingStream(const RecordingStream&) = delete;
80 /// \private
81 RecordingStream() = delete;
82
83 // -----------------------------------------------------------------------------------------
84 /// \name Properties
85 /// @{
86
87 /// Returns the store kind as passed during construction
88 StoreKind kind() const {
89 return _store_kind;
90 }
91
92 /// Returns whether the recording stream is enabled.
93 ///
94 /// All log functions early out if a recording stream is disabled.
95 /// Naturally, logging functions that take unserialized data will skip the serialization step as well.
96 bool is_enabled() const {
97 return _enabled;
98 }
99
100 /// @}
101
102 // -----------------------------------------------------------------------------------------
103 /// \name Controlling globally available instances of RecordingStream.
104 /// @{
105
106 /// Replaces the currently active recording for this stream's store kind in the global scope
107 /// with this one.
108 ///
109 /// Afterwards, destroying this recording stream will *not* change the global recording
110 /// stream, as it increases an internal ref-count.
111 void set_global() const;
112
113 /// Replaces the currently active recording for this stream's store kind in the thread-local
114 /// scope with this one
115 ///
116 /// Afterwards, destroying this recording stream will *not* change the thread local
117 /// recording stream, as it increases an internal ref-count.
118 void set_thread_local() const;
119
120 /// Retrieves the most appropriate globally available recording stream for the given kind.
121 ///
122 /// I.e. thread-local first, then global.
123 /// If neither was set, any operations on the returned stream will be no-ops.
124 static RecordingStream& current(StoreKind store_kind = StoreKind::Recording);
125
126 /// @}
127
128 // -----------------------------------------------------------------------------------------
129 /// \name Directing the recording stream.
130 /// \details Either of these needs to be called, otherwise the stream will buffer up indefinitely.
131 /// @{
132
133 /// Connect to a remote Rerun Viewer on the given ip:port.
134 ///
135 /// Requires that you first start a Rerun Viewer by typing 'rerun' in a terminal.
136 ///
137 /// flush_timeout_sec:
138 /// The minimum time the SDK will wait during a flush before potentially
139 /// dropping data if progress is not being made. Passing a negative value indicates no
140 /// timeout, and can cause a call to `flush` to block indefinitely.
141 ///
142 /// This function returns immediately.
143 Error connect(std::string_view tcp_addr = "127.0.0.1:9876", float flush_timeout_sec = 2.0)
144 const;
145
146 /// Spawns a new Rerun Viewer process from an executable available in PATH, then connects to it
147 /// over TCP.
148 ///
149 /// If a Rerun Viewer is already listening on this TCP port, the stream will be redirected to
150 /// that viewer instead of starting a new one.
151 ///
152 /// ## Parameters
153 /// options:
154 /// See `rerun::SpawnOptions` for more information.
155 ///
156 /// flush_timeout_sec:
157 /// The minimum time the SDK will wait during a flush before potentially
158 /// dropping data if progress is not being made. Passing a negative value indicates no
159 /// timeout, and can cause a call to `flush` to block indefinitely.
160 Error spawn(const SpawnOptions& options = {}, float flush_timeout_sec = 2.0) const;
161
162 /// @see RecordingStream::spawn
163 template <typename TRep, typename TPeriod>
165 const SpawnOptions& options = {},
166 std::chrono::duration<TRep, TPeriod> flush_timeout = std::chrono::seconds(2)
167 ) const {
168 using seconds_float = std::chrono::duration<float>; // Default ratio is 1:1 == seconds.
169 return spawn(options, std::chrono::duration_cast<seconds_float>(flush_timeout).count());
170 }
171
172 /// Stream all log-data to a given `.rrd` file.
173 ///
174 /// This function returns immediately.
175 Error save(std::string_view path) const;
176
177 /// Stream all log-data to standard output.
178 ///
179 /// Pipe the result into the Rerun Viewer to visualize it.
180 ///
181 /// If there isn't any listener at the other end of the pipe, the `RecordingStream` will
182 /// default back to `buffered` mode, in order not to break the user's terminal.
183 ///
184 /// This function returns immediately.
185 //
186 // NOTE: This should be called `stdout` like in other SDK, but turns out that `stdout` is a
187 // macro when compiling with msvc [1].
188 // [1]: https://learn.microsoft.com/en-us/cpp/c-runtime-library/stdin-stdout-stderr?view=msvc-170
190
191 /// Initiates a flush the batching pipeline and waits for it to propagate.
192 ///
193 /// See `RecordingStream` docs for ordering semantics and multithreading guarantees.
194 void flush_blocking() const;
195
196 /// @}
197
198 // -----------------------------------------------------------------------------------------
199 /// \name Controlling log time.
200 /// \details
201 /// @{
202
203 /// Set the current time of the recording, for the current calling thread.
204 ///
205 /// Used for all subsequent logging performed from this same thread, until the next call
206 /// to one of the time setting methods.
207 ///
208 /// For example: `rec.set_time_sequence("frame_nr", frame_nr)`.
209 ///
210 /// You can remove a timeline from subsequent log calls again using `rec.disable_timeline`.
211 /// @see set_time_seconds, set_time_nanos, reset_time, set_time, disable_timeline
212 void set_time_sequence(std::string_view timeline_name, int64_t sequence_nr) const;
213
214 /// Set the current time of the recording, for the current calling thread.
215 ///
216 /// Used for all subsequent logging performed from this same thread, until the next call
217 /// to one of the time setting methods.
218 ///
219 /// For example: `rec.set_time("sim_time", sim_time_secs)`.
220 ///
221 /// You can remove a timeline from subsequent log calls again using `rec.disable_timeline`.
222 /// @see set_time_sequence, set_time_seconds, set_time_nanos, reset_time, disable_timeline
223 template <typename TClock>
224 void set_time(std::string_view timeline_name, std::chrono::time_point<TClock> time) const {
225 set_time(timeline_name, time.time_since_epoch());
226 }
227
228 /// Set the current time of the recording, for the current calling thread.
229 ///
230 /// Used for all subsequent logging performed from this same thread, until the next call
231 /// to one of the time setting methods.
232 ///
233 /// For example: `rec.set_time("sim_time", sim_time_secs)`.
234 ///
235 /// You can remove a timeline from subsequent log calls again using `rec.disable_timeline`.
236 /// @see set_time_sequence, set_time_seconds, set_time_nanos, reset_time, disable_timeline
237 template <typename TRep, typename TPeriod>
238 void set_time(std::string_view timeline_name, std::chrono::duration<TRep, TPeriod> time)
239 const {
240 if constexpr (std::is_floating_point<TRep>::value) {
241 using seconds_double =
242 std::chrono::duration<double>; // Default ratio is 1:1 == seconds.
244 timeline_name,
245 std::chrono::duration_cast<seconds_double>(time).count()
246 );
247 } else {
249 timeline_name,
250 std::chrono::duration_cast<std::chrono::nanoseconds>(time).count()
251 );
252 }
253 }
254
255 /// Set the current time of the recording, for the current calling thread.
256 ///
257 /// Used for all subsequent logging performed from this same thread, until the next call
258 /// to one of the time setting methods.
259 ///
260 /// For example: `rec.set_time_seconds("sim_time", sim_time_secs)`.
261 ///
262 /// You can remove a timeline from subsequent log calls again using `rec.disable_timeline`.
263 /// @see set_time_sequence, set_time_nanos, reset_time, set_time, disable_timeline
264 void set_time_seconds(std::string_view timeline_name, double seconds) const;
265
266 /// Set the current time of the recording, for the current calling thread.
267 ///
268 /// Used for all subsequent logging performed from this same thread, until the next call
269 /// to one of the time setting methods.
270 ///
271 /// For example: `rec.set_time_nanos("sim_time", sim_time_nanos)`.
272 ///
273 /// You can remove a timeline from subsequent log calls again using `rec.disable_timeline`.
274 /// @see set_time_sequence, set_time_seconds, reset_time, set_time, disable_timeline
275 void set_time_nanos(std::string_view timeline_name, int64_t nanos) const;
276
277 /// Stops logging to the specified timeline for subsequent log calls.
278 ///
279 /// The timeline is still there, but will not be updated with any new data.
280 ///
281 /// No-op if the timeline doesn't exist.
282 ///
283 /// @see set_time_sequence, set_time_seconds, set_time, reset_time
284 void disable_timeline(std::string_view timeline_name) const;
285
286 /// Clears out the current time of the recording, for the current calling thread.
287 ///
288 /// Used for all subsequent logging performed from this same thread, until the next call
289 /// to one of the time setting methods.
290 ///
291 /// For example: `rec.reset_time()`.
292 /// @see set_time_sequence, set_time_seconds, set_time_nanos, disable_timeline
293 void reset_time() const;
294
295 /// @}
296
297 // -----------------------------------------------------------------------------------------
298 /// \name Logging
299 /// @{
300
301 /// Logs one or more archetype and/or component batches.
302 ///
303 /// This is the main entry point for logging data to rerun. It can be used to log anything
304 /// that implements the `AsComponents<T>` trait.
305 ///
306 /// When logging data, you must always provide an [entity_path](https://www.rerun.io/docs/concepts/entity-path)
307 /// for identifying the data. Note that the path prefix "rerun/" is considered reserved for use by the Rerun SDK
308 /// itself and should not be used for logging user data. This is where Rerun will log additional information
309 /// such as warnings.
310 ///
311 /// The most common way to log is with one of the rerun archetypes, all of which implement the `AsComponents` trait.
312 ///
313 /// For example, to log two 3D points:
314 /// ```
315 /// rec.log("my/point", rerun::Points3D({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}}));
316 /// ```
317 ///
318 /// The `log` function can flexibly accept an arbitrary number of additional objects which will
319 /// be merged into the first entity so long as they don't expose conflicting components, for instance:
320 /// ```
321 /// // Log three points with arrows sticking out of them:
322 /// rec.log(
323 /// "my/points",
324 /// rerun::Points3D({{0.2f, 0.5f, 0.3f}, {0.9f, 1.2f, 0.1f}, {1.0f, 4.2f, 0.3f}})
325 /// .with_radii({0.1, 0.2, 0.3}),
326 /// rerun::Arrows3D::from_vectors({{0.3f, 2.1f, 0.2f}, {0.9f, -1.1, 2.3f}, {-0.4f, 0.5f, 2.9f}})
327 /// );
328 /// ```
329 ///
330 /// Any failures that may occur during serialization are handled with `Error::handle`.
331 ///
332 /// \param entity_path Path to the entity in the space hierarchy.
333 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
334 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
335 ///
336 /// @see try_log, log_static, try_log_with_static
337 template <typename... Ts>
338 void log(std::string_view entity_path, const Ts&... archetypes_or_collections) const {
339 if (!is_enabled()) {
340 return;
341 }
342 try_log_with_static(entity_path, false, archetypes_or_collections...).handle();
343 }
344
345 template <typename... Ts>
346 [[deprecated("Use `log_static` instead")]] void log_timeless(
347 std::string_view entity_path, const Ts&... archetypes_or_collections
348 ) const {
349 return log_static(entity_path, archetypes_or_collections...);
350 }
351
352 /// Logs one or more archetype and/or component batches as static data.
353 ///
354 /// Like `log` but logs the data as static:
355 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
356 /// any temporal data of the same type.
357 ///
358 /// Failures are handled with `Error::handle`.
359 ///
360 /// \param entity_path Path to the entity in the space hierarchy.
361 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
362 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
363 ///
364 /// @see log, try_log_static, try_log_with_static
365 template <typename... Ts>
366 void log_static(std::string_view entity_path, const Ts&... archetypes_or_collections)
367 const {
368 if (!is_enabled()) {
369 return;
370 }
371 try_log_with_static(entity_path, true, archetypes_or_collections...).handle();
372 }
373
374 /// Logs one or more archetype and/or component batches.
375 ///
376 /// See `log` for more information.
377 /// Unlike `log` this method returns an error if an error occurs during serialization or logging.
378 ///
379 /// \param entity_path Path to the entity in the space hierarchy.
380 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
381 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
382 ///
383 /// @see log, try_log_static, try_log_with_static
384 template <typename... Ts>
385 Error try_log(std::string_view entity_path, const Ts&... archetypes_or_collections) const {
386 if (!is_enabled()) {
387 return Error::ok();
388 }
389 return try_log_with_static(entity_path, false, archetypes_or_collections...);
390 }
391
392 template <typename... Ts>
393 [[deprecated("Use `try_log_static` instead")]] Error try_log_timeless(
394 std::string_view entity_path, const Ts&... archetypes_or_collections
395 ) const {
396 return try_log_static(entity_path, archetypes_or_collections...);
397 }
398
399 /// Logs one or more archetype and/or component batches as static data, returning an error.
400 ///
401 /// See `log`/`log_static` for more information.
402 /// Unlike `log_static` this method returns if an error occurs during serialization or logging.
403 ///
404 /// \param entity_path Path to the entity in the space hierarchy.
405 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
406 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
407 /// \returns An error if an error occurs during serialization or logging.
408 ///
409 /// @see log_static, try_log, try_log_with_static
410 template <typename... Ts>
411 Error try_log_static(std::string_view entity_path, const Ts&... archetypes_or_collections)
412 const {
413 if (!is_enabled()) {
414 return Error::ok();
415 }
416 return try_log_with_static(entity_path, true, archetypes_or_collections...);
417 }
418
419 template <typename... Ts>
420 [[deprecated("Use `log_with_static` instead")]] void log_with_timeless(
421 std::string_view entity_path, bool timeless, const Ts&... archetypes_or_collections
422 ) const {
423 return log_with_static(entity_path, timeless, archetypes_or_collections...);
424 }
425
426 /// Logs one or more archetype and/or component batches optionally static, returning an error.
427 ///
428 /// See `log`/`log_static` for more information.
429 /// Returns an error if an error occurs during serialization or logging.
430 ///
431 /// \param entity_path Path to the entity in the space hierarchy.
432 /// \param static_ If true, the logged components will be static.
433 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
434 /// any temporal data of the same type.
435 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
436 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
437 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
438 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
439 ///
440 /// @see log, try_log, log_static, try_log_static
441 template <typename... Ts>
443 std::string_view entity_path, bool static_, const Ts&... archetypes_or_collections
444 ) const {
445 try_log_with_static(entity_path, static_, archetypes_or_collections...).handle();
446 }
447
448 template <typename... Ts>
449 [[deprecated("Use `try_log_with_static` instead")]] Error try_log_with_timeless(
450 std::string_view entity_path, bool static_, const Ts&... archetypes_or_collections
451 ) const {
452 return try_log_with_static(entity_path, static_, archetypes_or_collections...);
453 }
454
455 /// Logs one or more archetype and/or component batches optionally static, returning an error.
456 ///
457 /// See `log`/`log_static` for more information.
458 /// Returns an error if an error occurs during serialization or logging.
459 ///
460 /// \param entity_path Path to the entity in the space hierarchy.
461 /// \param static_ If true, the logged components will be static.
462 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
463 /// any temporal data of the same type.
464 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
465 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
466 /// \param archetypes_or_collections Any type for which the `AsComponents<T>` trait is implemented.
467 /// This is the case for any archetype or `std::vector`/`std::array`/C-array of components implements.
468 /// \returns An error if an error occurs during serialization or logging.
469 ///
470 /// @see log, try_log, log_static, try_log_static
471 template <typename... Ts>
473 std::string_view entity_path, bool static_, const Ts&... archetypes_or_collections
474 ) const {
475 if (!is_enabled()) {
476 return Error::ok();
477 }
478 std::vector<DataCell> serialized_batches;
479 Error err;
480 (
481 [&] {
482 if (err.is_err()) {
483 return;
484 }
485
486 const Result<std::vector<DataCell>> serialization_result =
487 AsComponents<Ts>().serialize(archetypes_or_collections);
488 if (serialization_result.is_err()) {
489 err = serialization_result.error;
490 return;
491 }
492
493 if (serialized_batches.empty()) {
494 // Fast path for the first batch (which is usually the only one!)
495 serialized_batches = std::move(serialization_result.value);
496 } else {
497 serialized_batches.insert(
498 serialized_batches.end(),
499 std::make_move_iterator(serialization_result.value.begin()),
500 std::make_move_iterator(serialization_result.value.end())
501 );
502 }
503 }(),
504 ...
505 );
506 RR_RETURN_NOT_OK(err);
507
508 return try_log_serialized_batches(entity_path, static_, std::move(serialized_batches));
509 }
510
511 /// Logs several serialized batches batches, returning an error on failure.
512 ///
513 /// This is a more low-level API than `log`/`log_static\ and requires you to already serialize the data
514 /// ahead of time.
515 ///
516 /// \param entity_path Path to the entity in the space hierarchy.
517 /// \param static_ If true, the logged components will be static.
518 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
519 /// any temporal data of the same type.
520 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
521 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
522 /// \param batches The serialized batches to log.
523 ///
524 /// \see `log`, `try_log`, `log_static`, `try_log_static`, `try_log_with_static`
526 std::string_view entity_path, bool static_, std::vector<DataCell> batches
527 ) const;
528
529 /// Bottom level API that logs raw data cells to the recording stream.
530 ///
531 /// In order to use this you need to pass serialized Arrow data cells.
532 ///
533 /// \param entity_path Path to the entity in the space hierarchy.
534 /// \param num_data_cells Number of data cells passed in.
535 /// \param data_cells The data cells to log.
536 /// \param inject_time
537 /// If set to `true`, the row's timestamp data will be overridden using the recording
538 /// streams internal clock.
539 ///
540 /// \see `try_log_serialized_batches`
542 std::string_view entity_path, size_t num_data_cells, const DataCell* data_cells,
543 bool inject_time
544 ) const;
545
546 /// Logs the file at the given `path` using all `DataLoader`s available.
547 ///
548 /// A single `path` might be handled by more than one loader.
549 ///
550 /// This method blocks until either at least one `DataLoader` starts streaming data in
551 /// or all of them fail.
552 ///
553 /// See <https://www.rerun.io/docs/reference/data-loaders/overview> for more information.
554 ///
555 /// \param filepath Path to the file to be logged.
556 /// \param entity_path_prefix What should the logged entity paths be prefixed with?
557 /// \param static_ If true, the logged components will be static.
558 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
559 /// any temporal data of the same type.
560 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
561 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
562 ///
563 /// \see `try_log_file_from_path`
565 const std::filesystem::path& filepath,
566 std::string_view entity_path_prefix = std::string_view(), bool static_ = false
567 ) const {
568 try_log_file_from_path(filepath, entity_path_prefix, static_).handle();
569 }
570
571 /// Logs the file at the given `path` using all `DataLoader`s available.
572 ///
573 /// A single `path` might be handled by more than one loader.
574 ///
575 /// This method blocks until either at least one `DataLoader` starts streaming data in
576 /// or all of them fail.
577 ///
578 /// See <https://www.rerun.io/docs/reference/data-loaders/overview> for more information.
579 ///
580 /// \param filepath Path to the file to be logged.
581 /// \param entity_path_prefix What should the logged entity paths be prefixed with?
582 /// \param static_ If true, the logged components will be static.
583 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
584 /// any temporal data of the same type.
585 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
586 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
587 ///
588 /// \see `log_file_from_path`
590 const std::filesystem::path& filepath,
591 std::string_view entity_path_prefix = std::string_view(), bool static_ = false
592 ) const;
593
594 /// Logs the given `contents` using all `DataLoader`s available.
595 ///
596 /// A single `path` might be handled by more than one loader.
597 ///
598 /// This method blocks until either at least one `DataLoader` starts streaming data in
599 /// or all of them fail.
600 ///
601 /// See <https://www.rerun.io/docs/reference/data-loaders/overview> for more information.
602 ///
603 /// \param filepath Path to the file that the `contents` belong to.
604 /// \param contents Contents to be logged.
605 /// \param contents_size Size in bytes of the `contents`.
606 /// \param entity_path_prefix What should the logged entity paths be prefixed with?
607 /// \param static_ If true, the logged components will be static.
608 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
609 /// any temporal data of the same type.
610 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
611 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
612 ///
613 /// \see `try_log_file_from_contents`
615 const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size,
616 std::string_view entity_path_prefix = std::string_view(), bool static_ = false
617 ) const {
619 filepath,
620 contents,
621 contents_size,
622 entity_path_prefix,
623 static_
624 )
625 .handle();
626 }
627
628 /// Logs the given `contents` using all `DataLoader`s available.
629 ///
630 /// A single `path` might be handled by more than one loader.
631 ///
632 /// This method blocks until either at least one `DataLoader` starts streaming data in
633 /// or all of them fail.
634 ///
635 /// See <https://www.rerun.io/docs/reference/data-loaders/overview> for more information.
636 ///
637 /// \param filepath Path to the file that the `contents` belong to.
638 /// \param contents Contents to be logged.
639 /// \param contents_size Size in bytes of the `contents`.
640 /// \param entity_path_prefix What should the logged entity paths be prefixed with?
641 /// \param static_ If true, the logged components will be static.
642 /// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
643 /// any temporal data of the same type.
644 /// Otherwise, the data will be timestamped automatically with `log_time` and `log_tick`.
645 /// Additional timelines set by `set_time_sequence` or `set_time` will also be included.
646 ///
647 /// \see `log_file_from_contents`
649 const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size,
650 std::string_view entity_path_prefix = std::string_view(), bool static_ = false
651 ) const;
652
653 /// @}
654
655 private:
656 RecordingStream(uint32_t id, StoreKind store_kind);
657
658 uint32_t _id;
659 StoreKind _store_kind;
660 bool _enabled;
661 };
662} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:89
void handle() const
Handle this error based on the set log handler.
bool is_err() const
Returns true if the code is not Ok.
Definition error.hpp:125
static Error ok()
Creates a new error set to ok.
Definition error.hpp:110
A RecordingStream handles everything related to logging data into Rerun.
Definition recording_stream.hpp:57
Error spawn(const SpawnOptions &options={}, float flush_timeout_sec=2.0) const
Spawns a new Rerun Viewer process from an executable available in PATH, then connects to it over TCP.
Error try_log_data_row(std::string_view entity_path, size_t num_data_cells, const DataCell *data_cells, bool inject_time) const
Bottom level API that logs raw data cells to the recording stream.
void log_file_from_path(const std::filesystem::path &filepath, std::string_view entity_path_prefix=std::string_view(), bool static_=false) const
Logs the file at the given path using all DataLoaders available.
Definition recording_stream.hpp:564
bool is_enabled() const
Returns whether the recording stream is enabled.
Definition recording_stream.hpp:96
Error try_log_static(std::string_view entity_path, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches as static data, returning an error.
Definition recording_stream.hpp:411
void disable_timeline(std::string_view timeline_name) const
Stops logging to the specified timeline for subsequent log calls.
void reset_time() const
Clears out the current time of the recording, for the current calling thread.
Error try_log_serialized_batches(std::string_view entity_path, bool static_, std::vector< DataCell > batches) const
Logs several serialized batches batches, returning an error on failure.
Error to_stdout() const
Stream all log-data to standard output.
Error try_log_file_from_path(const std::filesystem::path &filepath, std::string_view entity_path_prefix=std::string_view(), bool static_=false) const
Logs the file at the given path using all DataLoaders available.
Error save(std::string_view path) const
Stream all log-data to a given .rrd file.
void log_with_static(std::string_view entity_path, bool static_, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches optionally static, returning an error.
Definition recording_stream.hpp:442
StoreKind kind() const
Returns the store kind as passed during construction.
Definition recording_stream.hpp:88
void log(std::string_view entity_path, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:338
Error spawn(const SpawnOptions &options={}, std::chrono::duration< TRep, TPeriod > flush_timeout=std::chrono::seconds(2)) const
Definition recording_stream.hpp:164
void log_file_from_contents(const std::filesystem::path &filepath, const std::byte *contents, size_t contents_size, std::string_view entity_path_prefix=std::string_view(), bool static_=false) const
Logs the given contents using all DataLoaders available.
Definition recording_stream.hpp:614
Error try_log(std::string_view entity_path, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:385
void flush_blocking() const
Initiates a flush the batching pipeline and waits for it to propagate.
void set_time_nanos(std::string_view timeline_name, int64_t nanos) const
Set the current time of the recording, for the current calling thread.
void set_time(std::string_view timeline_name, std::chrono::duration< TRep, TPeriod > time) const
Set the current time of the recording, for the current calling thread.
Definition recording_stream.hpp:238
void log_static(std::string_view entity_path, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches as static data.
Definition recording_stream.hpp:366
static RecordingStream & current(StoreKind store_kind=StoreKind::Recording)
Retrieves the most appropriate globally available recording stream for the given kind.
RecordingStream(std::string_view app_id, std::string_view recording_id=std::string_view(), StoreKind store_kind=StoreKind::Recording)
Creates a new recording stream to log to.
void set_thread_local() const
Replaces the currently active recording for this stream's store kind in the thread-local scope with t...
void set_time(std::string_view timeline_name, std::chrono::time_point< TClock > time) const
Set the current time of the recording, for the current calling thread.
Definition recording_stream.hpp:224
void set_time_seconds(std::string_view timeline_name, double seconds) const
Set the current time of the recording, for the current calling thread.
Error try_log_with_static(std::string_view entity_path, bool static_, const Ts &... archetypes_or_collections) const
Logs one or more archetype and/or component batches optionally static, returning an error.
Definition recording_stream.hpp:472
Error try_log_file_from_contents(const std::filesystem::path &filepath, const std::byte *contents, size_t contents_size, std::string_view entity_path_prefix=std::string_view(), bool static_=false) const
Logs the given contents using all DataLoaders available.
void set_global() const
Replaces the currently active recording for this stream's store kind in the global scope with this on...
Error connect(std::string_view tcp_addr="127.0.0.1:9876", float flush_timeout_sec=2.0) const
Connect to a remote Rerun Viewer on the given ip:port.
void set_time_sequence(std::string_view timeline_name, int64_t sequence_nr) const
Set the current time of the recording, for the current calling thread.
A class for representing either a usable value, or an error.
Definition result.hpp:14
bool is_err() const
Returns true if error is not set to rerun::ErrorCode::Ok, implying that no value is contained,...
Definition result.hpp:44
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:21
Arrow-encoded data of a single batch components for a single entity.
Definition data_cell.hpp:21
Options to control the behavior of spawn.
Definition spawn_options.hpp:17