|
|
@ -17,6 +17,21 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "logger.h" |
|
|
|
#include "logger.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <capnp/serialize.h> |
|
|
|
|
|
|
|
#include "cereal/gen/cpp/log.capnp.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void log_sentinel(LoggerState *s, cereal::Sentinel::SentinelType type) { |
|
|
|
|
|
|
|
capnp::MallocMessageBuilder msg; |
|
|
|
|
|
|
|
auto event = msg.initRoot<cereal::Event>(); |
|
|
|
|
|
|
|
event.setLogMonoTime(nanos_since_boot()); |
|
|
|
|
|
|
|
auto sen = event.initSentinel(); |
|
|
|
|
|
|
|
sen.setType(type); |
|
|
|
|
|
|
|
auto words = capnp::messageToFlatArray(msg); |
|
|
|
|
|
|
|
auto bytes = words.asBytes(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger_log(s, bytes.begin(), bytes.size(), true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int mkpath(char* file_path) { |
|
|
|
static int mkpath(char* file_path) { |
|
|
|
assert(file_path && *file_path); |
|
|
|
assert(file_path && *file_path); |
|
|
|
char* p; |
|
|
|
char* p; |
|
|
@ -125,6 +140,9 @@ fail: |
|
|
|
int logger_next(LoggerState *s, const char* root_path, |
|
|
|
int logger_next(LoggerState *s, const char* root_path, |
|
|
|
char* out_segment_path, size_t out_segment_path_len, |
|
|
|
char* out_segment_path, size_t out_segment_path_len, |
|
|
|
int* out_part) { |
|
|
|
int* out_part) { |
|
|
|
|
|
|
|
bool is_start_of_route = !s->cur_handle; |
|
|
|
|
|
|
|
if (!is_start_of_route) log_sentinel(s, cereal::Sentinel::SentinelType::END_OF_SEGMENT); |
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&s->lock); |
|
|
|
pthread_mutex_lock(&s->lock); |
|
|
|
s->part++; |
|
|
|
s->part++; |
|
|
|
|
|
|
|
|
|
|
@ -147,6 +165,8 @@ int logger_next(LoggerState *s, const char* root_path, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&s->lock); |
|
|
|
pthread_mutex_unlock(&s->lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_sentinel(s, is_start_of_route ? cereal::Sentinel::SentinelType::START_OF_ROUTE : cereal::Sentinel::SentinelType::START_OF_SEGMENT); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -171,6 +191,8 @@ void logger_log(LoggerState *s, uint8_t* data, size_t data_size, bool in_qlog) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void logger_close(LoggerState *s) { |
|
|
|
void logger_close(LoggerState *s) { |
|
|
|
|
|
|
|
log_sentinel(s, cereal::Sentinel::SentinelType::END_OF_ROUTE); |
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&s->lock); |
|
|
|
pthread_mutex_lock(&s->lock); |
|
|
|
free(s->init_data); |
|
|
|
free(s->init_data); |
|
|
|
if (s->cur_handle) { |
|
|
|
if (s->cur_handle) { |