PX4 Firmware
PX4 Autopilot Software http://px4.io
px4::logger::LogWriterFile Class Reference

Writes logging data to a file. More...

#include <log_writer_file.h>

Collaboration diagram for px4::logger::LogWriterFile:

Classes

class  LogFileBuffer
 

Public Member Functions

 LogWriterFile (size_t buffer_size)
 
 ~LogWriterFile ()
 
bool init ()
 
int thread_start ()
 start the thread More...
 
void thread_stop ()
 
void start_log (LogType type, const char *filename)
 
void stop_log (LogType type)
 
bool is_started (LogType type) const
 
int write_message (LogType type, void *ptr, size_t size, uint64_t dropout_start=0)
 
void lock ()
 
void unlock ()
 
void notify ()
 
size_t get_total_written (LogType type) const
 
size_t get_buffer_size (LogType type) const
 
size_t get_buffer_fill_count (LogType type) const
 
void set_need_reliable_transfer (bool need_reliable)
 
bool need_reliable_transfer () const
 
pthread_t thread_id () const
 

Private Member Functions

void run ()
 
int hardfault_store_filename (const char *log_file)
 permanently store the ulog file name for the hardfault crash handler, so that it can append crash logs to the last ulog file. More...
 
int write (LogType type, void *ptr, size_t size, uint64_t dropout_start)
 write w/o waiting/blocking More...
 

Static Private Member Functions

static void * run_helper (void *)
 

Private Attributes

LogFileBuffer _buffers [(int) LogType::Count]
 
bool _exit_thread = false
 
bool _need_reliable_transfer = false
 
pthread_mutex_t _mtx
 
pthread_cond_t _cv
 
pthread_t _thread = 0
 

Static Private Attributes

static constexpr size_t _min_write_chunk = 4096
 

Detailed Description

Writes logging data to a file.

Definition at line 64 of file log_writer_file.h.

Constructor & Destructor Documentation

◆ LogWriterFile()

px4::logger::LogWriterFile::LogWriterFile ( size_t  buffer_size)

Definition at line 56 of file log_writer_file.cpp.

References _cv, _min_write_chunk, _mtx, math::max(), PC_ELAPSED, and perf_alloc.

Here is the call graph for this function:

◆ ~LogWriterFile()

px4::logger::LogWriterFile::~LogWriterFile ( )

Definition at line 78 of file log_writer_file.cpp.

References _cv, and _mtx.

Member Function Documentation

◆ get_buffer_fill_count()

size_t px4::logger::LogWriterFile::get_buffer_fill_count ( LogType  type) const
inline

Definition at line 114 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::get_buffer_fill_count_file().

Here is the caller graph for this function:

◆ get_buffer_size()

size_t px4::logger::LogWriterFile::get_buffer_size ( LogType  type) const
inline

Definition at line 109 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::get_buffer_size_file().

Here is the caller graph for this function:

◆ get_total_written()

size_t px4::logger::LogWriterFile::get_total_written ( LogType  type) const
inline

Definition at line 104 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::get_total_written_file().

Here is the caller graph for this function:

◆ hardfault_store_filename()

int px4::logger::LogWriterFile::hardfault_store_filename ( const char *  log_file)
private

permanently store the ulog file name for the hardfault crash handler, so that it can append crash logs to the last ulog file.

Parameters
log_filepath to the log file
Returns
0 on success, <0 errno otherwise

Definition at line 116 of file log_writer_file.cpp.

References fd, HARDFAULT_MAX_ULOG_FILE_LEN, HARDFAULT_ULOG_PATH, and write().

Referenced by start_log().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

bool px4::logger::LogWriterFile::init ( )

Definition at line 73 of file log_writer_file.cpp.

Referenced by px4::logger::LogWriter::init().

Here is the caller graph for this function:

◆ is_started()

bool px4::logger::LogWriterFile::is_started ( LogType  type) const
inline

Definition at line 84 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::is_started(), and write().

Here is the caller graph for this function:

◆ lock()

void px4::logger::LogWriterFile::lock ( )
inline

Definition at line 89 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::lock(), start_log(), and write_message().

Here is the caller graph for this function:

◆ need_reliable_transfer()

bool px4::logger::LogWriterFile::need_reliable_transfer ( ) const
inline

Definition at line 124 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::need_reliable_transfer().

Here is the caller graph for this function:

◆ notify()

void px4::logger::LogWriterFile::notify ( )
inline

Definition at line 99 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::notify(), start_log(), stop_log(), thread_stop(), and write_message().

Here is the caller graph for this function:

◆ run()

void px4::logger::LogWriterFile::run ( )
private

Definition at line 197 of file log_writer_file.cpp.

