Skip to content

Commit 2c2196d

Browse files
committed
Merge branch 'devel' of github.com:stack-of-tasks/dynamic-graph into devel
2 parents 9bde667 + b5338a7 commit 2c2196d

File tree

6 files changed

+266
-7
lines changed

6 files changed

+266
-7
lines changed

doc/additionalDoc/debug-doc.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
\page debug Debugging
33
44
They are several ways to perform debugging in dynamic-graph depending on your needs or situation:
5+
- Programmatically inside the entity in C++ will write inside a buffer in a different thread and output in a stream
6+
(either std::cout or a file). It is detailed in \subpage subp_debug_rt_logger.
7+
- Programmatically inside the entity in C++ using a member of the entities and the previous real-time mechanism.
8+
It provides 4 levels of messags :(DEBUG,INFO, WARNING, ERROR). It is described in details here:
9+
\subpage subp_logger
10+
- Programmatically in C++ to avoid overhead with macros and handling level as an int: \subpage subp_dbg_trace
511
- If you just need to collect informations from signals (like rosbag). You can use
6-
an entity called Tracer inside the graph:\subpage tracerdoc
7-
- programmatically in C++ with macros \subpage subp_dbg_trace
8-
- programmatically inside the entity in C++ using member of the entities:
9-
\subpage tracerrealtimedoc
12+
an entity called Tracer inside the graph:\subpage tracerdoc . <br>
13+
A real time version exists
14+
to write directly inside a memory buffer \subpage tracerrealtimedoc
1015
**/

doc/additionalDoc/debug-logger.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
\page subp_logger Loggers
3+
4+
\section sec_logger Initialization of the logger
5+
6+
\subsection subsec_logger_hcpp Header and preprocessor variable
7+
8+
In order to activate the logger you need to add the following lines:
9+
\code
10+
#define ENABLE_RT_LOG
11+
#include <dynamic-graph/real-time-logger.h>
12+
#include <dynamic-graph/logger.h>
13+
\endcode
14+
15+
\subsection subsec_logger_ Initialize the output stream
16+
17+
It is possible to set the output stream of the messages inside a file:
18+
\code
19+
dynamicgraph::RealTimeLogger::instance();
20+
of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
21+
dgADD_OSTREAM_TO_RTLOG (of);
22+
23+
dynamicgraph::RealTimeLogger::destroy();
24+
\endcode
25+
Here the file is "/tmp/dg-LOGS.txt".
26+
27+
\subsection subsec_logger_init Initialization of the logger
28+
29+
Inside the constructor of the entity:
30+
\code
31+
logger_.setTimeSample(0.001);
32+
logger_.setStreamPrintPeriod(0.005);
33+
logger_.setVerbosity(VERBOSITY_ALL);
34+
LoggerVerbosity alv = logger_.getVerbosity();
35+
\endcode
36+
37+
The first line sets the frequency at which the logger will be updated.<br>
38+
The second line specifies at which frequency the message should be
39+
printed.<br>
40+
The third line specifies the level of message to accept.<br>
41+
The fourth line returns the level of verbosity.
42+
In this case, all messages are accepted. <br>
43+
44+
The full list of options are:
45+
<ul>
46+
<li>VERBOSITY_ALL: Accept all messages</li>
47+
<li>VERBOSITY_INFO_WARNING_ERROR: Accept messages at minimum level : INFO, WARNING, ERROR</li>
48+
<li>VERBOSITY_WARNING_ERROR: Accept messages at minimum level : WARNING, ERROR</li>
49+
<li>VERBOSITY_ERROR: Accept messages at minimum level : ERROR</li>
50+
</ul>
51+
52+
53+
\section sec_logger_tests Displaying messages
54+
55+
Here is some example on how to display or record some information.
56+
\code
57+
sendMsg("This is a message of level MSG_TYPE_DEBUG",MSG_TYPE_DEBUG);
58+
sendMsg("This is a message of level MSG_TYPE_INFO",MSG_TYPE_INFO);
59+
sendMsg("This is a message of level MSG_TYPE_WARNING",MSG_TYPE_WARNING);
60+
sendMsg("This is a message of level MSG_TYPE_ERROR",MSG_TYPE_ERROR);
61+
sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",MSG_TYPE_DEBUG_STREAM);
62+
sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",MSG_TYPE_INFO_STREAM);
63+
sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",MSG_TYPE_WARNING_STREAM);
64+
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",MSG_TYPE_ERROR_STREAM);
65+
66+
logger_.countdown();
67+
\endcode
68+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
\page subp_debug_rt_logger Real-time Logger
3+
4+
It is intended to be used like this:
5+
\code
6+
#define ENABLE_RT_LOG
7+
#include <dynamic-graph/real-time-logger.h>
8+
9+
// Somewhere in the main function of your executable
10+
int main (int argc, char** argv) {
11+
dgADD_OSTREAM_TO_RTLOG (std::cout);
12+
}
13+
14+
// Somewhere in your library
15+
dgRTLOG() << "your message. Prefer to use \n than std::endl."
16+
\endcode
17+
18+
\note Thread safety. This class expects to have:
19+
- only one reader: the one who take the log entries and write them somewhere.
20+
- one writer at a time. Writing to the logs is **never** a blocking
21+
operation. If the resource is busy, the log entry is discarded.
22+
*/

