9#include "as_components.hpp"
10#include "collection.hpp"
12#include "spawn_options.hpp"
17 enum class StoreKind {
63 RecordingStream(std::string_view app_id, StoreKind store_kind = StoreKind::Recording);
139 Error connect(std::string_view tcp_addr =
"127.0.0.1:9876",
float flush_timeout_sec = 2.0)
159 template <
typename TRep,
typename TPeriod>
162 std::chrono::duration<TRep, TPeriod> flush_timeout = std::chrono::seconds(2)
164 using seconds_float = std::chrono::duration<float>;
165 return spawn(options, std::chrono::duration_cast<seconds_float>(flush_timeout).count());
205 template <
typename TClock>
206 void set_time(std::string_view timeline_name, std::chrono::time_point<TClock> time)
const {
207 set_time(timeline_name, time.time_since_epoch());
219 template <
typename TRep,
typename TPeriod>
220 void set_time(std::string_view timeline_name, std::chrono::duration<TRep, TPeriod> time)
222 if constexpr (std::is_floating_point<TRep>::value) {
223 using seconds_double =
224 std::chrono::duration<double>;
227 std::chrono::duration_cast<seconds_double>(time).count()
232 std::chrono::duration_cast<std::chrono::nanoseconds>(time).count()
319 template <
typename... Ts>
320 void log(std::string_view entity_path,
const Ts&... archetypes_or_collectiones)
const {
340 template <
typename... Ts>
341 void log_timeless(std::string_view entity_path,
const Ts&... archetypes_or_collectiones)
359 template <
typename... Ts>
360 Error try_log(std::string_view entity_path,
const Ts&... archetypes_or_collectiones)
const {
378 template <
typename... Ts>
380 std::string_view entity_path,
const Ts&... archetypes_or_collectiones
402 template <
typename... Ts>
404 std::string_view entity_path,
bool timeless,
const Ts&... archetypes_or_collectiones
409 std::vector<DataCell> serialized_batches;
418 AsComponents<Ts>().serialize(archetypes_or_collectiones);
419 if (serialization_result.
is_err()) {
420 err = serialization_result.error;
424 if (serialized_batches.empty()) {
426 serialized_batches = std::move(serialization_result.value);
428 serialized_batches.insert(
429 serialized_batches.end(),
430 std::make_move_iterator(serialization_result.value.begin()),
431 std::make_move_iterator(serialization_result.value.end())
437 RR_RETURN_NOT_OK(err);
459 std::string_view entity_path,
bool timeless, std::vector<DataCell> batches
477 std::string_view entity_path,
size_t num_instances,
size_t num_data_cells,
478 const DataCell* data_cells,
bool inject_time
487 StoreKind _store_kind;
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:87
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:123
static Error ok()
Creates a new error set to ok.
Definition error.hpp:108
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.
bool is_enabled() const
Returns whether the recording stream is enabled.
Definition recording_stream.hpp:92
void log_timeless(std::string_view entity_path, const Ts &... archetypes_or_collectiones) const
Logs one or more archetype and/or component batches as timeless data.
Definition recording_stream.hpp:341
Error try_log_with_timeless(std::string_view entity_path, bool timeless, const Ts &... archetypes_or_collectiones) const
Logs one or more archetype and/or component batches optionally timeless, returning an error.
Definition recording_stream.hpp:403
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 save(std::string_view path) const
Stream all log-data to a given file.
Error try_log_serialized_batches(std::string_view entity_path, bool timeless, std::vector< DataCell > batches) const
Logs several serialized batches batches, returning an error on failure.
StoreKind kind() const
Returns the store kind as passed during construction.
Definition recording_stream.hpp:84
Error spawn(const SpawnOptions &options={}, std::chrono::duration< TRep, TPeriod > flush_timeout=std::chrono::seconds(2)) const
Definition recording_stream.hpp:160
Error try_log_timeless(std::string_view entity_path, const Ts &... archetypes_or_collectiones) const
Logs one or more archetype and/or component batches as timeless data, returning an error.
Definition recording_stream.hpp:379
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:220
RecordingStream(std::string_view app_id, StoreKind store_kind=StoreKind::Recording)
Creates a new recording stream to log to.
static RecordingStream & current(StoreKind store_kind=StoreKind::Recording)
Retrieves the most appropriate globally available recording stream for the given kind.
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:206
Error try_log_data_row(std::string_view entity_path, size_t num_instances, 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.
Error try_log(std::string_view entity_path, const Ts &... archetypes_or_collectiones) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:360
void set_time_seconds(std::string_view timeline_name, double seconds) const
Set the current time of the recording, for the current calling thread.
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 log(std::string_view entity_path, const Ts &... archetypes_or_collectiones) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:320
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:20
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