bt_minitrace_logger.cpp
Go to the documentation of this file.
1 
3 #include "minitrace/minitrace.h"
4 
5 namespace BT
6 {
7 std::atomic<bool> MinitraceLogger::ref_count(false);
8 
9 MinitraceLogger::MinitraceLogger(const Tree &tree, const char* filename_json)
10  : StatusChangeLogger( tree.rootNode() )
11 {
12  bool expected = false;
13  if (!ref_count.compare_exchange_strong(expected, true))
14  {
15  throw LogicError("Only one instance of StdCoutLogger shall be created");
16  }
17 
19  minitrace::mtr_init(filename_json);
20  this->enableTransitionToIdle(true);
21 }
22 
24 {
27  ref_count = false;
28 }
29 
30 const char* toConstStr(NodeType type)
31 {
32  switch (type)
33  {
34  case NodeType::ACTION:
35  return "Action";
37  return "Condition";
39  return "Decorator";
40  case NodeType::CONTROL:
41  return "Control";
42  case NodeType::SUBTREE:
43  return "SubTree";
44  default:
45  return "Undefined";
46  }
47 }
48 
50  const TreeNode& node, NodeStatus prev_status,
51  NodeStatus status)
52 {
53  using namespace minitrace;
54 
55  const bool statusCompleted = (status == NodeStatus::SUCCESS || status == NodeStatus::FAILURE);
56 
57  const char* category = toConstStr(node.type());
58  const char* name = node.name().c_str();
59 
60  if (prev_status == NodeStatus::IDLE && statusCompleted)
61  {
62  MTR_INSTANT(category, name);
63  }
64  else if (status == NodeStatus::RUNNING)
65  {
66  MTR_BEGIN(category, name);
67  }
68  else if (prev_status == NodeStatus::RUNNING && statusCompleted)
69  {
70  MTR_END(category, name);
71  }
72 }
73 
75 {
77 }
78 } // end namespace
void mtr_shutdown()
Definition: minitrace.cpp:173
virtual NodeType type() const =0
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
#define MTR_END(c, n)
Definition: minitrace.h:97
void mtr_register_sigint_handler()
Definition: minitrace.cpp:147
void mtr_init(const char *json_file)
Definition: minitrace.cpp:158
virtual ~MinitraceLogger() override
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
static std::atomic< bool > ref_count
#define MTR_BEGIN(c, n)
Definition: minitrace.h:96
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:130
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
virtual void flush() override
NodeStatus
Definition: basic_types.h:35
MinitraceLogger(const BT::Tree &tree, const char *filename_json)
#define MTR_INSTANT(c, n)
Definition: minitrace.h:131
NodeType
Enumerates the possible types of nodes.
Definition: basic_types.h:22
void enableTransitionToIdle(bool enable)
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:340
void mtr_flush()
Definition: minitrace.cpp:224
const char * toConstStr(NodeType type)


behaviotree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Tue May 4 2021 02:56:24