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.root_node )
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 
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 std::string& 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.c_str(), name);
44  }
45  else if (status == NodeStatus::RUNNING)
46  {
47  MTR_BEGIN(category.c_str(), name);
48  }
49  else if (prev_status == NodeStatus::RUNNING && statusCompleted)
50  {
51  MTR_END(category.c_str(), 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
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
std::string toStr(T value)
Definition: basic_types.h:127
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
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
virtual void flush() override
NodeStatus
Definition: basic_types.h:35
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:78
MinitraceLogger(const BT::Tree &tree, const char *filename_json)
#define MTR_INSTANT(c, n)
Definition: minitrace.h:131
void enableTransitionToIdle(bool enable)
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:339
void mtr_flush()
Definition: minitrace.cpp:224


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04