File: tracing_example_8cpp-example.html

package info (click to toggle)
quantlib-refman-html 1.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 84,552 kB
  • ctags: 5,132
  • sloc: makefile: 33
file content (152 lines) | stat: -rw-r--r-- 7,391 bytes parent folder | download
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="robots" content="none">
<title>tracing_example.cpp</title>
<link rel="stylesheet" href="quantlib.css" type="text/css">
<link rel="stylesheet" href="print.css" type="text/css" media="print">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>

<div id="container">
<div id="header">
<img class="titleimage"
 src="QL-title.jpg" width="185" height="50" border="0"
 alt="QuantLib">
<br>
<h3 class="subtitle">A free/open-source library for quantitative finance</h3>
</div>
<div id="menu">

<h3 class="navbartitle">Version 1.2</h3>

<hr>

<h3 class="navbartitle">Getting started</h3>
<ul class="navbarlist">
<li class="navlink"><a href="index.html">Introduction</a></li>
<li class="navlink"><a href="where.html">Where to get QuantLib</a></li>
<li class="navlink"><a href="install.html">Installation</a></li>
<li class="navlink"><a href="config.html">Configuration</a></li>
<li class="navlink"><a href="usage.html">Usage</a></li>
<li class="navlink"><a href="history.html">Version history</a></li>
<li class="navlink"><a href="resources.html">Additional resources</a></li>
<li class="navlink"><a href="group.html">The QuantLib group</a></li>
<li class="navlink"><a href="license.html">Copyright and license</a></li>
</ul>

<hr>

<h3 class="navbartitle">Reference manual</h3>
<ul class="navbarlist">
<li class="navlink"><a href="modules.html">Modules</a></li>
<li class="navlink"><a href="hierarchy.html">Class Hierarchy</a></li>
<li class="navlink"><a href="annotated.html">Compound List</a></li>
<li class="navlink"><a href="files.html">File List</a></li>
<li class="navlink"><a href="functions.html">Compound Members</a></li>
<li class="navlink"><a href="globals.html">File Members</a></li>
<li class="navlink"><a href="todo.html">Todo List</a></li>
<li class="navlink"><a href="bug.html">Known Bugs</a></li>
<li class="navlink"><a href="caveats.html">Caveats</a></li>
<li class="navlink"><a href="test.html">Test Suite</a></li>
<li class="navlink"><a href="examples.html">Examples</a></li>
</ul>
</div>

<div id="content">
<!--Doxygen-generated content-->

<!-- Generated by Doxygen 1.7.6.1 -->
</div>
<div class="header">
  <div class="headertitle">
<div class="title">tracing_example.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>This code exemplifies how to insert trace statements to follow the flow of program execution. When compiler under gcc 3.3 and run, the following program will output the following trace: </p>
<div class="fragment"><pre class="fragment">        trace[1]: Entering <span class="keywordtype">int</span> main()
        trace[2]: Entering <span class="keywordtype">int</span> foo(<span class="keywordtype">int</span>)
        trace[3]: Entering <span class="keywordtype">int</span> Foo::bar(<span class="keywordtype">int</span>)
        trace[3]: i = 21
        trace[3]: At line 16 in tracing_example.cpp
        trace[3]: Wrong answer
        trace[3]: i = 42
        trace[3]: Exiting <span class="keywordtype">int</span> Foo::bar(<span class="keywordtype">int</span>)
        trace[3]: Entering <span class="keywordtype">int</span> Foo::bar(<span class="keywordtype">int</span>)
        trace[3]: i = 42
        trace[3]: At line 13 in tracing_example.cpp
        trace[3]: Right answer, but no question
        trace[3]: i = 42
        trace[3]: Exiting <span class="keywordtype">int</span> Foo::bar(<span class="keywordtype">int</span>)
        trace[2]: Exiting <span class="keywordtype">int</span> foo(<span class="keywordtype">int</span>)
        trace[1]: Exiting <span class="keywordtype">int</span> main()
