Mercurial > octave-nkf
annotate doc/interpreter/debug.txi @ 18189:d638db6d045c stable
doc: Note that dbstop can be used with class methods as well (bug #40958).
* debug.txi: Note that dbstop can be used with class methods as well
(bug #40958).
author | Rik <rik@octave.org> |
---|---|
date | Wed, 01 Jan 2014 18:24:55 -0800 |
parents | dae2230227a7 |
children | 7e39cbefe299 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17097
diff
changeset
|
1 @c Copyright (C) 1996-2013 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
4175 | 18 |
19 @node Debugging | |
20 @chapter Debugging | |
21 | |
6646 | 22 Octave includes a built-in debugger to aid in the development of |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 scripts. This can be used to interrupt the execution of an Octave script |
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 at a certain point, or when certain conditions are met. Once execution |
6646 | 25 has stopped, and debug mode is entered, the symbol table at the point |
26 where execution has stopped can be examined and modified to check for | |
27 errors. | |
4175 | 28 |
8485
2beb59bf773a
[docs] commandline => command-line
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
29 The normal command-line editing and history functions are available in |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
30 debug mode. |
6646 | 31 |
32 @menu | |
33 * Entering Debug Mode:: | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
34 * Leaving Debug Mode:: |
6646 | 35 * Breakpoints:: |
36 * Debug Mode:: | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
37 * Call Stack:: |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
38 * Profiling:: |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
39 * Profiler Example:: |
6646 | 40 @end menu |
4175 | 41 |
6646 | 42 @node Entering Debug Mode |
43 @section Entering Debug Mode | |
4175 | 44 |
6646 | 45 There are two basic means of interrupting the execution of an Octave |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16844
diff
changeset
|
46 script. These are breakpoints (@pxref{Breakpoints}), discussed in the next |
6646 | 47 section and interruption based on some condition. |
48 | |
49 Octave supports three means to stop execution based on the values set in | |
50 the functions @code{debug_on_interrupt}, @code{debug_on_warning} and | |
51 @code{debug_on_error}. | |
4175 | 52 |
4185 | 53 @DOCSTRING(debug_on_interrupt) |
4175 | 54 |
55 @DOCSTRING(debug_on_warning) | |
4185 | 56 |
57 @DOCSTRING(debug_on_error) | |
6646 | 58 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
59 @node Leaving Debug Mode |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
60 @section Leaving Debug Mode |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
61 |
8828 | 62 To leave the debug mode, use either @code{dbcont} |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
63 or @code{return}. |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
64 |
8275 | 65 @DOCSTRING(dbcont) |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
66 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
67 To quit debug mode and return directly to the prompt @code{dbquit} |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
68 should be used instead |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
69 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
70 @DOCSTRING(dbquit) |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
71 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
72 Finally, typing @code{exit} or @code{quit} at the debug prompt will |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
73 result in Octave terminating normally. |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
74 |
6646 | 75 @node Breakpoints |
76 @section Breakpoints | |
77 | |
78 Breakpoints can be set in any Octave function, using the @code{dbstop} | |
79 function. | |
80 | |
81 @DOCSTRING(dbstop) | |
82 | |
83 @noindent | |
18189
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
84 Breakpoints in class methods are also supported (e.g., |
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
85 @code{dbstop("@@class/method")}). However, breakpoints cannot be set in |
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
86 built-in functions (e.g., @code{sin}, etc.) or dynamically loaded function |
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
87 (i.e., oct-files). |
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
88 |
d638db6d045c
doc: Note that dbstop can be used with class methods as well (bug #40958).
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
89 To set a breakpoint immediately on entering a function, the breakpoint |
6646 | 90 should be set to line 1. The leading comment block will be ignored and |
91 the breakpoint will be set to the first executable statement in the | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
92 function. For example: |
6646 | 93 |
94 @example | |
95 @group | |
96 dbstop ("asind", 1) | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
97 @result{} 29 |
6646 | 98 @end group |
99 @end example | |
100 | |
101 @noindent | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
102 Note that the return value of @code{29} means that the breakpoint was |
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
103 effectively set to line 29. The status of breakpoints in a function can |
6646 | 104 be queried with the @code{dbstatus} function. |
105 | |
106 @DOCSTRING(dbstatus) | |
107 | |
108 @noindent | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
109 Reusing the previous example, @code{dbstatus ("asind")} will return |
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
110 29. The breakpoints listed can then be cleared with the @code{dbclear} |
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
111 function. |
6646 | 112 |
113 @DOCSTRING(dbclear) | |
114 | |
115 @noindent | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
116 These functions can be used together to clear all the breakpoints in a |
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
117 particular function. For example: |
6646 | 118 |
119 @example | |
120 dbclear ("asind", dbstatus ("asind")); | |
121 @end example | |
122 | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
123 A breakpoint may also be set in a subfunction. For example, if a file contains |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
124 the functions |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
125 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
126 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
127 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
128 function y = func1 (x) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
129 y = func2 (x); |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
130 endfunction |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
131 function y = func2 (x) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
132 y = x + 1; |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
133 endfunction |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
134 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
135 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
136 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
137 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
138 then a breakpoint can be set at the start of the subfunction directly |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
139 with |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
140 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
141 @example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
142 @group |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
143 dbstop (["func1", filemarker(), "func2"]) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
144 @result{} 5 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
145 @end group |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
146 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
147 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
148 Note that @code{filemarker} returns a character that marks the |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
149 subfunctions from the file containing them. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7787
diff
changeset
|
150 |
8828 | 151 Another simple way of setting a breakpoint in an Octave script is the |
6646 | 152 use of the @code{keyboard} function. |
153 | |
154 @DOCSTRING(keyboard) | |
155 | |
156 @noindent | |
157 The @code{keyboard} function is typically placed in a script at the | |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
158 point where the user desires that the execution be stopped. It |
6646 | 159 automatically sets the running script into the debug mode. |
160 | |
161 @node Debug Mode | |
162 @section Debug Mode | |
163 | |
16842
035b5fe157ad
Add new dblist command to debugger (bug #38953)
Rik <rik@octave.org>
parents:
16771
diff
changeset
|
164 There are three additional support functions that allow the user to |
6646 | 165 interrogate where in the execution of a script Octave entered the debug |
166 mode and to print the code in the script surrounding the point where | |
167 Octave entered debug mode. | |
168 | |
169 @DOCSTRING(dbwhere) | |
170 | |
171 @DOCSTRING(dbtype) | |
6647 | 172 |
16842
035b5fe157ad
Add new dblist command to debugger (bug #38953)
Rik <rik@octave.org>
parents:
16771
diff
changeset
|
173 @DOCSTRING(dblist) |
035b5fe157ad
Add new dblist command to debugger (bug #38953)
Rik <rik@octave.org>
parents:
16771
diff
changeset
|
174 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8485
diff
changeset
|
175 You may also use @code{isdebugmode} to determine whether the debugger is |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8485
diff
changeset
|
176 currently active. |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8485
diff
changeset
|
177 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8485
diff
changeset
|
178 @DOCSTRING(isdebugmode) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8485
diff
changeset
|
179 |
8828 | 180 Debug mode also allows single line stepping through a function using |
16771
d8a719ccd464
doc: Improve documentation for command debugger.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
181 the command @code{dbstep}. |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
182 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
183 @DOCSTRING(dbstep) |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
184 |
16844
1b0650075a74
doc: Add note about function of <RETURN> key in debug mode.
Rik <rik@octave.org>
parents:
16842
diff
changeset
|
185 When in debug mode the @key{RETURN} will execute the last entered command. |
1b0650075a74
doc: Add note about function of <RETURN> key in debug mode.
Rik <rik@octave.org>
parents:
16842
diff
changeset
|
186 This is useful, for example, after hitting a breakpoint and entering |
1b0650075a74
doc: Add note about function of <RETURN> key in debug mode.
Rik <rik@octave.org>
parents:
16842
diff
changeset
|
187 @code{dbstep}. After that one can advance line by line through the code |
1b0650075a74
doc: Add note about function of <RETURN> key in debug mode.
Rik <rik@octave.org>
parents:
16842
diff
changeset
|
188 with only a single key stroke. |
1b0650075a74
doc: Add note about function of <RETURN> key in debug mode.
Rik <rik@octave.org>
parents:
16842
diff
changeset
|
189 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
190 @node Call Stack |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
191 @section Call Stack |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
192 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
193 @DOCSTRING(dbstack) |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
194 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
195 @DOCSTRING(dbup) |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
196 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
197 @DOCSTRING(dbdown) |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
198 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
199 @node Profiling |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
200 @section Profiling |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
201 @cindex profiler |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
202 @cindex code profiling |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
203 |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
204 Octave supports profiling of code execution on a per-function level. If |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
205 profiling is enabled, each call to a function (supporting built-ins, |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
206 operators, functions in oct- and mex-files, user-defined functions in |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
207 Octave code and anonymous functions) is recorded while running Octave |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
208 code. After that, this data can aid in analyzing the code behavior, and |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
209 is in particular helpful for finding ``hot spots'' in the code which use |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
210 up a lot of computation time and are the best targets to spend |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
211 optimization efforts on. |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
212 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
213 The main command for profiling is @code{profile}, which can be used to |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
214 start or stop the profiler and also to query collected data afterwards. |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
215 The data is returned in an Octave data structure which can then be |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
216 examined or further processed by other routines or tools. |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
217 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
218 @DOCSTRING(profile) |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
219 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
220 An easy way to get an overview over the collected data is |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
221 @code{profshow}. This function takes the profiler data returned by |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
222 @code{profile} as input and prints a flat profile, for instance: |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
223 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
224 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
225 @group |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
226 Function Attr Time (s) Calls |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
227 ---------------------------------------- |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
228 >myfib R 2.195 13529 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
229 binary <= 0.061 13529 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
230 binary - 0.050 13528 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
231 binary + 0.026 6764 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
232 @end group |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
233 @end example |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
234 |
13931
9de488c6c59c
doc: Spellcheck documentation before 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
13195
diff
changeset
|
235 This shows that most of the run time was spent executing the function |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
236 @samp{myfib}, and some minor proportion evaluating the listed binary |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
237 operators. Furthermore, it is shown how often the function was called |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
238 and the profiler also records that it is recursive. |
12976
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
239 |
2e20c26b1007
Document the profiler functions.
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
240 @DOCSTRING(profshow) |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
241 |
13195
08650b6fbf67
document profexplore and include it in the list of files to distribute
John W. Eaton <jwe@octave.org>
parents:
12979
diff
changeset
|
242 @DOCSTRING(profexplore) |
08650b6fbf67
document profexplore and include it in the list of files to distribute
John W. Eaton <jwe@octave.org>
parents:
12979
diff
changeset
|
243 |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
244 @node Profiler Example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
245 @section Profiler Example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
246 |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16844
diff
changeset
|
247 Below, we will give a short example of a profiler session. |
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16844
diff
changeset
|
248 @xref{Profiling}, for the documentation of the profiler functions in |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
249 detail. Consider the code: |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
250 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
251 @example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
252 global N A; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
253 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
254 N = 300; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
255 A = rand (N, N); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
256 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
257 function xt = timesteps (steps, x0, expM) |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
258 global N; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
259 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
260 if (steps == 0) |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
261 xt = NA (N, 0); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
262 else |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
263 xt = NA (N, steps); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
264 x1 = expM * x0; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
265 xt(:, 1) = x1; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
266 xt(:, 2 : end) = timesteps (steps - 1, x1, expM); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
267 endif |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
268 endfunction |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
269 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
270 function foo () |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
271 global N A; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
272 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
273 initial = @@(x) sin (x); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
274 x0 = (initial (linspace (0, 2 * pi, N)))'; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
275 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
276 expA = expm (A); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
277 xt = timesteps (100, x0, expA); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
278 endfunction |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
279 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
280 function fib = bar (N) |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
281 if (N <= 2) |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
282 fib = 1; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
283 else |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
284 fib = bar (N - 1) + bar (N - 2); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
285 endif |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
286 endfunction |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
287 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
288 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
289 If we execute the two main functions, we get: |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
290 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
291 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
292 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
293 tic; foo; toc; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
294 @result{} Elapsed time is 2.37338 seconds. |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
295 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
296 tic; bar (20); toc; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
297 @result{} Elapsed time is 2.04952 seconds. |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
298 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
299 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
300 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
301 But this does not give much information about where this time is spent; |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
302 for instance, whether the single call to @code{expm} is more expensive |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
303 or the recursive time-stepping itself. To get a more detailed picture, |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
304 we can use the profiler. |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
305 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
306 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
307 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
308 profile on; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
309 foo; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
310 profile off; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
311 |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
312 data = profile ("info"); |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
313 profshow (data, 10); |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
314 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
315 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
316 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
317 This prints a table like: |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
318 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
319 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
320 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
321 # Function Attr Time (s) Calls |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
322 --------------------------------------------- |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
323 7 expm 1.034 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
324 3 binary * 0.823 117 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
325 41 binary \ 0.188 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
326 38 binary ^ 0.126 2 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
327 43 timesteps R 0.111 101 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
328 44 NA 0.029 101 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
329 39 binary + 0.024 8 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
330 34 norm 0.011 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
331 40 binary - 0.004 101 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
332 33 balance 0.003 1 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
333 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
334 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
335 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
336 The entries are the individual functions which have been executed (only |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
337 the 10 most important ones), together with some information for each of |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
338 them. The entries like @samp{binary *} denote operators, while other |
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
339 entries are ordinary functions. They include both built-ins like |
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
340 @code{expm} and our own routines (for instance @code{timesteps}). From |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
341 this profile, we can immediately deduce that @code{expm} uses up the |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
342 largest proportion of the processing time, even though it is only called |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
343 once. The second expensive operation is the matrix-vector product in the |
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
344 routine @code{timesteps}. @footnote{We only know it is the binary |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
345 multiplication operator, but fortunately this operator appears only at |
13931
9de488c6c59c
doc: Spellcheck documentation before 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
13195
diff
changeset
|
346 one place in the code and thus we know which occurrence takes so much |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
347 time. If there were multiple places, we would have to use the |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
348 hierarchical profile to find out the exact place which uses up the time |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
349 which is not covered in this example.} |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
350 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
351 Timing, however, is not the only information available from the profile. |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
352 The attribute column shows us that @code{timesteps} calls itself |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
353 recursively. This may not be that remarkable in this example (since it's |
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
354 clear anyway), but could be helpful in a more complex setting. As to the |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
355 question of why is there a @samp{binary \} in the output, we can easily |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
356 shed some light on that too. Note that @code{data} is a structure array |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
357 (@ref{Structure Arrays}) which contains the field @code{FunctionTable}. |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
358 This stores the raw data for the profile shown. The number in the first |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
359 column of the table gives the index under which the shown function can |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
360 be found there. Looking up @code{data.FunctionTable(41)} gives: |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
361 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
362 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
363 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
364 scalar structure containing the fields: |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
365 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
366 FunctionName = binary \ |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
367 TotalTime = 0.18765 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
368 NumCalls = 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
369 IsRecursive = 0 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
370 Parents = 7 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
371 Children = [](1x0) |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
372 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
373 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
374 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
375 Here we see the information from the table again, but have additional |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
376 fields @code{Parents} and @code{Children}. Those are both arrays, which |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
377 contain the indices of functions which have directly called the function |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
378 in question (which is entry 7, @code{expm}, in this case) or been called |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
379 by it (no functions). Hence, the backslash operator has been used |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
380 internally by @code{expm}. |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
381 |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
382 Now let's take a look at @code{bar}. For this, we start a fresh |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
383 profiling session (@code{profile on} does this; the old data is removed |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
384 before the profiler is restarted): |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
385 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
386 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
387 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
388 profile on; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
389 bar (20); |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
390 profile off; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
391 |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 profshow (profile ("info")); |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
393 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
394 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
395 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
396 This gives: |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
397 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
398 @example |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
399 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
400 # Function Attr Time (s) Calls |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
401 ------------------------------------------------------- |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
402 1 bar R 2.091 13529 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
403 2 binary <= 0.062 13529 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
404 3 binary - 0.042 13528 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
405 4 binary + 0.023 6764 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
406 5 profile 0.000 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
407 8 false 0.000 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
408 6 nargin 0.000 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
409 7 binary != 0.000 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
410 9 __profiler_enable__ 0.000 1 |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
411 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
412 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
413 |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
414 Unsurprisingly, @code{bar} is also recursive. It has been called 13,529 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
415 times in the course of recursively calculating the Fibonacci number in a |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
416 suboptimal way, and most of the time was spent in @code{bar} itself. |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
417 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
418 Finally, let's say we want to profile the execution of both @code{foo} |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13931
diff
changeset
|
419 and @code{bar} together. Since we already have the run-time data |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
420 collected for @code{bar}, we can restart the profiler without clearing |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
421 the existing data and collect the missing statistics about @code{foo}. |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
422 This is done by: |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
423 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
424 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
425 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
426 profile resume; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
427 foo; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
428 profile off; |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
429 |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 profshow (profile ("info"), 10); |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
431 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
432 @end example |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
433 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
434 As you can see in the table below, now we have both profiles mixed |
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
435 together. |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
436 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
437 @example |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
438 @group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
439 # Function Attr Time (s) Calls |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
440 --------------------------------------------- |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
441 1 bar R 2.091 13529 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
442 16 expm 1.122 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
443 12 binary * 0.798 117 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
444 46 binary \ 0.185 1 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
445 45 binary ^ 0.124 2 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
446 48 timesteps R 0.115 101 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
447 2 binary <= 0.062 13529 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
448 3 binary - 0.045 13629 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
449 4 binary + 0.041 6772 |
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
450 49 NA 0.036 101 |
12979
6a9fbeff3368
Proofread profiler documentation
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12978
diff
changeset
|
451 @end group |
12978
fb0f40cd8752
Add an example profiler session to the manual.
Daniel Kraft <d@domob.eu>
parents:
12976
diff
changeset
|
452 @end example |