13#include "as_components.hpp"
14#include "component_column.hpp"
16#include "log_sink.hpp"
17#include "spawn_options.hpp"
18#include "time_column.hpp"
21 struct ComponentBatch;
23 enum class StoreKind {
67 static constexpr const char PROPERTIES_ENTITY_PATH[] =
"__properties/";
76 std::string_view app_id, std::string_view recording_id = std::string_view(),
77 StoreKind store_kind = StoreKind::Recording
153 template <
typename... Ts>
155 LogSink out_sinks[] = {sinks...};
156 uint32_t num_sinks =
sizeof...(Ts);
157 return try_set_sinks(out_sinks, num_sinks);
180 std::string_view bind_ip =
"0.0.0.0", uint16_t port = 9876,
181 std::string_view server_memory_limit =
"1GiB",
183 std::vector<std::string> cors_allow_origins = {}
196 template <
typename TRep,
typename TPeriod>
199 std::chrono::duration<TRep, TPeriod> flush_timeout = std::chrono::seconds(2)
201 using seconds_float = std::chrono::duration<float>;
202 return spawn(options, std::chrono::duration_cast<seconds_float>(flush_timeout).count());
266 template <
typename TRep,
typename TPeriod>
268 std::string_view timeline_name, std::chrono::duration<TRep, TPeriod> duration
270 auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
307 template <
typename TClock>
309 std::string_view timeline_name, std::chrono::time_point<TClock> timestamp
313 std::chrono::duration_cast<std::chrono::nanoseconds>(timestamp.time_since_epoch())
331 static_cast<int64_t
>(1e9 * seconds)
356 template <
typename TClock>
357 [[deprecated(
"Renamed to `set_time_timestamp`")]]
void set_time(
358 std::string_view timeline_name, std::chrono::time_point<TClock> time
360 set_time(timeline_name, time.time_since_epoch());
372 template <
typename TRep,
typename TPeriod>
373 [[deprecated(
"Renamed `set_time_duration`")]]
void set_time(
374 std::string_view timeline_name, std::chrono::duration<TRep, TPeriod> time
388 [[deprecated(
"Use either `set_time_duration_secs` or `set_time_timestamp_secs_since_epoch`"
404 "Use either `set_time_duration_nanos` or `set_time_timestamp_nanos_since_epoch`"
489 template <
typename... Ts>
490 void log(std::string_view entity_path,
const Ts&... as_components)
const {
511 template <
typename... Ts>
512 void log_static(std::string_view entity_path,
const Ts&... as_components)
const {
530 template <
typename... Ts>
531 Error try_log(std::string_view entity_path,
const Ts&... as_components)
const {
550 template <
typename... Ts>
574 template <
typename... Ts>
575 void log_with_static(std::string_view entity_path,
bool static_,
const Ts&... as_components)
597 template <
typename... Ts>
599 std::string_view entity_path,
bool static_,
const Ts&... as_components
604 std::vector<ComponentBatch> serialized_columns;
613 AsComponents<Ts>().as_batches(as_components);
614 if (serialization_result.
is_err()) {
615 err = serialization_result.error;
619 if (serialized_columns.empty()) {
621 serialized_columns = std::move(serialization_result.value).to_vector();
623 serialized_columns.insert(
624 serialized_columns.end(),
625 std::make_move_iterator(serialization_result.value.begin()),
626 std::make_move_iterator(serialization_result.value.end())
632 RR_RETURN_NOT_OK(err);
652 std::string_view entity_path,
bool static_, std::vector<ComponentBatch> batches
668 std::string_view entity_path,
size_t num_data_cells,
const ComponentBatch* data_cells,
691 const std::filesystem::path& filepath,
692 std::string_view entity_path_prefix = std::string_view(),
bool static_ =
false
716 const std::filesystem::path& filepath,
717 std::string_view entity_path_prefix = std::string_view(),
bool static_ =
false
741 const std::filesystem::path& filepath,
const std::byte* contents,
size_t contents_size,
742 std::string_view entity_path_prefix = std::string_view(),
bool static_ =
false
775 const std::filesystem::path& filepath,
const std::byte* contents,
size_t contents_size,
776 std::string_view entity_path_prefix = std::string_view(),
bool static_ =
false
798 template <
typename... Ts>
801 Ts... component_columns
823 template <
typename... Ts>
826 Ts... component_columns
828 if constexpr (
sizeof...(Ts) == 1) {
833 std::move(time_columns),
834 Collection(std::forward<Ts...>(component_columns...))
838 std::vector<ComponentColumn> flat_column_list;
843 std::is_constructible_v<Collection<ComponentColumn>, Ts>,
844 "Ts must be ComponentColumn or a collection thereof"
847 push_back_columns(flat_column_list, std::move(component_columns));
853 std::move(time_columns),
910 template <
typename... Ts>
922 template <
typename... Ts>
925 this->PROPERTIES_ENTITY_PATH + std::string(name),
965 Error try_set_sinks(
const LogSink* sinks, uint32_t num_sinks)
const;
968 static void push_back_columns(
971 for (
const auto& new_column : new_columns) {
972 component_columns.emplace_back(std::move(new_column));
976 static void push_back_columns(
977 std::vector<ComponentColumn>& component_columns, ComponentColumn new_column
979 component_columns.emplace_back(std::move(new_column));
985 StoreKind _store_kind;
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:103
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:139
static Error ok()
Creates a new error set to ok.
Definition error.hpp:124
A RecordingStream handles everything related to logging data into Rerun.
Definition recording_stream.hpp:63
Error try_log_with_static(std::string_view entity_path, bool static_, const Ts &... as_components) const
Logs one or more archetype and/or component batches optionally static, returning an error.
Definition recording_stream.hpp:598
Error try_send_property(std::string_view name, const Ts &... values) const
Set a property of a recording.
Definition recording_stream.hpp:923
void set_log_time_enabled(bool enabled) const
Enable or disable automatic injection of the log_time timeline into logged data.
Error try_send_columns(std::string_view entity_path, Collection< TimeColumn > time_columns, Collection< ComponentColumn > component_columns) const
Directly log a columns of data to Rerun.
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 Importers available.
Definition recording_stream.hpp:690
bool is_enabled() const
Returns whether the recording stream is enabled.
Definition recording_stream.hpp:107
void set_time_duration_nanos(std::string_view timeline_name, int64_t nanos) const
Set the index value of the given timeline as a duration in nanoseconds, for the current calling threa...
void send_property(std::string_view name, const Ts &... values) const
Set a property of a recording.
Definition recording_stream.hpp:911
Error try_send_recording_start_time_nanos(int64_t nanos) const
Set the start time of a recording.
Error try_log(std::string_view entity_path, const Ts &... as_components) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:531
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 to_stdout() const
Stream all log-data to standard output.
void send_columns(std::string_view entity_path, Collection< TimeColumn > time_columns, Collection< ComponentColumn > component_columns) const
Directly log a columns of data to Rerun.
Definition recording_stream.hpp:876
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 Importers available.
Error save(std::string_view path) const
Stream all log-data to a given .rrd file.
Error try_log_static(std::string_view entity_path, const Ts &... as_components) const
Logs one or more archetype and/or component batches as static data, returning an error.
Definition recording_stream.hpp:551
StoreKind kind() const
Returns the store kind as passed during construction.
Definition recording_stream.hpp:99
Error flush_blocking(float timeout_sec=std::numeric_limits< float >::infinity()) const
Initiates a flush the batching pipeline and waits for it to propagate.
Error spawn(const SpawnOptions &options={}, std::chrono::duration< TRep, TPeriod > flush_timeout=std::chrono::seconds(2)) const
Definition recording_stream.hpp:197
Error try_log_data_row(std::string_view entity_path, size_t num_data_cells, const ComponentBatch *data_cells, bool inject_time) const
Bottom level API that logs raw data cells to the recording stream.
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 Importers available.
Definition recording_stream.hpp:740
void set_time_timestamp_secs_since_epoch(std::string_view timeline_name, double seconds) const
Set the index value of the given timeline as seconds since Unix Epoch (1970), for the current calling...
Definition recording_stream.hpp:327
void set_time_duration_secs(std::string_view timeline_name, double secs) const
Set the index value of the given timeline as a duration in seconds, for the current calling thread.
Definition recording_stream.hpp:283
void set_time_duration(std::string_view timeline_name, std::chrono::duration< TRep, TPeriod > duration) const
Set the index value of the given timeline as a duration, for the current calling thread.
Definition recording_stream.hpp:267
Error set_sinks(const Ts &... sinks) const
Stream data to multiple sinks.
Definition recording_stream.hpp:154
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.
Definition recording_stream.hpp:406
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:373
Result< std::string > serve_grpc(std::string_view bind_ip="0.0.0.0", uint16_t port=9876, std::string_view server_memory_limit="1GiB", PlaybackBehavior playback_behavior=PlaybackBehavior::OldestFirst, std::vector< std::string > cors_allow_origins={}) const
Swaps the underlying sink for a gRPC server sink pre-configured to listen on rerun+http://{bind_ip}:{...
void send_recording_start_time_nanos(int64_t nanos) const
Set the start time of a recording.
Definition recording_stream.hpp:952
void log_with_static(std::string_view entity_path, bool static_, const Ts &... as_components) const
Logs one or more archetype and/or component batches optionally static, returning an error.
Definition recording_stream.hpp:575
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 log(std::string_view entity_path, const Ts &... as_components) const
Logs one or more archetype and/or component batches.
Definition recording_stream.hpp:490
void set_thread_local() const
Replaces the currently active recording for this stream's store kind in the thread-local scope with t...
Error try_send_recording_name(std::string_view name) const
Set the name of a recording.
Error try_log_serialized_batches(std::string_view entity_path, bool static_, std::vector< ComponentBatch > batches) const
Logs several serialized batches batches, returning an error on failure.
Error connect_grpc(std::string_view url="rerun+http://127.0.0.1:9876/proxy") const
Connect to a remote Rerun Viewer on the given URL.
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:357
Error spawn(const SpawnOptions &options={}) const
Spawns a new Rerun Viewer process from an executable available in PATH, then connects to it over gRPC...
void set_time_seconds(std::string_view timeline_name, double seconds) const
Set the current time of the recording, for the current calling thread.
Definition recording_stream.hpp:390
void set_time_timestamp_nanos_since_epoch(std::string_view timeline_name, int64_t nanos) const
Set the index value of the given timeline as nanoseconds since Unix Epoch (1970), for the current cal...
void send_columns(std::string_view entity_path, Collection< TimeColumn > time_columns, Ts... component_columns) const
Directly log a columns of data to Rerun.
Definition recording_stream.hpp:799
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 Importers available.
void send_recording_name(std::string_view name) const
Set the name of a recording.
Definition recording_stream.hpp:936
void set_global() const
Replaces the currently active recording for this stream's store kind in the global scope with this on...
void set_log_tick_enabled(bool enabled) const
Enable or disable automatic injection of the log_tick timeline into logged data.
void set_time_timestamp(std::string_view timeline_name, std::chrono::time_point< TClock > timestamp) const
Set the index value of the given timeline as a timestamp, for the current calling thread.
Definition recording_stream.hpp:308
void set_time_sequence(std::string_view timeline_name, int64_t sequence_nr) const
Set the index value of the given timeline as a sequence number, for the current calling thread.
Error try_send_columns(std::string_view entity_path, Collection< TimeColumn > time_columns, Ts... component_columns) const
Directly log a columns of data to Rerun.
Definition recording_stream.hpp:824
void log_static(std::string_view entity_path, const Ts &... as_components) const
Logs one or more archetype and/or component batches as static data.
Definition recording_stream.hpp:512
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:23
PlaybackBehavior
What happens when a client connects to a gRPC server.
Definition log_sink.hpp:12
@ OldestFirst
Start by playing back all old data, then send data that arrived during playback.
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
Arrow-encoded data of a column of components.
Definition component_column.hpp:20
A sink for log messages.
Definition log_sink.hpp:86
Options to control the behavior of spawn.
Definition spawn_options.hpp:17