mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
cabana: segment live stream logging (#28407)
old-commit-hash: b7a2a921ecd9576799922287fd43d18c75c0042b
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user