Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
BT::SqliteLogger Class Reference

The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite database (single file). More...

#include <bt_sqlite_logger.h>

Inheritance diagram for BT::SqliteLogger:
Inheritance graph
[legend]

Classes

struct  Transition
 

Public Types

using ExtraCallback = std::function< std::string(Duration, const TreeNode &, NodeStatus, NodeStatus)>
 

Public Member Functions

virtual void callback (Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
 
void execSqlStatement (std::string statement)
 
virtual void flush () override
 
void setAdditionalCallback (ExtraCallback func)
 
 SqliteLogger (const Tree &tree, std::filesystem::path const &file, bool append=false)
 To correctly read this log with Groot2, you must use the suffix ".db3". Constructor will throw otherwise. More...
 
virtual ~SqliteLogger () override
 
- Public Member Functions inherited from BT::StatusChangeLogger
bool enabled () const
 
void enableTransitionToIdle (bool enable)
 
StatusChangeLoggeroperator= (const StatusChangeLogger &other)=delete
 
StatusChangeLoggeroperator= (StatusChangeLogger &&other)=default
 
void setEnabled (bool enabled)
 
void setTimestampType (TimestampType type)
 
bool showsTransitionToIdle () const
 
 StatusChangeLogger (const StatusChangeLogger &other)=delete
 
 StatusChangeLogger (StatusChangeLogger &&other)=default
 
 StatusChangeLogger (TreeNode *root_node)
 
virtual ~StatusChangeLogger ()=default
 

Private Member Functions

void writerLoop ()
 

Private Attributes

std::unique_ptr< sqlite::Connectiondb_
 
ExtraCallback extra_func_
 
std::atomic_bool loop_ = true
 
int64_t monotonic_timestamp_ = 0
 
std::condition_variable queue_cv_
 
std::mutex queue_mutex_
 
int session_id_ = -1
 
std::unordered_map< const BT::TreeNode *, int64_t > starting_time_
 
std::deque< Transitiontransitions_queue_
 
std::thread writer_thread_
 

Detailed Description

The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite database (single file).

SQL schema

CREATE TABLE IF NOT EXISTS Definitions ( session_id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, xml_tree TEXT NOT NULL);

CREATE TABLE IF NOT EXISTS Nodes (" session_id INTEGER NOT NULL, fullpath VARCHAR, " node_uid INTEGER NOT NULL );

CREATE TABLE IF NOT EXISTS Transitions ( timestamp INTEGER PRIMARY KEY NOT NULL, session_id INTEGER NOT NULL, node_uid INTEGER NOT NULL, duration INTEGER, state INTEGER NOT NULL, extra_data VARCHAR ); You can append data to the same file; this allows you to store multiple experiments into the database. Yn that case, each recording has a unique session_id.

This is primarily meant to be used with Groot2, but the content of the tables is sufficiently self-explaining, and you can create your own tools to extract the information.

Definition at line 47 of file bt_sqlite_logger.h.

Member Typedef Documentation

◆ ExtraCallback

using BT::SqliteLogger::ExtraCallback = std::function<std::string(Duration, const TreeNode&, NodeStatus, NodeStatus)>

Definition at line 66 of file bt_sqlite_logger.h.

Constructor & Destructor Documentation

◆ SqliteLogger()

BT::SqliteLogger::SqliteLogger ( const Tree tree,
std::filesystem::path const &  file,
bool  append = false 
)

To correctly read this log with Groot2, you must use the suffix ".db3". Constructor will throw otherwise.

Parameters
treethe tree to log
filepathpath of the file where info will be stored
appendif true, add this recording to the database

Definition at line 8 of file bt_sqlite_logger.cpp.

◆ ~SqliteLogger()

BT::SqliteLogger::~SqliteLogger ( )
overridevirtual

Definition at line 73 of file bt_sqlite_logger.cpp.

Member Function Documentation

◆ callback()

void BT::SqliteLogger::callback ( Duration  timestamp,
const TreeNode node,
NodeStatus  prev_status,
NodeStatus  status 
)
overridevirtual

Implements BT::StatusChangeLogger.

Definition at line 87 of file bt_sqlite_logger.cpp.

◆ execSqlStatement()

void BT::SqliteLogger::execSqlStatement ( std::string  statement)

Definition at line 134 of file bt_sqlite_logger.cpp.

◆ flush()

void BT::SqliteLogger::flush ( )
overridevirtual

Implements BT::StatusChangeLogger.

Definition at line 164 of file bt_sqlite_logger.cpp.

◆ setAdditionalCallback()

void BT::SqliteLogger::setAdditionalCallback ( ExtraCallback  func)

Definition at line 82 of file bt_sqlite_logger.cpp.

◆ writerLoop()

void BT::SqliteLogger::writerLoop ( )
private

Definition at line 139 of file bt_sqlite_logger.cpp.

Member Data Documentation

◆ db_

std::unique_ptr<sqlite::Connection> BT::SqliteLogger::db_
private

Definition at line 77 of file bt_sqlite_logger.h.

◆ extra_func_

ExtraCallback BT::SqliteLogger::extra_func_
private

Definition at line 100 of file bt_sqlite_logger.h.

◆ loop_

std::atomic_bool BT::SqliteLogger::loop_ = true
private

Definition at line 98 of file bt_sqlite_logger.h.

◆ monotonic_timestamp_

int64_t BT::SqliteLogger::monotonic_timestamp_ = 0
private

Definition at line 79 of file bt_sqlite_logger.h.

◆ queue_cv_

std::condition_variable BT::SqliteLogger::queue_cv_
private

Definition at line 94 of file bt_sqlite_logger.h.

◆ queue_mutex_

std::mutex BT::SqliteLogger::queue_mutex_
private

Definition at line 95 of file bt_sqlite_logger.h.

◆ session_id_

int BT::SqliteLogger::session_id_ = -1
private

Definition at line 82 of file bt_sqlite_logger.h.

◆ starting_time_

std::unordered_map<const BT::TreeNode*, int64_t> BT::SqliteLogger::starting_time_
private

Definition at line 80 of file bt_sqlite_logger.h.

◆ transitions_queue_

std::deque<Transition> BT::SqliteLogger::transitions_queue_
private

Definition at line 93 of file bt_sqlite_logger.h.

◆ writer_thread_

std::thread BT::SqliteLogger::writer_thread_
private

Definition at line 97 of file bt_sqlite_logger.h.


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


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:09