Skip to content

Commit

Permalink
add shared_recording cpp example
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Nov 29, 2023
1 parent 8b2e238 commit 157b0ca
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
add_subdirectory(clock)
add_subdirectory(custom_collection_adapter)
add_subdirectory(dna)
add_subdirectory(shared_recording)
add_subdirectory(minimal)
add_subdirectory(spawn_viewer)
add_subdirectory(custom_collection_adapter)

add_custom_target(examples)

add_dependencies(examples example_clock)
add_dependencies(examples example_custom_collection_adapter)
add_dependencies(examples example_dna)
add_dependencies(examples example_shared_recording)
add_dependencies(examples example_minimal)
add_dependencies(examples example_spawn_viewer)
add_dependencies(examples example_custom_collection_adapter)
32 changes: 32 additions & 0 deletions examples/cpp/shared_recording/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.16...3.27)

# If you use the example outside of the Rerun SDK you need to specify
# where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable.
# This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake.
if(DEFINED RERUN_REPOSITORY)
add_executable(example_shared_recording main.cpp)
rerun_strict_warning_settings(example_shared_recording)
else()
project(example_shared_recording LANGUAGES CXX)

add_executable(example_shared_recording main.cpp)

# Set the path to the rerun_c build.
set(RERUN_CPP_URL "https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip" CACHE STRING "URL to the rerun_cpp zip.")
option(RERUN_FIND_PACKAGE "Whether to use find_package to find a preinstalled rerun package (instead of using FetchContent)." OFF)

if(RERUN_FIND_PACKAGE)
find_package(rerun_sdk REQUIRED)
else()
# Download the rerun_sdk
include(FetchContent)
FetchContent_Declare(rerun_sdk URL ${RERUN_CPP_URL})
FetchContent_MakeAvailable(rerun_sdk)
endif()

# Rerun requires at least C++17, but it should be compatible with newer versions.
set_property(TARGET example_shared_recording PROPERTY CXX_STANDARD 17)
endif()

# Link against rerun_sdk.
target_link_libraries(example_shared_recording PRIVATE rerun_sdk)
26 changes: 26 additions & 0 deletions examples/cpp/shared_recording/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Shared Recording
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/shared_recording/src/main.rs?speculative-link
cpp: https://github.com/rerun-io/rerun/tree/latest/examples/cpp/shared_recording/main.cpp?speculative-link
---

<picture>
<img src="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/full.png" alt="">
<source media="(max-width: 480px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/1200w.png">
</picture>

This example demonstrates how to use `RecordingId`s to create a single shared recording across multiple processes.

To build it from a checkout of the repository (requires a Rust toolchain):
```bash
cmake .
cmake --build . --target example_shared_recording
```

Run the following multiple times, and you'll see that each invocation adds data to the existing recording rather than creating a new one:
```bash
./examples/cpp/shared_recording/example_shared_recording
```
22 changes: 22 additions & 0 deletions examples/cpp/shared_recording/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <unistd.h>
#include <iostream>
#include <sstream>

#include <rerun.hpp>
#include <rerun/demo_utils.hpp>

using rerun::demo::grid3d;

int main() {
const auto rec =
rerun::RecordingStream("rerun_example_shared_recording", "my_shared_recording");
rec.spawn().exit_on_failure();

int pid = getpid();
std::ostringstream oss;
oss << "Hello from " << pid;

rec.log("updates", rerun::TextLog(oss.str()));

std::cout << "Run me again to append more data to the recording!" << std::endl;
}

0 comments on commit 157b0ca

Please sign in to comment.