This guide explains how to configure the CRecorder class to capture simulation data efficiently, using frame-based flushing and change/receive-based filtering.

1. Understand CRecorder

CRecorder is a static, globally accessible recording manager responsible for setting up, configuring, and controlling the capture of runtime data into persistent storage. It provides:

The recorder is designed to minimize I/O overhead and reduce redundant writes while preserving deterministic frame-aligned recording.

Design characteristics: fully static interface, centralized state, frame-aware flushing, selective data capture, optimized for high-rate systems.

2. Know the Public API

class CRecorder
{
public:
    static void StartRecording();
    static void StopRecording();

    static void SetRecorderPath(const char* path);
    static void SetRecorderPath(const std::vector& drives);   // several drives: a directory each, the first is the recording directory
    static void SetRecordingFramesFlush(int iRecordingFlushEveryMinorFrame);
    static void SetRecordOnlyIfChanged(int bRecordOnlyIfChanged);
    static void SetRecordingProperties(const char* elementName,
                                       int64_t engSize = -1,
                                       int64_t rawSize = -1,
                                       bool bRecordOnlyIfReceived = true,
                                       const char* storage = nullptr,
                                       const char* recRate = nullptr);
    static void AddRecordingItem(const char* itemName,
                                 int64_t engSize = -1,
                                 int64_t rawSize = -1,
                                 bool bRecordOnlyIfReceived = true,
                                 const char* storage = nullptr,    // drives: "0,2-4,6,*" (config.json recorder "drives")
                                 const char* recRate = nullptr);   // how often the data changes: "33" (ms), "30hz", "auto"
    // same with the drives as flags (storage[i] true = written to drive i), also for SetRecordingProperties:
    static void AddRecordingItem(const char* itemName, int64_t engSize, int64_t rawSize,
                                 bool bRecordOnlyIfReceived, const std::vector& storage,
                                 const char* recRate = nullptr);
    // recRate of an item already added: text as above ("" = one minor frame), or the period in ms
    static bool SetRecordingRate(const char* itemName, const char* recRate);
    static bool SetRecordingRate(const char* itemName, double periodMs);
};
MethodDescription
StartRecording()Initializes internal buffers, opens output files, and begins frame-aligned recording.
StopRecording()Stops recording, flushes remaining buffered data, and closes resources safely.
SetRecorderPath(path)Defines the directory or base path where recording files will be created.
SetRecordingFramesFlush(n)Controls how often buffers are flushed to disk (every n minor frames). Lower values increase safety, higher values improve performance.
SetRecordOnlyIfChanged(flag)Default is true. If enabled, data is recorded only when its value changes between frames, reducing file size and I/O load.
SetRecordingProperties(...)Defines metadata for a logical element: explicit engineering/raw size and optional "record only if received" gating.
AddRecordingItem(...)Registers a single recordable entity (stream/block/element) by name, with size control and conditional recording (see below).
SetRecordingRate(...)How often an item's data changes ("33" ms, "30hz", "auto"): a big item's copy may take that long instead of one minor frame (see 3b).

3. Choose Size Control Settings

When calling AddRecordingItem or SetRecordingProperties, control how much data is captured per item:

Parameter ValueEffect
engSize = -1Use the predefined engineering size as defined in the project DBSim.
engSize = 0Disable engineering value recording.
engSize > 0Record exactly the specified number of bytes for the engineering value.
rawSize = -1Use predefined raw size as defined in the project DBSim.
rawSize = 0Disable raw value recording.
rawSize > 0Record the exact number of raw bytes specified.

Use bRecordOnlyIfReceived (default true; pass false to record the item every frame) to write an item only if new data arrived during the current frame — this prevents recording stale or repeated values in event-driven or bus-based streams.

3b. Record Big Items (recRate)

Each minor frame's copy must be finished before the next minor frame starts. A big item (a 10.6 MB camera image at a 1 ms frame) does not fit: the profile view shows many late captures and dropped frames in Recording drops while the ring stays almost empty. Tell the recorder how often the item's data really changes; its copy may then take that long, on its own capture lane, while the other items are still recorded every frame:

// in code (outside the frame loop), the camera's frame rate:
CRecorder::AddRecordingItem("CAM.cam.frame", frameSize, 0, true, nullptr, "30hz");
CRecorder::PrepareRecording();

// or in config.json, recorder "coredb":
"CAM.cam.frame": { "recRate": "30hz" }     // 33 = ms, "auto" = framePerMS of the block in streams.json

Declare the fastest rate the data can change at (a bursty camera: a little faster than its nominal rate). Data that changes while it is copied is dropped and counted as changed in the Recording rate items profile row. Set rateRingMB so its ring is allocated at init. Only records of captureThresholdKB (256 KB) and more go to the recRate lane; a small item with a recRate (an INS block) is copied in the frame, every frame it changes, so none of its messages is lost. Details: Big items: recRate.

3c. See What Is Recorded (report) and When It Starts (startRecording)

"recorder": {
  "report": 2,                 // 0 nothing, 1 the recorder configuration + close totals, 2 also the table of the recorded items
  "startRecording": "model"    // "boot" (default): record from the start; "model": the first session opens at CRecorder::StartRecording()
}

With "report": 2 the session start prints the table Recorder: recorded items Detailed report: item, kind, eng (B), raw (B), rate (ms), on change, drives, max (MB/s) and a note (automatic rate, one frame, small record). When a model starts the recording itself, use "startRecording": "model": with "boot" its StartRecording() closes the boot session and opens a second one (two folders, the tables twice).

4. Apply Recording Policy Controls

Frame-Based Flushing

Recording is aligned to simulation minor frames. Choose the flush interval based on your tradeoff:

Change-Based Filtering

Enable SetRecordOnlyIfChanged(true) so identical consecutive values are not written again — especially effective for slow-changing or state-like signals.

Receive-Based Filtering

Set bRecordOnlyIfReceived to ensure an item is recorded only when fresh data is received during the frame, preventing duplication of stale values.

5. Follow the Typical Usage Flow

// Configure recorder
CRecorder::SetRecorderPath("C:/records/session1");
CRecorder::SetRecordingFramesFlush(10);
CRecorder::SetRecordOnlyIfChanged(true);

// Define properties
CRecorder::SetRecordingProperties("FlightModel", 64, 64);
CRecorder::AddRecordingItem("Altitude", 8, 8);
CRecorder::AddRecordingItem("Velocity", 8, 8);

// Start capture
CRecorder::StartRecording();

// ... simulation runs ...

CRecorder::StopRecording();

5b. Record on Several Drives (Optional)

A big item (a camera frame) can be recorded faster than one device writes by spreading it over several drives. List the drives in config.json recorder and name per item the drives it uses:

"recorder": {
  "drives": [ "D:/rec/", "E:/rec/" ],          // each can be an object with its own ioMode, queueDepth, ringMB...
  "coredb": {
    "CAM.cam.frame": { "storage": "0-1" },     // split over both drives
    "IMU.*":         { "storage": "0" }         // only the first drive
  }
}

In code: CRecorder::SetRecorderPath({"D:/rec", "E:/rec"}) and CRecorder::AddRecordingItem("CAM.cam.frame", -1, 0, true, "0-1") (or a std::vector<bool> of drive flags). Each drive writes its own session folder with the same name; open the one on drive 0 in the Recording Viewer, which merges the drives. See Several drives and, for recordings copied away from their devices, Playing a copied recording.

6. Follow Best Practices

7. Treat the Recorder as Infrastructure

CRecorder should be treated as an infrastructure service rather than a business-logic component. Modules register their items declaratively, while the recorder enforces consistent storage format and timing alignment.