|
Thunderbots Project
|
#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 | |
| ProtoLogger & | operator= (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) |
Logs incoming Protobufs to a folder to be played back later.
Each entry will contain:
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:
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.
|
explicit |
Constructor
| log_path | The path to the directory where the logs will be saved |
| time_provider | A function that returns the current time in seconds |
| friendly_colour_yellow | Whether the friendly team is yellow or not |
|
delete |
Removing copy constructor and assignment operator to prevent accidental copying of the ProtoLogger.
|
static |
Helper function for creating a log entry
| protobuf_type_full_name | The full name of the protobuf message type (e.g. TbotsProto.ThunderbotsConfig) |
| serialized_proto | The serialized protobuf message to store |
| receive_time_sec | The time the protobuf was received |
| void flushAndStopLogging | ( | ) |
Flushes the buffer and stops the logging thread.
| void saveSerializedProto | ( | const std::string & | protobuf_type_full_name, |
| const std::string & | serialized_proto | ||
| ) |
Saves a serialized protobuf message to the log
| protobuf_type_full_name | The full name of the protobuf message type (e.g. TbotsProto.ThunderbotsConfig) |
| serialized_proto | The serialized protobuf message to store |
|
inline |
Saves a serialized protobuf message to the log
| ProtoType | The type of the protobuf message (Must extend the google::protobuf::Message class and not google::protobuf::MessageLite so it has reflection capabilities) |
| serialized_proto | The serialized protobuf message to store |
| void updateTimeProvider | ( | std::function< double()> | time_provider | ) |
Update the time provider used to create timestamp for the protobufs
| time_provider | A function that returns the current time in seconds |