cabana: segment live stream logging (#28407)

pull/28410/head
Dean Lee 2 years ago committed by GitHub
parent b792485dfd
commit b7a2a921ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      tools/cabana/streams/livestream.cc
  2. 4
      tools/cabana/streams/livestream.h

@ -1,10 +1,30 @@
#include "tools/cabana/streams/livestream.h"
struct LiveStream::Logger {
Logger() : start_ts(seconds_since_epoch()), segment_num(-1) {}
void write(const char *data, const size_t size) {
int n = (seconds_since_epoch() - start_ts) / 60.0;
if (std::exchange(segment_num, n) != segment_num) {
QString dir = QString("%1/%2--%3")
.arg(settings.log_path)
.arg(QDateTime::fromSecsSinceEpoch(start_ts).toString("yyyy-MM-dd--hh-mm-ss"))
.arg(n);
util::create_directories(dir.toStdString(), 0755);
fs.reset(new std::ofstream((dir + "/rlog").toStdString(), std::ios::binary | std::ios::out));
}
fs->write(data, size);
}
std::unique_ptr<std::ofstream> fs;
int segment_num;
uint64_t start_ts;
};
LiveStream::LiveStream(QObject *parent) : AbstractStream(parent) {
if (settings.log_livestream) {
std::string path = (settings.log_path + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd--hh-mm-ss") + "--0").toStdString();
util::create_directories(path, 0755);
fs.reset(new std::ofstream(path + "/rlog", std::ios::binary | std::ios::out));
logger = std::make_unique<Logger>();
}
stream_thread = new QThread(this);
@ -34,8 +54,8 @@ LiveStream::~LiveStream() {
// called in streamThread
void LiveStream::handleEvent(const char *data, const size_t size) {
if (fs) {
fs->write(data, size);
if (logger) {
logger->write(data, size);
}
std::lock_guard lk(lock);

@ -42,7 +42,6 @@ private:
std::vector<Event *> receivedEvents;
std::deque<Msg> receivedMessages;
std::unique_ptr<std::ofstream> fs;
int timer_id;
QBasicTimer update_timer;
@ -53,4 +52,7 @@ private:
bool post_last_event = true;
double speed_ = 1;
bool paused_ = false;
struct Logger;
std::unique_ptr<Logger> logger;
};

Loading…
Cancel
Save