References _buffers, _cv, _exit_thread, _min_write_chunk, _mtx, px4::logger::LogWriterFile::LogFileBuffer::_should_run, px4::logger::LogWriterFile::LogFileBuffer::close_file(), px4::logger::Count, fd, px4::logger::LogWriterFile::LogFileBuffer::fsync(), px4::logger::LogWriterFile::LogFileBuffer::get_read_ptr(), hrt_absolute_time(), hrt_abstime, px4::logger::LogWriterFile::LogFileBuffer::mark_read(), start(), and px4::logger::LogWriterFile::LogFileBuffer::write_to_file().

Referenced by run_helper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_helper()

void * px4::logger::LogWriterFile::run_helper ( void *  context)
staticprivate

Definition at line 189 of file log_writer_file.cpp.

References run().

Referenced by thread_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_need_reliable_transfer()

void px4::logger::LogWriterFile::set_need_reliable_transfer ( bool  need_reliable)
inline

Definition at line 119 of file log_writer_file.h.

Referenced by px4::logger::LogWriter::set_need_reliable_transfer().

Here is the caller graph for this function:

◆ start_log()

void px4::logger::LogWriterFile::start_log ( LogType  type,
const char *  filename 
)

Definition at line 84 of file log_writer_file.cpp.

References _buffers, fd, px4::logger::Full, hardfault_store_filename(), lock(), px4::logger::log_type_str(), notify(), system_usleep, and unlock().

Referenced by px4::logger::LogWriter::start_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_log()

void px4::logger::LogWriterFile::stop_log ( LogType  type)

Definition at line 148 of file log_writer_file.cpp.

References _buffers, and notify().

Referenced by px4::logger::LogWriter::stop_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_id()

pthread_t px4::logger::LogWriterFile::thread_id ( ) const
inline

Definition at line 129 of file log_writer_file.h.

References write().

Referenced by px4::logger::LogWriter::thread_id_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_start()

int px4::logger::LogWriterFile::thread_start ( )

start the thread

Returns
0 on success, error number otherwise (
See also
pthread_create)

Definition at line 154 of file log_writer_file.cpp.

References _thread, and run_helper().

Referenced by px4::logger::LogWriter::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_stop()

void px4::logger::LogWriterFile::thread_stop ( )

Definition at line 172 of file log_writer_file.cpp.

References _buffers, _exit_thread, px4::logger::LogWriterFile::LogFileBuffer::_should_run, _thread, and notify().

Referenced by px4::logger::LogWriter::thread_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void px4::logger::LogWriterFile::unlock ( )
inline

Definition at line 94 of file log_writer_file.h.

Referenced by start_log(), px4::logger::LogWriter::unlock(), and write_message().

Here is the caller graph for this function:

◆ write()

int px4::logger::LogWriterFile::write ( LogType  type,
void *  ptr,
size_t  size,
uint64_t  dropout_start 
)
private

write w/o waiting/blocking

Definition at line 345 of file log_writer_file.cpp.

References _buffers, ulog_message_dropout_s::duration, hrt_elapsed_time(), and is_started().

Referenced by hardfault_store_filename(), write_message(), and px4::logger::LogWriterFile::LogFileBuffer::write_to_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_message()

int px4::logger::LogWriterFile::write_message ( LogType  type,
void *  ptr,
size_t  size,
uint64_t  dropout_start = 0 
)
See also
LogWriter::write_message()

Definition at line 307 of file log_writer_file.cpp.

References _buffers, _need_reliable_transfer, lock(), math::min(), notify(), unlock(), and write().

Referenced by px4::logger::LogWriter::write_message().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _buffers

LogFileBuffer px4::logger::LogWriterFile::_buffers[(int) LogType::Count]
private

Definition at line 197 of file log_writer_file.h.

Referenced by run(), start_log(), stop_log(), thread_stop(), write(), and write_message().

◆ _cv

pthread_cond_t px4::logger::LogWriterFile::_cv
private

Definition at line 202 of file log_writer_file.h.

Referenced by LogWriterFile(), run(), and ~LogWriterFile().

◆ _exit_thread

bool px4::logger::LogWriterFile::_exit_thread = false
private

Definition at line 199 of file log_writer_file.h.

Referenced by run(), and thread_stop().

◆ _min_write_chunk

constexpr size_t px4::logger::LogWriterFile::_min_write_chunk = 4096
staticprivate

Definition at line 150 of file log_writer_file.h.

Referenced by LogWriterFile(), and run().

◆ _mtx

pthread_mutex_t px4::logger::LogWriterFile::_mtx
private

Definition at line 201 of file log_writer_file.h.

Referenced by LogWriterFile(), run(), and ~LogWriterFile().

◆ _need_reliable_transfer

bool px4::logger::LogWriterFile::_need_reliable_transfer = false
private

Definition at line 200 of file log_writer_file.h.

Referenced by write_message().

◆ _thread

pthread_t px4::logger::LogWriterFile::_thread = 0
private

Definition at line 203 of file log_writer_file.h.

Referenced by thread_start(), and thread_stop().


The documentation for this class was generated from the following files: