Skip to content

Make timestamp-indexed naming the default for split bagfiles #2198

@Tiryoh

Description

@Tiryoh

Description

This proposal introduces a new --split-naming option to improve the usability of split bagfiles by allowing timestamps to be included directly in the filenames.

Note

Supplementary comment:

  • This proposal changes course from adding a new CLI option to instead adopt timestamp-indexed naming (start-timestamp plus index) as the default behavior for split bagfiles. The goal is to improve human-readability and make filenames naturally sortable by time. To preserve backward compatibility during transition, an explicit flag to force the legacy serial naming (for example --split-naming=serial) may be provided, but the baseline behavior will be timestamp-indexed naming.

Currently, rosbag2 names split bagfiles using sequential numbering only (record_0.mcap, record_1.mcap, etc.). While this is functional, it makes it harder to quickly understand the time range each file covers when browsing files in a directory.

With the proposed --split-naming option, users could select between:

  • serial (default): Current behavior with sequential numbering.
  • timestamp-index: Each split bagfile name includes the start timestamp plus an index (e.g., record_2025-02-21-16-21-00_0.mcap).

This change would provide clearer, human-readable filenames, giving users immediate temporal context and helping those migrating from ROS1 workflows feel more at home. It is especially valuable in continuous operation scenarios, where stopping and restarting ros2 bag record frequently is not practical for systems with many topics or complex discovery.

Related Issues

This proposal is related to #1917 (Timestamp split bagfiles instead of serial numbering), which in turn is part of #1915 (Always-on recording). While all of these proposals aim to make bagfile naming more informative, they serve slightly different needs:

  • Purpose: Timestamp split bagfiles instead of serial numbering #1917 is designed for always-on recording, where session boundaries do not apply. This proposal focuses on general split recording scenarios where timestamp context is important.
  • Format: Timestamp split bagfiles instead of serial numbering #1917 suggests timestamp-only names (recording_20250221T162100Z.mcap). This proposal keeps both timestamp and index (recording_2025-02-21-16-21-00_0.mcap), ensuring both clarity and ordering.
  • Compatibility: These approaches can coexist under a unified --split-naming interface, giving users flexibility to choose the scheme that best fits their workflow.

Completion Criteria

  • Add --split-naming option to the ros2 bag record command.
  • Implement serial mode (default, maintains current behavior).
  • Implement timestamp-index mode with filesystem-safe timestamp format.
  • Ensure compatibility with all splitting mechanisms (--max-bag-duration, --max-bag-size, manual splitting via ~/split_bagfile).
  • Preserve backward compatibility by defaulting to serial.
  • Add appropriate unit and integration tests.
  • Update documentation and CLI help text.

Implementation Notes / Suggestions

  • Timestamps should be filesystem-safe and sortable (suggested: YYYY-MM-DD-HH-mm-ss).
  • Implementation would involve extending the SequentialWriter to handle naming modes.
  • Use std::strftime or similar for formatting.
  • Recommend UTC timestamps for consistency across environments.
  • Timestamp should reflect the start time of each bagfile.
  • Index should always be included to ensure uniqueness, even if multiple splits occur in the same second.

Testing Notes / Suggestions

  • Unit tests: Verify filename generation for both modes.

  • Integration tests: Confirm behavior with size, duration, and manual splits.

  • Edge cases:

    • Rapid splits (sub-second).
    • Cross-platform filesystem compatibility.
    • Uniqueness guarantees under load.
  • Backward compatibility: Verify unchanged behavior when --split-naming is not specified.

  • Playback compatibility: Ensure generated bagfiles can be played back regardless of naming mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions