Repository navigation
Expand file tree
/
Copy pathbt_minitrace_logger.cpp
More file actions
76 lines (65 loc) · 1.54 KB
/
Copy pathbt_minitrace_logger.cpp
File metadata and controls
76 lines (65 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "behaviortree_cpp/loggers/bt_minitrace_logger.h"
#define MTR_ENABLED true
#include "minitrace.h"
namespace BT
{
MinitraceLogger::MinitraceLogger(const Tree& tree, const char* filename_json)
: StatusChangeLogger(tree.rootNode())
{
mtr_register_sigint_handler();
mtr_init(filename_json);
this->enableTransitionToIdle(true);
}
MinitraceLogger::~MinitraceLogger()
{
// Stop status callbacks before shutting down minitrace.
unsubscribeFromTreeChanges();
mtr_flush();
mtr_shutdown();
}
namespace
{
const char* toConstStr(NodeType type)
{
switch(type)
{
case NodeType::ACTION:
return "Action";
case NodeType::CONDITION:
return "Condition";
case NodeType::DECORATOR:
return "Decorator";
case NodeType::CONTROL:
return "Control";
case NodeType::SUBTREE:
return "SubTree";
default:
return "Undefined";
}
}
} // namespace
void MinitraceLogger::callback(Duration /*timestamp*/, const TreeNode& node,
NodeStatus prev_status, NodeStatus status)
{
const bool statusCompleted = isStatusCompleted(status);
const char* category = toConstStr(node.type());
const char* name = node.name().c_str();
if(prev_status == NodeStatus::IDLE && statusCompleted)
{
MTR_INSTANT(category, name);
}
else if(status == NodeStatus::RUNNING)
{
MTR_BEGIN(category, name);
}
else if(prev_status == NodeStatus::RUNNING && statusCompleted)
{
MTR_END(category, name);
}
mtr_flush();
}
void MinitraceLogger::flush()
{
mtr_flush();
}
} // namespace BT