CRecorder – Recording Infrastructure

The CRecorder class is a static recording manager responsible for setting up configuring and controling the capturing runtime data into persistent storage. The class is globally accessible and operates as a centralized recording controller.

It provides:

  • Lifecycle control (start / stop)
  • Output path configuration
  • Frame-based flush policy
  • Change-based filtering
  • Selective streams, blocks and elements registration for recording
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

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);
};
    

Method Breakdown

Method Description
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. SetRecorderPath({"D:/rec", "E:/rec"}) (a list of strings) sets several drives, one directory each (the first is the recording directory; a drive keeps the settings config.json gave it); items choose among them with storage. Takes effect at the next recording session (StartRecording()).
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. Allows explicit engineering/raw size declaration and optional “record only if received” gating.
SetRecordingRate(name, recRate)
SetRecordingRate(name, periodMs)
How often the item's data changes at most (also the last argument recRate of AddRecordingItem / SetRecordingProperties): a number = ms ("33.3", or 33.3 for the double overload), "30hz", "1khz", "1mhz", or "auto" (the block's framePerMS in streams.json). The copy of a big item (a camera image) may then take that long instead of one minor frame, on its own capture lane. "" / 0 = one minor frame (as before); nullptr in AddRecordingItem keeps the value of config.json. SetRecordingRate returns false (and reports) when the item was not added or the text is not valid. Like the other properties: set them outside the frame loop, then PrepareRecording() + StartRecording(false). See Big items: recRate.
AddRecordingItem(...) Registers a single recordable entity within the recorder configuration. The itemName represents the logical data source name (stream / block / element identifier) exactly as defined in the system.

Size Control:
  • engSize = -1 → Use the predefined engineering size as defined in the project DBSim.
  • engSize = 0 → Disable engineering value recording.
  • engSize > 0 → Record exactly the specified number of bytes for the engineering value.
The same logic applies to rawSize:
  • rawSize = -1 → Use predefined raw size as defined in the project DBSim.
  • rawSize = 0 → Disable raw value recording.
  • rawSize > 0 → Record the exact number of raw bytes specified.
Conditional Recording:
bRecordOnlyIfReceived — Default true. The item is written only if new data was received during the current frame (the block's msgCounter changed: a stream read, a successful send, or a model that increments it). Pass false, or set recordOnlyOnChange: false on the item or in the recorder section of config.json, to record the item every frame. A recordOnlyOnChange in the recorder section of config.json overrides the item's flag. This prevents recording stale or repeated values in event-driven or bus-based streams.

Several drives:
storage — the drives the item is spread over when config.json recorder lists several drives (each with its own path and setup): "0", "0-1", "0,2-4,6,*". The records go to the next drive with room, so a big item (a camera frame) can be recorded faster than one device writes. nullptr keeps the storage of the item's config.json entry, else the recorder storage, else drive 0. See Several drives.

Recording Policy Controls

1. Frame-Based Flushing

Recording is aligned to simulation minor frames. The flush interval determines how often buffered data is committed to disk.

2. Change-Based Filtering

When SetRecordOnlyIfChanged(true) is enabled, identical consecutive values are not written again. This is especially effective for slow-changing or state-like signals.

3. Receive-Based Filtering

The bRecordOnlyIfReceived flag ensures an item is recorded only when fresh data is received during the frame, preventing duplication of stale values.

4. Console report, start, big items (config.json "recorder")

KeyValuesWhat it does
report0 (default), 1, 20: nothing. 1: the recorder configuration when a session opens (table "Recorder config.json setup": files, capture, frame ring, recRate lane and its ring, I/O method per drive) and the totals per drive when it closes. 2: the same and the detailed table of the recorded items (item, kind, eng (B), raw (B), rate (ms), on change, drives, max (MB/s), note). Errors and warnings are always shown.
startRecording"boot" (default), "model"boot: the first session opens when the engine runs. model: no session at start; the first one opens when a model calls CRecorder::StartRecording() (or a network record: command). Use model when a model starts the recording itself: with boot that call closes the boot session and opens a second one (two folders, two reports).
recRate (per item)ms, "30hz", "auto"How often the item's data changes at most: its copy may take that long (own capture lane). Only for records of captureThresholdKB (256 KB) and more, e.g. camera images; a smaller item with a recRate (INS blocks) is copied in the frame, every frame it changes, so no message is lost. The detailed table marks it "small record: copied every frame it changes".

All keys: config.html, Storage driver settings; big items: recRate.

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();
    

Best Practices

Architectural Role

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.