forked from lagadic/visp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial-trace.doc
132 lines (103 loc) · 6.3 KB
/
tutorial-trace.doc
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
\page tutorial-trace Tutorial: Debug and trace printings
\tableofcontents
\section intro_trace Introduction
ViSP allows to introduce trace and debug printings that may help debugging. To this end ViSP provides C or C++ macros that allows to print messages to the standard output std::cout or to std::cerr.
~~~
|----------|-------|-------------------------------------|---------------------------------------|
| output | type | std::cout | std::cerr |
|----------|-------|-------------------------------------|---------------------------------------|
| C-like | trace | vpTRACE, vpTRACE(level) | vpERROR_TRACE, vpERROR_TRACE(level) |
| | trace | vpIN_FCT, vpOUT_FCT | |
| | debug | vpDEBUG_TRACE, vpDEBUG_TRACE(level) | vpDERROR_TRACE, vpDERROR_TRACE(level) |
|----------|-------|-------------------------------------|---------------------------------------|
| C++-like | trace | vpCTRACE | vpCERROR |
| | debug | vpCDEBUG(level) | |
|----------|-------|-------------------------------------|---------------------------------------|
~~~
\subsection trace_macro Macros for trace
Macro for tracing vpTRACE(), vpTRACE(level), vpERROR_TRACE(), vpERROR_TRACE(level),
vpIN_FCT() and vpOUT_FCT()
work like printf with carrier return at the end of the string, while
vpCTRACE() and vpCERROR() work like the C++ output streams std::cout
and std::cerr. All these macro print messages only if VP_TRACE macro is defined.
\subsection debug_macro Macros for debug
Macros for debug vpDEBUG_TRACE(level) and vpDERROR_TRACE(level)
work like printf while vpCDEBUG(level) works like the C++ output stream std::cout.
These macro print messages only if VP_DEBUG macro is defined and
if the debug \e level is greater than the one defined in VP_DEBUG_MODE
macro. Moreover vpDEBUG_ENABLE(level) can be used to check if a given debug level is active; vpDEBUG_ENABLE(level) is
equal to 1 if the debug \e level is greater than the debug mode
VP_DEBUG_MODE, 0 else.
\section debug_trace_usage Debug and trace usage in ViSP library
In ViSP, before an exception is thrown, trace macro are widely used to inform the user that an error occur. This is redundant, since the same trace message in generally associated to the exception that is thrown. Since ViSP 2.9.0, during CMake configuration it is possible to disable debug and trace printings by turning \c ACTIVATE_DEBUG_TRACE cmake variable to \c OFF.
- Using cmake command just run:
\code
%cmake -DACTIVATE_DEBUG_TRACE=OFF <path to ViSP source code>
\endcode
- or using ccmake GUI as shown in the next snapshot:
\image html img-cmake-debug-trace.jpg
\note When \c ACTIVATE_DEBUG_TRACE is turned to \c ON (this is the default behavior in ViSP), we simply define VP_TRACE and VP_DEBUG macro using the compiler -D option.
\section example Debug and trace usage in your own project
If you develop a project that uses ViSP library as a 3rd party, there are different ways to benefit from debug and trace macro described previously.
- If ViSP was build with debug and trace enabled using \c cmake \c ACTIVATE_DEBUG_TRACE=ON, debug and trace are also enabled in your development.
- If debug and trace were disabled in ViSP (\c ACTIVATE_DEBUG_TRACE=OFF), you can enable debug and trace in your own development either by defining \c VP_DEBUG and/or \c VP_TRACE macro in your code using
\code
#define VP_TRACE
#define VP_DEBUG
#include <visp3/core/vpDebug.h>
\endcode
either by modifying your \c CMakeLists.txt file by adding an option as in ViSP:
\code
option(ACTIVATE_DEBUG_TRACE "Enable debug and trace printings" ON)
if(ACTIVATE_DEBUG_TRACE)
add_definitions("-DVP_DEBUG -DVP_TRACE")
endif()
\endcode
The following example also available in tutorial-trace.cpp shows how to use the previous macro.
\includelineno tutorial-trace.cpp
\note In the previous example it is important to notice that the following lines have to be put prior to any other ViSP includes:
\code
#define VP_DEBUG_MODE 2 // Activate debug level 1 and 2
#include <visp3/core/vpDebug.h>
\endcode
For example, if you modify the previous example just by including <visp3/core/vpImage.h> on the top of the file, you will get the following warnings:
\code
Building CXX object tutorial/trace/CMakeFiles/tutorial-trace.dir/tutorial-trace.cpp.o
.../ViSP-code/tutorial/trace/tutorial-trace.cpp:5:1: warning: "VP_DEBUG_MODE" redefined
In file included from .../ViSP-build-debug/include/visp3/core/vpImage.h:52,
from .../ViSP-code/tutorial/trace/tutorial-trace.cpp:2:
.../ViSP-build-debug/include/visp3/core/vpDebug.h:67:1: warning: this is the location of the previous definition
\endcode
When ViSP library was built without debug and trace the previous example produces the output:
\code
%./tutorial-trace
Debug level 1 active: 0
Debug level 2 active: 0
Debug level 3 active: 0
\endcode
When ViSP is rather build with debug and trace the previous example produces the output:
\code
%./tutorial-trace
(L0) begin /tmp/tutorial-trace.cpp: main(#9) : main()
Debug level 1 active: 1
Debug level 2 active: 1
Debug level 3 active: 0
(L0) /tmp/tutorial-trace.cpp: main(#17) : C-like trace
(L1) /tmp/tutorial-trace.cpp: main(#18) : C-like trace level 1
(L0) !! /tmp/tutorial-trace.cpp: main(#20) : C-like error trace
(L1) !! /tmp/tutorial-trace.cpp: main(#21) : C-like error trace level 1
(L0) /tmp/tutorial-trace.cpp: main(#24) : C-like debug trace
(L0) !! /tmp/tutorial-trace.cpp: main(#25) : C-like error trace
(L2) /tmp/tutorial-trace.cpp: main(#27) : C-like debug trace level 2
(L2) !! /tmp/tutorial-trace.cpp: main(#28) : C-like error trace level 2
(L0) /tmp/tutorial-trace.cpp: main(#31) : C++-like trace
(L0) !! /tmp/tutorial-trace.cpp: main(#32) : C++-like error trace
(L2) /tmp/tutorial-trace.cpp: main(#35) : C++-like debug trace level 2
(L0) end /tmp/tutorial-trace.cpp: main(#37) : main()
\endcode
In the previous printings:
- the number after "L" indicates the debug or trace level; example (L2) is for level 2.
- the number after "#" indicates the line of the code that produce the printing; example main(#37) means in function main() at line 37.
- the "!!" indicate that the printing is on std::cerr. Others are on std::cout.
*/