WPILibC++ 2025.0.0-alpha-1-10-g1ccd8d1
wpi::log::DataLogBackgroundWriter Class Referencefinal

A data log background writer that periodically flushes the data log on a background thread. More...

#include <wpi/DataLogBackgroundWriter.h>

Inheritance diagram for wpi::log::DataLogBackgroundWriter:
wpi::log::DataLog

Public Member Functions

 DataLogBackgroundWriter (std::string_view dir="", std::string_view filename="", double period=0.25, std::string_view extraHeader="")
 Construct a new Data Log. More...
 
 DataLogBackgroundWriter (wpi::Logger &msglog, std::string_view dir="", std::string_view filename="", double period=0.25, std::string_view extraHeader="")
 Construct a new Data Log. More...
 
 DataLogBackgroundWriter (std::function< void(std::span< const uint8_t > data)> write, double period=0.25, std::string_view extraHeader="")
 Construct a new Data Log that passes its output to the provided function rather than a file. More...
 
 DataLogBackgroundWriter (wpi::Logger &msglog, std::function< void(std::span< const uint8_t > data)> write, double period=0.25, std::string_view extraHeader="")
 Construct a new Data Log that passes its output to the provided function rather than a file. More...
 
 ~DataLogBackgroundWriter () final
 
 DataLogBackgroundWriter (const DataLogBackgroundWriter &)=delete
 
DataLogBackgroundWriteroperator= (const DataLogBackgroundWriter &)=delete
 
 DataLogBackgroundWriter (DataLogBackgroundWriter &&)=delete
 
DataLogBackgroundWriteroperator= (const DataLogBackgroundWriter &&)=delete
 
void SetFilename (std::string_view filename)
 Change log filename. More...
 
void Flush () final
 Explicitly flushes the log data to disk. More...
 
void Pause () final
 Pauses appending of data records to the log. More...
 
void Resume () final
 Resumes appending of data records to the log. More...
 
void Stop () final
 Stops appending all records to the log, and closes the log file. More...
 
- Public Member Functions inherited from wpi::log::DataLog
virtual ~DataLog ()=default
 
 DataLog (const DataLog &)=delete
 
DataLogoperator= (const DataLog &)=delete
 
 DataLog (DataLog &&)=delete
 
DataLogoperator= (const DataLog &&)=delete
 
virtual void Flush ()=0
 Explicitly flushes the log data to disk. More...
 
virtual void Pause ()
 Pauses appending of data records to the log. More...
 
virtual void Resume ()
 Resumes appending of data records to the log. More...
 
virtual void Stop ()
 Stops appending start/metadata/schema records to the log. More...
 
bool HasSchema (std::string_view name) const
 Returns whether there is a data schema already registered with the given name. More...
 
void AddSchema (std::string_view name, std::string_view type, std::span< const uint8_t > schema, int64_t timestamp=0)
 Registers a data schema. More...
 
void AddSchema (std::string_view name, std::string_view type, std::string_view schema, int64_t timestamp=0)
 Registers a data schema. More...
 
template<ProtobufSerializable T>
void AddProtobufSchema (ProtobufMessage< T > &msg, int64_t timestamp=0)
 Registers a protobuf schema. More...
 
template<typename T , typename... I>
requires StructSerializable<T, I...>
void AddStructSchema (const I &... info, int64_t timestamp=0)
 Registers a struct schema. More...
 
