Thunderbots Project
Loading...
Searching...
No Matches
ProtoLogger Class Reference

#include <proto_logger.h>

Public Member Functions

 ProtoLogger (const std::string &log_path, std::function< double()> time_provider, bool friendly_colour_yellow)
 
 ProtoLogger (const ProtoLogger &)=delete
 
ProtoLoggeroperator= (const ProtoLogger &)=delete
 
void saveSerializedProto (const std::string &protobuf_type_full_name, const std::string &serialized_proto)
 
template<typename ProtoType >
void saveSerializedProto (const std::string &serialized_proto)
 
void updateTimeProvider (std::function< double()> time_provider)
 
void flushAndStopLogging ()
 

Static Public Member Functions

static std::string createLogEntry (const std::string &proto_full_name, const std::string &serialized_proto, double receive_time_sec)
 

Detailed Description

Logs incoming Protobufs to a folder to be played back later.

Each entry will contain:

  • The timestamp
  • The protobuf type
  • The protobuf serialized as base64 (to remove newline characters)

Stored in log_path/proto_YYYY_MM_DD_HH_MM_SS/ With each entry in the file formatted as timestamp,protobuf_type,protobuf_base64 Note that in order to reduce the size of the log files, the files are compressed using gzip.

We need to store the data in a way that we can:

  1. Replay the data chronologically
  2. Seek to a specific time (random access)

To seek to a specific time, we need to load the entire log file into memory. To make this feasible, we store the data in chunks. Each chunk contains REPLAY_MAX_CHUNK_SIZE_BYTES of serialized protos. We can load each chunk into memory and perform search operations to find the appropriate entry. Or we can just play the chunks in order.

Constructor & Destructor Documentation

◆ ProtoLogger() [1/2]

ProtoLogger ( const std::string &  log_path,
std::function< double()>  time_provider,
bool  friendly_colour_yellow 
)
explicit

Constructor

Parameters
log_pathThe path to the directory where the logs will be saved
time_providerA function that returns the current time in seconds
friendly_colour_yellowWhether the friendly team is yellow or not

◆ ProtoLogger() [2/2]

ProtoLogger ( const ProtoLogger )
delete

Removing copy constructor and assignment operator to prevent accidental copying of the ProtoLogger.

Member Function Documentation

◆ createLogEntry()

std::string createLogEntry ( const std::string &  proto_full_name,
const std::string &  serialized_proto,
double  receive_time_sec 
)
static

Helper function for creating a log entry

Parameters
protobuf_type_full_nameThe full name of the protobuf message type (e.g. TbotsProto.ThunderbotsConfig)
serialized_protoThe serialized protobuf message to store
receive_time_secThe time the protobuf was received
Returns
A string containing the log entry

◆ flushAndStopLogging()

void flushAndStopLogging ( )

Flushes the buffer and stops the logging thread.

Note
ProtoLogger will try to flush the buffer for up to MAX_TIME_TO_EXIT_FULL_SYSTEM_SEC seconds before stopping the logging thread. As such, if there are many logs in the buffer, not all may be flushed in time and some data may be lost.

◆ saveSerializedProto() [1/2]

void saveSerializedProto ( const std::string &  protobuf_type_full_name,
const std::string &  serialized_proto 
)

Saves a serialized protobuf message to the log

Parameters
protobuf_type_full_nameThe full name of the protobuf message type (e.g. TbotsProto.ThunderbotsConfig)
serialized_protoThe serialized protobuf message to store

◆ saveSerializedProto() [2/2]

template<typename ProtoType >
void saveSerializedProto ( const std::string &  serialized_proto)
inline

Saves a serialized protobuf message to the log

Template Parameters
ProtoTypeThe type of the protobuf message (Must extend the google::protobuf::Message class and not google::protobuf::MessageLite so it has reflection capabilities)
Parameters
serialized_protoThe serialized protobuf message to store

◆ updateTimeProvider()

void updateTimeProvider ( std::function< double()>  time_provider)

Update the time provider used to create timestamp for the protobufs

Parameters
time_providerA function that returns the current time in seconds

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