doc/additionalDoc/extension.h

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
\section usecase How to use this package
55
66
\subsection use_programmatically General introduction
7+
8+
For control purposes the main use of this package is to create new entities and connect them through signals.
9+
710
Objects, which are derived from Entities (base class dynamicgraph::Entity), can be
8-
declared within the code and compiled to shared libraries (.so/.dll files).
11+
declared within the code and compiled as shared libraries (.so/.dll files).
912
These libraries can be loaded at run-time using the PluginLoader methods,
1013
and at the same time register their class names to the Factory (see the
1114
examples in the <a href="http://projects.laas.fr/gepetto/doc/stack-of-tasks/sot-core/master/doxygen-html">sot-core documentation</a>
1215
for advanced control examples).
1316
1417
The Factory can then create instances of these objects and subsequently
15-
register them in the Pool, where they can be listed, accessed, and acted upon
18+
register them in the Pool. From the pool they can be listed, accessed, and acted upon
1619
(see PoolStorage documentation). Basic commands defined by entities include
1720
signal connection graph file generation, help and name print, and signals.
1821
This is usually done through a scripting language such as python (see
@@ -27,12 +30,82 @@ For an example of a program creating entities in C++, see the unit test
2730
test_pool.cpp (in your package source directory/tests).
2831
2932
\subsection Tutorial
30-
A tutorial is available <a href="http://stack-of-tasks.github.io/dynamic-graph-tutorial/">here</a>
33+
A tutorial is available <a href="http://stack-of-tasks.github.io/dynamic-graph-tutorial/">here</a>.
34+
It is providing a step-by-step way of building an entity
3135
3236
\section sec_htw_helpers Helpers
3337
3438
When writing entities you might use some macros which are very useful to write your class.
3539
They are given also in the <a href="http://projects.laas.fr/gepetto/doc/stack-of-tasks/sot-core/master/doxygen-html">sot-core</a> package as well.
3640
41+
\subsection subsec_howto_typedef Entity helpers
42+
43+
The header <b>entity-helper.h</b> is defining a type called EntityClassName
44+
\section sec_howto_macros_helpers Macro helpers
45+
46+
\subsection subsec_howto_macros_helpers Preprocessing macros for signals
47+
48+
<ul>
49+
<li> Macro for input signals
50+
<ul>
51+
<li> <b>DECLARE_SIGNAL_IN(signal_name,type)</b>:
52+
Declare an input time dependent signal as a field of the class with the following name:
53+
\code
54+
m_signal_nameSIN
55+
\endcode
56+
</li>
57+
<li> <b>CONSTRUCT_SIGNAL_IN(signal_name,type)</b>:
58+
This macro is used in the constructor of the entity class handling this signal.
59+
It is calling the signal constructor and set the signal name to:
60+
\code
61+
EntityClassName(entity-name)::input(type)::signal_name
62+
\endcode
63+
</ul>
64+
</li>
65+
<li> Macro for output signals
66+
<ul>
67+
<li> <b>DECLARE_SIGNAL_OUT(signal_name,type)</b>:
68+
Declare an output time dependent signal as a field of the class with the following name:
69+
\code
70+
m_signal_nameSOUT
71+
\endcode
72+
It also declares a method with the following pattern:
73+
\code
74+
type signal_nameSOUT_function(type &,int)
75+
\endcode
76+
The second pattern is the time when calling the output.
77+
</li>
78+
<li> <b>CONSTRUCT_SIGNAL_OUT(signal_name,type)</b>
79+
This macro is used in the constructor of the entity class handling this signal.
80+
It creates the binding to the method described previously, and set the signal name to:
81+
\code
82+
EntityClassName(entity_name)::output(type)::signal_name
83+
\endcode
84+
where entity_name is the name of the entity currently instanciated.
85+
</li>
86+
87+
<li> <b>DEFINE_SIGNAL_OUT_FUNCTION(signal_name, type)</b>:
88+
This macro is used when implementing the method specific to the output signal.
89+
It is used in the main body of the entity class to declare the header of the method
90+
with the following pattern:
91+
\code
92+
type EntityClassName::signal_nameSOUT_function(type &, int iter)
93+
\endcode
94+
</li>
95+
96+
</ul>
97+
<li>
98+
</li>
99+
<li> <b> DECLARE_SIGNAL_INNER(signal_name,type)</b>
100+
Inner signal are signal that depend on a state of the entity and not on input signals.
101+
This macro declares an inner signal with the following pattern:
102+
\code
103+
m_signal_nameSINNER
104+
\endcode
105+
</li>
106+
<li> <b>DEFINE_SIGNAL_INNER_FUNCTION</b>
107+
This macro
108+
</li>
109+
</ul>
37110
38111
*/

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ DYNAMIC_GRAPH_TEST(real-time-logger)
5959
DYNAMIC_GRAPH_TEST(debug-trace)
6060
DYNAMIC_GRAPH_TEST(debug-tracer)
6161
TARGET_LINK_LIBRARIES(debug-tracer tracer)
62+
DYNAMIC_GRAPH_TEST(debug-logger)
63+
DYNAMIC_GRAPH_TEST(debug-logger-winit)

tests/debug-logger.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright 2019, LAAS-CNRS
2+
*
3+
* Olivier Stasse
4+
*
5+
* See LICENSE file
6+
*
7+
*/
8+
#include <sstream>
9+
#include <iostream>
10+
#include <dynamic-graph/entity.h>
11+
#include <dynamic-graph/exception-factory.h>
12+
#include "dynamic-graph/factory.h"
13+
#include "dynamic-graph/pool.h"
14+
15+
#define ENABLE_RT_LOG
16+
#include <dynamic-graph/real-time-logger.h>
17+
#include <dynamic-graph/logger.h>
18+
19+
#define BOOST_TEST_MODULE debug-logger
20+
21+
#include <boost/test/unit_test.hpp>
22+
#include <boost/test/output_test_stream.hpp>
23+
24+
using boost::test_tools::output_test_stream;
25+
26+
27+
namespace dynamicgraph
28+
{
29+
class CustomEntity : public Entity
30+
{
31+
public:
32+
static const std::string CLASS_NAME;
33+
virtual const std::string& getClassName () const
34+
{
35+
return CLASS_NAME;
36+
}
37+
CustomEntity (const std::string n)
38+
: Entity (n)
39+
{
40+
logger_.setTimeSample(0.001);
41+
logger_.setStreamPrintPeriod(0.005);
42+
logger_.setVerbosity(VERBOSITY_ALL);
43+
LoggerVerbosity alv = logger_.getVerbosity();
44+
BOOST_CHECK(alv==VERBOSITY_ALL);
45+
}
46+
47+
~CustomEntity()
48+
{
49+
}
50+
void testDebugTrace()
51+
{
52+
sendMsg("This is a message of level MSG_TYPE_DEBUG",MSG_TYPE_DEBUG);
53+
sendMsg("This is a message of level MSG_TYPE_INFO",MSG_TYPE_INFO);
54+
sendMsg("This is a message of level MSG_TYPE_WARNING",MSG_TYPE_WARNING);
55+
sendMsg("This is a message of level MSG_TYPE_ERROR",MSG_TYPE_ERROR);
56+
sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",MSG_TYPE_DEBUG_STREAM);
57+
sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",MSG_TYPE_INFO_STREAM);
58+
sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",MSG_TYPE_WARNING_STREAM);
59+
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",MSG_TYPE_ERROR_STREAM);
60+
61+
logger_.countdown();
62+
63+
}
64+
};
65+
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");
66+
}
67+
68+
BOOST_AUTO_TEST_CASE(debug_logger)
69+
{
70+
std::ofstream of;
71+
dynamicgraph::RealTimeLogger::instance();
72+
of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
73+
dgADD_OSTREAM_TO_RTLOG (of);
74+
75+
BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
76+
77+
dynamicgraph::CustomEntity& entity = *(dynamic_cast<dynamicgraph::CustomEntity *>(
78+
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
79+
"my-entity")));
80+
81+
for(unsigned int i=0;i<10000;i++)
82+
{
83+
entity.testDebugTrace();
84+
}
85+
86+
dynamicgraph::RealTimeLogger::destroy();
87+
}
88+
89+

0 commit comments

Comments
 (0)