ILLIXR: Illinois Extended Reality Testbed
Public Member Functions | List of all members
ILLIXR::record_coalescer Class Reference

Coalesces logs of the same type to be written back as a single-transaction. More...

#include <record_logger.hpp>

Public Member Functions

 record_coalescer (std::shared_ptr< record_logger > logger_)
 
void log (const record &r)
 Appends a log to the buffer, which will eventually be written.
 
void maybe_flush ()
 Use internal decision process, and possibly trigger flush.
 
void flush ()
 Flush buffer of logs to the underlying logger.
 
 operator bool () const
 

Detailed Description

Coalesces logs of the same type to be written back as a single-transaction.

Records should all be of the same type. TODO: remove this constraint. Use log<record_type>(Args... args) and std::forward.

In some backend-implementations, logging many logs of the same type is more efficient than logging them individually; However, the client often wants to produce one log-record at a time. This class resolves this mismatch by buffering logs from the client. Every time a new log is added, an internal decision process determines whether or not to flush the buffer, or keep accumulating and wait unitl later.

Currently this internal decision process is "is the oldest log in the buffer more than 1 second old?". I chose this because this frequency should have very little overhead, even if every component is also coalescing at 1 per second.

At destructor time, any remaining logs are flushed.

Use like:

log_coalescer(logger);
lc.log(make_my_record(id, it, skip_it, ...));

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