bt_minitrace_logger.cpp
Go to the documentation of this file.
1 
3 
4 #define MTR_ENABLED true
5 #include "minitrace/minitrace.h"
6 
7 namespace BT
8 {
9 
10 MinitraceLogger::MinitraceLogger(const Tree& tree, const char* filename_json)
11  : StatusChangeLogger(tree.rootNode())
12 {
14  mtr_init(filename_json);
15  this->enableTransitionToIdle(true);
16 }
17 
19 {
20  mtr_flush();
21  mtr_shutdown();
22 }
23 
24 const char* toConstStr(NodeType type)
25 {
26  switch(type)
27  {
28  case NodeType::ACTION:
29  return "Action";
31  return "Condition";
33  return "Decorator";
34  case NodeType::CONTROL:
35  return "Control";
36  case NodeType::SUBTREE:
37  return "SubTree";
38  default:
39  return "Undefined";
40  }
41 }
42 
43 void MinitraceLogger::callback(Duration /*timestamp*/, const TreeNode& node,
44  NodeStatus prev_status, NodeStatus status)
45 {
46  const bool statusCompleted = isStatusCompleted(status);
47 
48  const char* category = toConstStr(node.type());
49  const char* name = node.name().c_str();
50 
51  if(prev_status == NodeStatus::IDLE && statusCompleted)
52  {
53  MTR_INSTANT(category, name);
54  }
55  else if(status == NodeStatus::RUNNING)
56  {
57  MTR_BEGIN(category, name);
58  }
59  else if(prev_status == NodeStatus::RUNNING && statusCompleted)
60  {
61  MTR_END(category, name);
62  }
63  mtr_flush();
64 }
65 
67 {
68  mtr_flush();
69 }
70 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::NodeType
NodeType
Enumerates the possible types of nodes.
Definition: basic_types.h:20
BT::NodeType::DECORATOR
@ DECORATOR
BT::NodeType::CONDITION
@ CONDITION
lexy::_unicode_db::category
constexpr lexy::code_point::general_category_t category[]
Definition: unicode_database.hpp:65
MTR_BEGIN
#define MTR_BEGIN(c, n)
Definition: minitrace.h:154
mtr_register_sigint_handler
void mtr_register_sigint_handler()
Definition: minitrace.cpp:167
BT::StatusChangeLogger::enableTransitionToIdle
void enableTransitionToIdle(bool enable)
Definition: abstract_logger.h:53
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::NodeType::SUBTREE
@ SUBTREE
minitrace.h
BT::MinitraceLogger::MinitraceLogger
MinitraceLogger(const BT::Tree &tree, const char *filename_json)
Definition: bt_minitrace_logger.cpp:10
BT::MinitraceLogger::flush
virtual void flush() override
Definition: bt_minitrace_logger.cpp:66
BT::StatusChangeLogger
Definition: abstract_logger.h:15
BT::Duration
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:628
MTR_END
#define MTR_END(c, n)
Definition: minitrace.h:155
BT::NodeType::ACTION
@ ACTION
MTR_INSTANT
#define MTR_INSTANT(c, n)
Definition: minitrace.h:177
BT::TreeNode::type
virtual NodeType type() const =0
mtr_init
void mtr_init(const char *json_file)
Definition: minitrace.cpp:195
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:302
mtr_shutdown
void mtr_shutdown()
Definition: minitrace.cpp:202
BT::NodeStatus::RUNNING
@ RUNNING
BT::isStatusCompleted
bool isStatusCompleted(const NodeStatus &status)
Definition: basic_types.h:47
BT::MinitraceLogger::~MinitraceLogger
virtual ~MinitraceLogger() override
Definition: bt_minitrace_logger.cpp:18
BT::NodeType::CONTROL
@ CONTROL
BT::NodeStatus::IDLE
@ IDLE
BT::MinitraceLogger::callback
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
Definition: bt_minitrace_logger.cpp:43
mtr_flush
void mtr_flush()
Definition: minitrace.cpp:373
BT::toConstStr
const char * toConstStr(NodeType type)
Definition: bt_minitrace_logger.cpp:24
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
bt_minitrace_logger.h


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