int Start (std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
 Start an entry. More...
 
void Finish (int entry, int64_t timestamp=0)
 Finish an entry. More...
 
void SetMetadata (int entry, std::string_view metadata, int64_t timestamp=0)
 Updates the metadata for an entry. More...
 
void AppendRaw (int entry, std::span< const uint8_t > data, int64_t timestamp)
 Appends a raw record to the log. More...
 
void AppendRaw2 (int entry, std::span< const std::span< const uint8_t > > data, int64_t timestamp)
 Appends a raw record to the log. More...
 
void AppendBoolean (int entry, bool value, int64_t timestamp)
 Appends a boolean record to the log. More...
 
void AppendInteger (int entry, int64_t value, int64_t timestamp)
 Appends an integer record to the log. More...
 
void AppendFloat (int entry, float value, int64_t timestamp)
 Appends a float record to the log. More...
 
void AppendDouble (int entry, double value, int64_t timestamp)
 Appends a double record to the log. More...
 
void AppendString (int entry, std::string_view value, int64_t timestamp)
 Appends a string record to the log. More...
 
void AppendBooleanArray (int entry, std::span< const bool > arr, int64_t timestamp)
 Appends a boolean array record to the log. More...
 
void AppendBooleanArray (int entry, std::span< const int > arr, int64_t timestamp)
 Appends a boolean array record to the log. More...
 
void AppendBooleanArray (int entry, std::span< const uint8_t > arr, int64_t timestamp)
 Appends a boolean array record to the log. More...
 
void AppendIntegerArray (int entry, std::span< const int64_t > arr, int64_t timestamp)
 Appends an integer array record to the log. More...
 
void AppendFloatArray (int entry, std::span< const float > arr, int64_t timestamp)
 Appends a float array record to the log. More...
 
void AppendDoubleArray (int entry, std::span< const double > arr, int64_t timestamp)
 Appends a double array record to the log. More...
 
void AppendStringArray (int entry, std::span< const std::string > arr, int64_t timestamp)
 Appends a string array record to the log. More...
 
void AppendStringArray (int entry, std::span< const std::string_view > arr, int64_t timestamp)
 Appends a string array record to the log. More...
 
void AppendStringArray (int entry, std::span< const struct WPI_String > arr, int64_t timestamp)
 Appends a string array record to the log. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::log::DataLog
 DataLog (wpi::Logger &msglog, std::string_view extraHeader="")
 Constructs the log. More...
 
void StartFile ()
 Starts the log. More...
 
void FlushBufs (std::vector< Buffer > *writeBufs)
 Provides complete set of all buffers that need to be written. More...
 
void ReleaseBufs (std::vector< Buffer > *bufs)
 Releases memory for a set of buffers back to the internal buffer pool. More...
 
virtual void BufferHalfFull ()
 Called when internal buffers are half the maximum count. More...
 
virtual bool BufferFull ()=0
 Called when internal buffers reach the maximum count. More...
 
- Protected Attributes inherited from wpi::log::DataLog
wpi::Loggerm_msglog
 
- Static Protected Attributes inherited from wpi::log::DataLog
static constexpr size_t kBlockSize = 16 * 1024
 
static wpi::Logger s_defaultMessageLog
 

Detailed Description

A data log background writer that periodically flushes the data log on a background thread.

The data log file is created immediately upon construction with a temporary filename. The file may be renamed at any time using the SetFilename() function.

The lifetime of this object must be longer than any data log entry objects that refer to it.

The data log is periodically flushed to disk. It can also be explicitly flushed to disk by using the Flush() function. This operation is, however, non-blocking.

Constructor & Destructor Documentation

◆ DataLogBackgroundWriter() [1/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( std::string_view  dir = "",
std::string_view  filename = "",
double  period = 0.25,
std::string_view  extraHeader = "" 
)
explicit

Construct a new Data Log.

The log will be initially created with a temporary filename.

Parameters
dirdirectory to store the log
filenamefilename to use; if none provided, a random filename is generated of the form "wpilog_{}.wpilog"
periodtime between automatic flushes to disk, in seconds; this is a time/storage tradeoff
extraHeaderextra header data

◆ DataLogBackgroundWriter() [2/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( wpi::Logger msglog,
std::string_view  dir = "",
std::string_view  filename = "",
double  period = 0.25,
std::string_view  extraHeader = "" 
)
explicit

Construct a new Data Log.

The log will be initially created with a temporary filename.

Parameters
msglogmessage logger (will be called from separate thread)
dirdirectory to store the log
filenamefilename to use; if none provided, a random filename is generated of the form "wpilog_{}.wpilog"
periodtime between automatic flushes to disk, in seconds; this is a time/storage tradeoff
extraHeaderextra header data

◆ DataLogBackgroundWriter() [3/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( std::function< void(std::span< const uint8_t > data)>  write,
double  period = 0.25,
std::string_view  extraHeader = "" 
)
explicit

Construct a new Data Log that passes its output to the provided function rather than a file.

The write function will be called on a separate background thread and may block. The write function is called with an empty data array when the thread is terminating.

Parameters
writewrite function
periodtime between automatic calls to write, in seconds; this is a time/storage tradeoff
extraHeaderextra header data

◆ DataLogBackgroundWriter() [4/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( wpi::Logger msglog,
std::function< void(std::span< const uint8_t > data)>  write,
double  period = 0.25,
std::string_view  extraHeader = "" 
)
explicit

Construct a new Data Log that passes its output to the provided function rather than a file.

The write function will be called on a separate background thread and may block. The write function is called with an empty data array when the thread is terminating.

Parameters
msglogmessage logger (will be called from separate thread)
writewrite function
periodtime between automatic calls to write, in seconds; this is a time/storage tradeoff
extraHeaderextra header data

◆ ~DataLogBackgroundWriter()

wpi::log::DataLogBackgroundWriter::~DataLogBackgroundWriter ( )
final

◆ DataLogBackgroundWriter() [5/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( const DataLogBackgroundWriter )
delete

◆ DataLogBackgroundWriter() [6/6]

wpi::log::DataLogBackgroundWriter::DataLogBackgroundWriter ( DataLogBackgroundWriter &&  )
delete

Member Function Documentation

◆ Flush()

void wpi::log::DataLogBackgroundWriter::Flush ( )
finalvirtual

Explicitly flushes the log data to disk.

Implements wpi::log::DataLog.

◆ operator=() [1/2]

DataLogBackgroundWriter & wpi::log::DataLogBackgroundWriter::operator= ( const DataLogBackgroundWriter &&  )
delete

◆ operator=() [2/2]

DataLogBackgroundWriter & wpi::log::DataLogBackgroundWriter::operator= ( const DataLogBackgroundWriter )
delete

◆ Pause()

void wpi::log::DataLogBackgroundWriter::Pause ( )
finalvirtual

Pauses appending of data records to the log.

While paused, no data records are saved (e.g. AppendX is a no-op). Has no effect on entry starts / finishes / metadata changes.

Reimplemented from wpi::log::DataLog.

◆ Resume()

void wpi::log::DataLogBackgroundWriter::Resume ( )
finalvirtual

Resumes appending of data records to the log.

If called after Stop(), opens a new file (with random name if SetFilename was not called after Stop()) and appends Start records and schema data values for all previously started entries and schemas.

Reimplemented from wpi::log::DataLog.

◆ SetFilename()

void wpi::log::DataLogBackgroundWriter::SetFilename ( std::string_view  filename)

Change log filename.

Parameters
filenamefilename

◆ Stop()

void wpi::log::DataLogBackgroundWriter::Stop ( )
finalvirtual

Stops appending all records to the log, and closes the log file.

Reimplemented from wpi::log::DataLog.


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