</pre></div><p> Of course, a word of warning must be added: adding so much tracing to your code might degrade its readability, at least until we devise an Emacs macro to hide trace statements with a couple of keystrokes.</p>
<div class="fragment"><pre class="fragment">
<span class="preprocessor">#include &lt;ql/quantlib.hpp&gt;</span>

<span class="keyword">using namespace </span>QuantLib;

<span class="keyword">namespace </span>Foo {

    <span class="keywordtype">int</span> bar(<span class="keywordtype">int</span> i) {
        <a name="a0"></a><a class="code" href="group__debug_macros.html#ga903ea9f035842ee3560fd787c84887d7" title="output tracing information">QL_TRACE_ENTER_FUNCTION</a>;
        <a name="a1"></a><a class="code" href="group__debug_macros.html#ga7d82587448e3f5531f79cfb215b905af" title="output tracing information">QL_TRACE_VARIABLE</a>(i);

        <span class="keywordflow">if</span> (i == 42) {
            <a name="a2"></a><a class="code" href="group__debug_macros.html#ga4b80d6b6b9d0d17493ac81428934f1c0" title="output tracing information">QL_TRACE_LOCATION</a>;
            <a name="a3"></a><a class="code" href="group__debug_macros.html#ga456b5371fdc64479d393a04b505df5d0" title="output tracing information">QL_TRACE</a>(<span class="stringliteral">&quot;Right answer, but no question&quot;</span>);
        } <span class="keywordflow">else</span> {
            <a class="code" href="group__debug_macros.html#ga4b80d6b6b9d0d17493ac81428934f1c0" title="output tracing information">QL_TRACE_LOCATION</a>;
            <a class="code" href="group__debug_macros.html#ga456b5371fdc64479d393a04b505df5d0" title="output tracing information">QL_TRACE</a>(<span class="stringliteral">&quot;Wrong answer&quot;</span>);
            i *= 2;
        }

        <a class="code" href="group__debug_macros.html#ga7d82587448e3f5531f79cfb215b905af" title="output tracing information">QL_TRACE_VARIABLE</a>(i);
        <a name="a4"></a><a class="code" href="group__debug_macros.html#ga33c013fea8c974f6781441deaa3ea53b" title="output tracing information">QL_TRACE_EXIT_FUNCTION</a>;
        <span class="keywordflow">return</span> i;
    }

}

<span class="keywordtype">int</span> foo(<span class="keywordtype">int</span> i) {
    <span class="keyword">using namespace </span>Foo;
    <a class="code" href="group__debug_macros.html#ga903ea9f035842ee3560fd787c84887d7" title="output tracing information">QL_TRACE_ENTER_FUNCTION</a>;

    <span class="keywordtype">int</span> j = bar(i);
    <span class="keywordtype">int</span> k = bar(j);

    <a class="code" href="group__debug_macros.html#ga33c013fea8c974f6781441deaa3ea53b" title="output tracing information">QL_TRACE_EXIT_FUNCTION</a>;
    <span class="keywordflow">return</span> k;
}

<span class="keywordtype">int</span> main() {

    <a name="a5"></a><a class="code" href="group__debug_macros.html#ga69b168aeab2ef4ff9033469b8214a279" title="enable tracing">QL_TRACE_ENABLE</a>;

    <a class="code" href="group__debug_macros.html#ga903ea9f035842ee3560fd787c84887d7" title="output tracing information">QL_TRACE_ENTER_FUNCTION</a>;

    <span class="keywordtype">int</span> i = foo(21);

    <a class="code" href="group__debug_macros.html#ga33c013fea8c974f6781441deaa3ea53b" title="output tracing information">QL_TRACE_EXIT_FUNCTION</a>;
    <span class="keywordflow">return</span> 0;
}

</pre></div> </div><!-- contents -->
</div><!-- contents -->

</div>

<div class="footer">
<div class="endmatter">
Documentation generated by
<a href="http://www.doxygen.org">Doxygen</a> 1.7.6.1
</div>
</div>

</div>

</body>
</html>