mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 02:16:53 +08:00
logger: store full file name in logger, remove it from log writer
- also add log file to the status output
This commit is contained in:
@@ -82,16 +82,15 @@ LogWriter::~LogWriter()
|
|||||||
|
|
||||||
void LogWriter::start_log(const char *filename)
|
void LogWriter::start_log(const char *filename)
|
||||||
{
|
{
|
||||||
::strncpy(_filename, filename, sizeof(_filename));
|
_fd = ::open(filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
|
||||||
_fd = ::open(_filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
|
|
||||||
|
|
||||||
if (_fd < 0) {
|
if (_fd < 0) {
|
||||||
PX4_ERR("Can't open log file %s", _filename);
|
PX4_ERR("Can't open log file %s", filename);
|
||||||
_should_run = false;
|
_should_run = false;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_INFO("Opened log file: %s", _filename);
|
PX4_INFO("Opened log file: %s", filename);
|
||||||
_should_run = true;
|
_should_run = true;
|
||||||
_running = true;
|
_running = true;
|
||||||
}
|
}
|
||||||
@@ -232,7 +231,7 @@ void LogWriter::run()
|
|||||||
PX4_WARN("error closing log file");
|
PX4_WARN("error closing log file");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_INFO("closed logfile: %s, bytes written: %zu", _filename, _total_written);
|
PX4_INFO("closed logfile, bytes written: %zu", _total_written);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ private:
|
|||||||
/* 512 didn't seem to work properly, 4096 should match the FAT cluster size */
|
/* 512 didn't seem to work properly, 4096 should match the FAT cluster size */
|
||||||
static constexpr size_t _min_write_chunk = 4096;
|
static constexpr size_t _min_write_chunk = 4096;
|
||||||
|
|
||||||
char _filename[64];
|
|
||||||
int _fd = -1;
|
int _fd = -1;
|
||||||
uint8_t *_buffer = nullptr;
|
uint8_t *_buffer = nullptr;
|
||||||
const size_t _buffer_size;
|
const size_t _buffer_size;
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ void Logger::print_statistics()
|
|||||||
float mebibytes = kibibytes / 1024.0f;
|
float mebibytes = kibibytes / 1024.0f;
|
||||||
float seconds = ((float)(hrt_absolute_time() - _start_time)) / 1000000.0f;
|
float seconds = ((float)(hrt_absolute_time() - _start_time)) / 1000000.0f;
|
||||||
|
|
||||||
|
PX4_INFO("Log file: %s/%s", _log_dir, _log_file_name);
|
||||||
PX4_INFO("Wrote %4.2f MiB (avg %5.2f KiB/s)", (double)mebibytes, (double)(kibibytes / seconds));
|
PX4_INFO("Wrote %4.2f MiB (avg %5.2f KiB/s)", (double)mebibytes, (double)(kibibytes / seconds));
|
||||||
PX4_INFO("Since last status: dropouts: %zu (max len: %.3f s), max used buffer: %zu / %zu B",
|
PX4_INFO("Since last status: dropouts: %zu (max len: %.3f s), max used buffer: %zu / %zu B",
|
||||||
_write_dropouts, (double)_max_dropout_duration, _high_water, _writer.get_buffer_size());
|
_write_dropouts, (double)_max_dropout_duration, _high_water, _writer.get_buffer_size());
|
||||||
@@ -942,9 +943,10 @@ int Logger::get_log_file_name(char *file_name, size_t file_name_size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char log_file_name[64] = "";
|
char log_file_name_time[16] = "";
|
||||||
strftime(log_file_name, sizeof(log_file_name), "%H_%M_%S", &tt);
|
strftime(log_file_name_time, sizeof(log_file_name_time), "%H_%M_%S", &tt);
|
||||||
snprintf(file_name, file_name_size, "%s/%s%s.ulg", _log_dir, log_file_name, replay_suffix);
|
snprintf(_log_file_name, sizeof(_log_file_name), "%s%s.ulg", log_file_name_time, replay_suffix);
|
||||||
|
snprintf(file_name, file_name_size, "%s/%s", _log_dir, _log_file_name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (create_log_dir(nullptr)) {
|
if (create_log_dir(nullptr)) {
|
||||||
@@ -956,7 +958,8 @@ int Logger::get_log_file_name(char *file_name, size_t file_name_size)
|
|||||||
/* look for the next file that does not exist */
|
/* look for the next file that does not exist */
|
||||||
while (file_number <= MAX_NO_LOGFILE) {
|
while (file_number <= MAX_NO_LOGFILE) {
|
||||||
/* format log file path: e.g. /fs/microsd/sess001/log001.ulg */
|
/* format log file path: e.g. /fs/microsd/sess001/log001.ulg */
|
||||||
snprintf(file_name, file_name_size, "%s/log%03u%s.ulg", _log_dir, file_number, replay_suffix);
|
snprintf(_log_file_name, sizeof(_log_file_name), "log%03u%s.ulg", file_number, replay_suffix);
|
||||||
|
snprintf(file_name, file_name_size, "%s/%s", _log_dir, _log_file_name);
|
||||||
|
|
||||||
if (!file_exist(file_name)) {
|
if (!file_exist(file_name)) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ private:
|
|||||||
int _msg_buffer_len = 0;
|
int _msg_buffer_len = 0;
|
||||||
bool _task_should_exit = true;
|
bool _task_should_exit = true;
|
||||||
char _log_dir[LOG_DIR_LEN];
|
char _log_dir[LOG_DIR_LEN];
|
||||||
|
char _log_file_name[32];
|
||||||
bool _has_log_dir = false;
|
bool _has_log_dir = false;
|
||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
bool _was_armed = false;
|
bool _was_armed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user