bt_sqlite_logger.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
5 
6 namespace sqlite
7 {
8 class Connection;
9 }
10 
11 namespace BT
12 {
13 
48 {
49 public:
58  SqliteLogger(const Tree& tree, std::filesystem::path const& file, bool append = false);
59 
60  virtual ~SqliteLogger() override;
61 
62  // You can inject a function that add a string to the Transitions table,
63  // in the column "extra_data".
64  // The arguments of the function are the same as SqliteLogger::callback()
65  using ExtraCallback =
66  std::function<std::string(Duration, const TreeNode&, NodeStatus, NodeStatus)>;
68 
69  virtual void callback(Duration timestamp, const TreeNode& node, NodeStatus prev_status,
70  NodeStatus status) override;
71 
72  void execSqlStatement(std::string statement);
73 
74  virtual void flush() override;
75 
76 private:
77  std::unique_ptr<sqlite::Connection> db_;
78 
79  int64_t monotonic_timestamp_ = 0;
80  std::unordered_map<const BT::TreeNode*, int64_t> starting_time_;
81 
82  int session_id_ = -1;
83 
84  struct Transition
85  {
86  uint16_t node_uid;
87  int64_t timestamp;
88  int64_t duration;
90  std::string extra_data;
91  };
92 
93  std::deque<Transition> transitions_queue_;
94  std::condition_variable queue_cv_;
96 
97  std::thread writer_thread_;
98  std::atomic_bool loop_ = true;
99 
101 
102  void writerLoop();
103 };
104 
105 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::SqliteLogger::Transition::duration
int64_t duration
Definition: bt_sqlite_logger.h:88
BT::SqliteLogger::Transition::timestamp
int64_t timestamp
Definition: bt_sqlite_logger.h:87
BT::SqliteLogger::queue_mutex_
std::mutex queue_mutex_
Definition: bt_sqlite_logger.h:95
BT::SqliteLogger::flush
virtual void flush() override
Definition: bt_sqlite_logger.cpp:164
BT::SqliteLogger::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 otherw...
Definition: bt_sqlite_logger.cpp:8
BT::SqliteLogger::writerLoop
void writerLoop()
Definition: bt_sqlite_logger.cpp:139
BT::SqliteLogger::setAdditionalCallback
void setAdditionalCallback(ExtraCallback func)
Definition: bt_sqlite_logger.cpp:82
BT::SqliteLogger::writer_thread_
std::thread writer_thread_
Definition: bt_sqlite_logger.h:97
BT::SqliteLogger::extra_func_
ExtraCallback extra_func_
Definition: bt_sqlite_logger.h:100
BT::SqliteLogger::execSqlStatement
void execSqlStatement(std::string statement)
Definition: bt_sqlite_logger.cpp:134
BT::SqliteLogger
The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite data...
Definition: bt_sqlite_logger.h:47
BT::TreeNode
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:118
BT::Tree
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:91
BT::SqliteLogger::Transition
Definition: bt_sqlite_logger.h:84
BT::StatusChangeLogger
Definition: abstract_logger.h:15
BT::Duration
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:628
BT::SqliteLogger::starting_time_
std::unordered_map< const BT::TreeNode *, int64_t > starting_time_
Definition: bt_sqlite_logger.h:80
BT::SqliteLogger::Transition::status
NodeStatus status
Definition: bt_sqlite_logger.h:89
BT::SqliteLogger::transitions_queue_
std::deque< Transition > transitions_queue_
Definition: bt_sqlite_logger.h:93
mutex
static pthread_mutex_t mutex
Definition: minitrace.cpp:77
BT::SqliteLogger::callback
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
Definition: bt_sqlite_logger.cpp:87
BT::SqliteLogger::loop_
std::atomic_bool loop_
Definition: bt_sqlite_logger.h:98
BT::SqliteLogger::monotonic_timestamp_
int64_t monotonic_timestamp_
Definition: bt_sqlite_logger.h:79
BT::SqliteLogger::~SqliteLogger
virtual ~SqliteLogger() override
Definition: bt_sqlite_logger.cpp:73
BT::SqliteLogger::Transition::node_uid
uint16_t node_uid
Definition: bt_sqlite_logger.h:86
BT::SqliteLogger::queue_cv_
std::condition_variable queue_cv_
Definition: bt_sqlite_logger.h:94
BT::SqliteLogger::ExtraCallback
std::function< std::string(Duration, const TreeNode &, NodeStatus, NodeStatus)> ExtraCallback
Definition: bt_sqlite_logger.h:66
BT::SqliteLogger::session_id_
int session_id_
Definition: bt_sqlite_logger.h:82
BT::SqliteLogger::db_
std::unique_ptr< sqlite::Connection > db_
Definition: bt_sqlite_logger.h:77
sqlite
Definition: sqlite.hpp:43
BT::SqliteLogger::Transition::extra_data
std::string extra_data
Definition: bt_sqlite_logger.h:90
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
abstract_logger.h


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16