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(TreeNode* root_node, const char* filename_json)
10  : StatusChangeLogger(root_node)
11 {
12  bool expected = false;
13  if (!ref_count.compare_exchange_strong(expected, true))
14  {
15  throw std::logic_error("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 
31  const TreeNode& node, NodeStatus prev_status,
32  NodeStatus status)
33 {
34  using namespace minitrace;
35 
36  const bool statusCompleted = (status == NodeStatus::SUCCESS || status == NodeStatus::FAILURE);
37 
38  const char* category = toStr(node.type());
39  const char* name = node.name().c_str();
40 
41  if (prev_status == NodeStatus::IDLE && statusCompleted)
42  {
43  MTR_INSTANT(category, name);
44  }
45  else if (status == NodeStatus::RUNNING)
46  {
47  MTR_BEGIN(category, name);
48  }
49  else if (prev_status == NodeStatus::RUNNING && statusCompleted)
50  {
51  MTR_END(category, name);
52  }
53 }
54 
56 {
58 }
59 } // end namespace
void mtr_shutdown()
Definition: minitrace.cpp:173
virtual NodeType type() const =0
const std::string & name() const
Definition: tree_node.cpp:92
#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
const char * toStr(const BT::NodeStatus &status, bool colored=false)
toStr converts NodeStatus to string. Optionally colored.
Definition: basic_types.cpp:7
static std::atomic< bool > ref_count
MinitraceLogger(TreeNode *root_node, const char *filename_json)
#define MTR_BEGIN(c, n)
Definition: minitrace.h:96
virtual void flush() override
NodeStatus
Definition: basic_types.h:28
#define MTR_INSTANT(c, n)
Definition: minitrace.h:131
void enableTransitionToIdle(bool enable)
std::chrono::high_resolution_clock::duration Duration
Definition: tree_node.h:36
void mtr_flush()
Definition: minitrace.cpp:224


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sun Feb 3 2019 03:14:32