Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions rosbag2_transport/src/rosbag2_transport/bag_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
#include <unordered_set>
#include <utility>
#include <vector>
#include <cstdio>
#include <cinttypes>

#include "rosbag2_cpp/reader.hpp"
#include "rosbag2_cpp/writer.hpp"
#include "rosbag2_transport/reader_writer_factory.hpp"
#include "rosbag2_transport/topic_filter.hpp"


namespace
{

Expand Down Expand Up @@ -177,9 +180,31 @@ void perform_rewrite(

auto topic_outputs = setup_topic_filtering(input_bags, output_bags);

// Sum total message count across all input bags for progress reporting
// Sum total message count across all input bags for progress reporting

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double comment

uint64_t total_messages = 0;
for (const auto & [reader, storage_options] : input_bags) {
if (reader) {
const auto & metadata = reader->get_metadata();
for (const auto & topic_info : metadata.topics_with_message_count) {
total_messages += topic_info.message_count;
}
}
}
if (total_messages > 0) {
fprintf(stdout, "Converting bag: 0%% (0 / %" PRIu64 " messages)", total_messages);
fflush(stdout);
} else {
Comment thread
Sourav0607 marked this conversation as resolved.
fprintf(stdout, "Converting bag: starting (total unknown)...");
fflush(stdout);
}

std::vector<std::shared_ptr<rosbag2_storage::SerializedBagMessage>> next_messages;
next_messages.resize(input_bags.size(), nullptr);

uint64_t processed = 0;
int last_printed_pct = 0;

std::shared_ptr<rosbag2_storage::SerializedBagMessage> next_msg;
while ((next_msg = get_next(input_bags, next_messages))) {
auto iterator = topic_outputs.find(next_msg->topic_name);
Expand All @@ -188,7 +213,21 @@ void perform_rewrite(
writer->write(next_msg);
}
}
++processed;

if (total_messages > 0) {
int pct = static_cast<int>((processed * 100) / total_messages);
if (pct > last_printed_pct) {
fprintf(
stdout, "\rConverting bag: %3d%% (%" PRIu64 " / %" PRIu64 " messages) ",
pct, processed, total_messages);
fflush(stdout);
last_printed_pct = pct;
}
}
}
fprintf(
stdout, "\nConverting bag: done (%" PRIu64 " messages written)\n", processed);
Comment thread
Sourav0607 marked this conversation as resolved.
}

} // namespace
Expand Down