Mercurial > octave
annotate libinterp/parse-tree/profiler.cc @ 23795:980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
* Backend.cc, BaseControl.h, ButtonGroup.cc, CheckBoxControl.cc,
Container.cc, ContextMenu.cc, ContextMenu.h, EditControl.cc, Figure.cc,
FigureWindow.cc, ListBoxControl.cc, Menu.cc, Menu.h, MouseModeActionGroup.cc,
Object.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc,
PushTool.cc, RadioButtonControl.cc, SliderControl.cc, TextControl.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, ToolBar.h, ToolBarButton.cc,
ToolBarButton.h, QTerminal.h, BlockArray.cpp, Emulation.cpp, Filter.cpp,
Filter.h, History.cpp, KeyboardTranslator.cpp, QUnixTerminalImpl.h, Screen.cpp,
ScreenWindow.cpp, ScreenWindow.h, SelfListener.h, TerminalCharacterDecoder.cpp,
TerminalModel.cpp, TerminalView.cpp, TerminalView.h, kpty.cpp, dialog.cc,
dialog.h, files-dock-widget.cc, find-files-model.h, file-editor-tab.cc,
file-editor.cc, main-window.cc, octave-dock-widget.cc, octave-gui.cc,
parser.cc, resource-manager.cc, resource-manager.h, shortcut-manager.cc,
shortcut-manager.h, workspace-model.cc, workspace-view.cc, __magick_read__.cc,
c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h,
daspk.cc, dasrt.cc, dassl.cc, det.cc, display.h, error.cc, ft-text-renderer.cc,
gl-render.cc, gl2ps-print.cc, graphics.in.h, help.cc, input.cc, interpreter.cc,
load-path.cc, load-save.cc, ls-hdf5.cc, ls-hdf5.h, ls-mat5.cc, lsode.cc,
mex.cc, mxarray.in.h, oct-errno.h, oct-hist.cc, oct-iostrm.h, oct-procbuf.cc,
oct-procbuf.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h,
oct-tex-parser.in.yy, octave-link.h, pager.cc, pager.h, pr-output.cc,
procstream.h, qz.cc, sighandlers.cc, svd.cc, symtab.cc, symtab.h,
text-renderer.cc, txt-eng.h, utils.cc, variables.cc, zfstream.cc, zfstream.h,
__glpk__.cc, __init_fltk__.cc, __ode15__.cc, audiodevinfo.cc, ccolamd.cc,
colamd.cc, dmperm.cc, gzip.cc, symbfact.cc, ov-base-int.cc, ov-base-int.h,
ov-base-mat.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-sparse.cc,
ov-bool.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-complex.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-fcn.h,
ov-float.cc, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc,
ov-java.h, ov-mex-fcn.cc, ov-oncleanup.cc, ov-range.cc, ov-range.h,
ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-typeinfo.cc,
ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, octave.cc, bp-table.cc,
bp-table.h, jit-ir.h, jit-typeinfo.cc, lex.h, profiler.cc, pt-arg-list.cc,
pt-array-list.cc, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h,
pt-cell.cc, pt-classdef.cc, pt-classdef.h, pt-colon.cc, pt-colon.h, pt-decl.cc,
pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.h, pt-fcn-handle.cc,
pt-fcn-handle.h, pt-idx.cc, pt-jit.cc, pt-loop.h, pt-mat.cc, pt-select.h,
pt-stmt.h, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt.cc, Array-C.cc, Array-d.cc,
Array-f.cc, Array-fC.cc, Array-util.cc, Array.cc, Array.h, CMatrix.cc,
CSparse.cc, DiagArray2.h, MArray.h, MDiagArray2.h, MatrixType.cc, Sparse.cc,
Sparse.h, dMatrix.cc, dSparse.cc, fMatrix.cc, idx-vector.cc, idx-vector.h,
DAEFunc.h, DAERTFunc.h, ODEFunc.h, ODESFunc.h, eigs-base.cc, oct-fftw.cc,
oct-fftw.h, oct-rand.h, oct-spparms.h, schur.cc, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, child-list.h, dir-ops.cc,
dir-ops.h, file-ops.cc, lo-sysdep.cc, oct-env.h, oct-time.cc, cmd-edit.cc,
cmd-edit.h, cmd-hist.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, oct-shlib.cc,
oct-shlib.h, oct-sort.cc, oct-sort.h, quit.cc, singleton-cleanup.h, str-vec.cc:
Use C++11 nullptr rather than 0 in code (bug #51565).
author | Rik <rik@octave.org> |
---|---|
date | Tue, 25 Jul 2017 14:54:10 -0700 |
parents | c3828bd031cd |
children | 194eb4bd202b |
rev | line source |
---|---|
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
1 /* |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
2 |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2014-2017 Julien Bect |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22131
diff
changeset
|
4 Copyright (C) 2012-2016 Daniel Kraft |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
5 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
6 This file is part of Octave. |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
7 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
8 Octave is free software; you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
11 (at your option) any later version. |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
16 GNU General Public License for more details. |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
17 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
21 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
22 */ |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
23 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
26 #endif |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
27 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
28 #include <iostream> |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
29 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
30 #include "defun.h" |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
31 #include "interpreter.h" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
32 #include "oct-time.h" |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
33 #include "ov-struct.h" |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
34 #include "pager.h" |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
35 #include "profiler.h" |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
36 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
37 namespace octave |
12869
de9a9719e594
Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents:
12784
diff
changeset
|
38 { |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
39 profiler::stats::stats () |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
40 : time (0.0), calls (0), recursive (false), |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
41 parents (), children () |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
42 { } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
43 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
44 octave_value |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
45 profiler::stats::function_set_value (const function_set& list) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
46 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
47 const octave_idx_type n = list.size (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
48 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
49 RowVector retval (n); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
50 octave_idx_type i = 0; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
51 for (const auto& nm : list) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
52 retval(i++) = nm; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
53 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
54 assert (i == n); |
12869
de9a9719e594
Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents:
12784
diff
changeset
|
55 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
56 return retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
57 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
58 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
59 profiler::tree_node::tree_node (tree_node *p, octave_idx_type f) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
60 : parent (p), fcn_id (f), children (), time (0.0), calls (0) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
61 { } |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
62 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
63 profiler::tree_node::~tree_node () |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
64 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
65 for (auto& idx_tnode : children) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
66 delete idx_tnode.second; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
67 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
68 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
69 profiler::tree_node* |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
70 profiler::tree_node::enter (octave_idx_type fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
71 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
72 tree_node *retval; |
12869
de9a9719e594
Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents:
12784
diff
changeset
|
73 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
74 child_map::iterator pos = children.find (fcn); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
75 if (pos == children.end ()) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
76 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
77 retval = new tree_node (this, fcn); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
78 children[fcn] = retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
79 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
80 else |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
81 retval = pos->second; |
12869
de9a9719e594
Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents:
12784
diff
changeset
|
82 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
83 ++retval->calls; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
84 return retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
85 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
86 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
87 profiler::tree_node* |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
88 profiler::tree_node::exit (octave_idx_type /* fcn */) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
89 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
90 // FIXME: These assert statements don't make sense if profile() is called |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
91 // from within a function hierarchy to begin with. See bug #39587. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
92 // assert (parent); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
93 // assert (fcn_id == fcn); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
94 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
95 return parent; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
96 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
97 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
98 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
99 profiler::tree_node::build_flat (flat_profile& data) const |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
100 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
101 // If this is not the top-level node, update profile entry for this function. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
102 if (fcn_id != 0) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
103 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
104 stats& entry = data[fcn_id - 1]; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
105 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
106 entry.time += time; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
107 entry.calls += calls; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
108 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
109 assert (parent); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
110 if (parent->fcn_id != 0) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
111 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
112 entry.parents.insert (parent->fcn_id); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
113 data[parent->fcn_id - 1].children.insert (fcn_id); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
114 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
115 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
116 if (! entry.recursive) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
117 for (const tree_node *i = parent; i; i = i->parent) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
118 if (i->fcn_id == fcn_id) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
119 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
120 entry.recursive = true; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
121 break; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
122 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
123 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
124 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
125 // Recurse on children. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
126 for (const auto& idx_tnode : children) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
127 idx_tnode.second->build_flat (data); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
128 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
129 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
130 octave_value |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
131 profiler::tree_node::get_hierarchical (double *total) const |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
132 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
133 // Note that we don't generate the entry just for this node, but |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
134 // rather a struct-array with entries for all children. This way, the |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
135 // top-node (for which we don't want a real entry) generates already |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
136 // the final hierarchical profile data. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
137 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
138 const octave_idx_type n = children.size (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
139 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
140 Cell rv_indices (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
141 Cell rv_times (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
142 Cell rv_totals (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
143 Cell rv_calls (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
144 Cell rv_children (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
145 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
146 octave_idx_type i = 0; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
147 for (const auto& idx_tnode : children) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
148 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
149 const tree_node& entry = *idx_tnode.second; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
150 double child_total = entry.time; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
151 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
152 rv_indices(i) = octave_value (idx_tnode.first); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
153 rv_times(i) = octave_value (entry.time); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
154 rv_calls(i) = octave_value (entry.calls); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
155 rv_children(i) = entry.get_hierarchical (&child_total); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
156 rv_totals(i) = octave_value (child_total); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
157 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
158 if (total) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
159 *total += child_total; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
160 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
161 ++i; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
162 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
163 assert (i == n); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
164 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
165 octave_map retval; |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
166 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
167 retval.assign ("Index", rv_indices); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
168 retval.assign ("SelfTime", rv_times); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
169 retval.assign ("TotalTime", rv_totals); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
170 retval.assign ("NumCalls", rv_calls); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
171 retval.assign ("Children", rv_children); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
172 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
173 return retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
174 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
175 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
176 profiler::profiler (void) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
177 : known_functions (), fcn_index (), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
178 enabled (false), call_tree (new tree_node (nullptr, 0)), |
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
179 active_fcn (nullptr), last_time (-1.0) |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
180 { } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
181 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
182 profiler::~profiler (void) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
183 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
184 delete call_tree; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
185 } |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13052
diff
changeset
|
186 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
187 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
188 profiler::set_active (bool value) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
189 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
190 enabled = value; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
191 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
192 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
193 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
194 profiler::enter_function (const std::string& fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
195 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
196 // The enter class will check and only call us if the profiler is active. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
197 assert (is_active ()); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
198 assert (call_tree); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
199 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
200 // If there is already an active function, add to its time before |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
201 // pushing the new one. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
202 if (active_fcn && active_fcn != call_tree) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
203 add_current_time (); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
204 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
205 // Map the function's name to its index. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
206 octave_idx_type fcn_idx; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
207 fcn_index_map::iterator pos = fcn_index.find (fcn); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
208 if (pos == fcn_index.end ()) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
209 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
210 known_functions.push_back (fcn); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
211 fcn_idx = known_functions.size (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
212 fcn_index[fcn] = fcn_idx; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
213 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
214 else |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
215 fcn_idx = pos->second; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
216 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
217 if (! active_fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
218 active_fcn = call_tree; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
219 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
220 active_fcn = active_fcn->enter (fcn_idx); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
221 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
222 last_time = query_time (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
223 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
224 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
225 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
226 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
227 profiler::exit_function (const std::string& fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
228 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
229 if (active_fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
230 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
231 assert (call_tree); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
232 // FIXME: This assert statements doesn't make sense if profile() is called |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
233 // from within a function hierarchy to begin with. See bug #39587. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
234 //assert (active_fcn != call_tree); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
235 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
236 // Usually, if we are disabled this function is not even called. But the |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
237 // call disabling the profiler is an exception. So also check here |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
238 // and only record the time if enabled. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
239 if (is_active ()) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
240 add_current_time (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
241 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
242 fcn_index_map::iterator pos = fcn_index.find (fcn); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
243 // FIXME: This assert statements doesn't make sense if profile() is called |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
244 // from within a function hierarchy to begin with. See bug #39587. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
245 //assert (pos != fcn_index.end ()); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
246 active_fcn = active_fcn->exit (pos->second); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
247 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
248 // If this was an "inner call", we resume executing the parent function |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
249 // up the stack. So note the start-time for this! |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
250 last_time = query_time (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
251 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
252 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
253 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
254 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
255 profiler::reset (void) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
256 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
257 if (is_active ()) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
258 error ("Can't reset active profiler."); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
259 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
260 known_functions.clear (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
261 fcn_index.clear (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
262 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
263 if (call_tree) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
264 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
265 delete call_tree; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
266 call_tree = new tree_node (nullptr, 0); |
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
267 active_fcn = nullptr; |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
268 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
269 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
270 last_time = -1.0; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
271 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
272 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
273 octave_value |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
274 profiler::get_flat (void) const |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
275 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
276 octave_value retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
277 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
278 const octave_idx_type n = known_functions.size (); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
279 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
280 flat_profile flat (n); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
281 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
282 if (call_tree) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
283 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
284 call_tree->build_flat (flat); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
285 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
286 Cell rv_names (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
287 Cell rv_times (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
288 Cell rv_calls (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
289 Cell rv_recursive (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
290 Cell rv_parents (n, 1); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
291 Cell rv_children (n, 1); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
292 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
293 for (octave_idx_type i = 0; i != n; ++i) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
294 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
295 rv_names(i) = octave_value (known_functions[i]); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
296 rv_times(i) = octave_value (flat[i].time); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
297 rv_calls(i) = octave_value (flat[i].calls); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
298 rv_recursive(i) = octave_value (flat[i].recursive); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
299 rv_parents(i) = stats::function_set_value (flat[i].parents); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
300 rv_children(i) = stats::function_set_value (flat[i].children); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
301 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
302 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
303 octave_map m; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
304 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
305 m.assign ("FunctionName", rv_names); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
306 m.assign ("TotalTime", rv_times); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
307 m.assign ("NumCalls", rv_calls); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
308 m.assign ("IsRecursive", rv_recursive); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
309 m.assign ("Parents", rv_parents); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
310 m.assign ("Children", rv_children); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
311 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
312 retval = m; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
313 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
314 else |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
315 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
316 static const char *fn[] = |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
317 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
318 "FunctionName", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
319 "TotalTime", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
320 "NumCalls", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
321 "IsRecursive", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
322 "Parents", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
323 "Children", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
324 nullptr |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
325 }; |
13188
6d57e53b21ea
Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents:
13141
diff
changeset
|
326 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
327 static octave_map m (dim_vector (0, 1), string_vector (fn)); |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
328 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
329 retval = m; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
330 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
331 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
332 return retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
333 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
334 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
335 octave_value |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
336 profiler::get_hierarchical (void) const |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
337 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
338 octave_value retval; |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
339 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
340 if (call_tree) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
341 retval = call_tree->get_hierarchical (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
342 else |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
343 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
344 static const char *fn[] = |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
345 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
346 "Index", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
347 "SelfTime", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
348 "NumCalls", |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
349 "Children", |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
350 nullptr |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
351 }; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
352 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
353 static octave_map m (dim_vector (0, 1), string_vector (fn)); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
354 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
355 retval = m; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
356 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
357 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
358 return retval; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
359 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
360 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
361 double |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
362 profiler::query_time (void) const |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
363 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
364 sys::time now; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
365 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
366 // FIXME: is this volatile declaration really needed? |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
367 // See bug #34210 for additional details. |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
368 volatile double dnow = now.double_value (); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
369 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
370 return dnow; |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
371 } |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
372 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
373 void |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
374 profiler::add_current_time (void) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
375 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
376 if (active_fcn) |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
377 { |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
378 const double t = query_time (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
379 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
380 active_fcn->add_time (t - last_time); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
381 } |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
382 } |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
383 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
384 |
12870
39d813616c8f
Restore the docstrings for internal profiler functions as C++ comments
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12869
diff
changeset
|
385 // Enable or disable the profiler data collection. |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
386 DEFMETHOD (__profiler_enable__, interp, args, , |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
387 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
388 @deftypefn {} {} __profiler_enable__ () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
389 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
390 @end deftypefn */) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
391 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
392 int nargin = args.length (); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
393 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
394 if (nargin > 1) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
395 print_usage (); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
396 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
397 octave::profiler& profiler = interp.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
398 |
23752
6be1bf9455e3
fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents:
23751
diff
changeset
|
399 if (nargin == 1) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
400 profiler.set_active (args(0).bool_value ()); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
401 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
402 return ovl (profiler.is_active ()); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
403 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
404 |
12870
39d813616c8f
Restore the docstrings for internal profiler functions as C++ comments
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12869
diff
changeset
|
405 // Clear all collected profiling data. |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
406 DEFMETHOD (__profiler_reset__, interp, args, , |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
407 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
408 @deftypefn {} {} __profiler_reset__ () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
409 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
410 @end deftypefn */) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
411 { |
23752
6be1bf9455e3
fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents:
23751
diff
changeset
|
412 if (args.length () != 0) |
6be1bf9455e3
fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents:
23751
diff
changeset
|
413 print_usage (); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
414 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
415 octave::profiler& profiler = interp.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
416 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
417 profiler.reset (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
418 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
419 return ovl (); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
420 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
421 |
12870
39d813616c8f
Restore the docstrings for internal profiler functions as C++ comments
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12869
diff
changeset
|
422 // Query the timings collected by the profiler. |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
423 DEFMETHOD (__profiler_data__, interp, args, nargout, |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
424 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
425 @deftypefn {} {} __profiler_data__ () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
426 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
427 @end deftypefn */) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
428 { |
23752
6be1bf9455e3
fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents:
23751
diff
changeset
|
429 if (args.length () != 0) |
6be1bf9455e3
fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents:
23751
diff
changeset
|
430 print_usage (); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
431 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
432 octave::profiler& profiler = interp.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23752
diff
changeset
|
433 |
12954
a451ae847adb
Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
434 if (nargout > 1) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
435 return ovl (profiler.get_flat (), profiler.get_hierarchical ()); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
436 else |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
437 return ovl (profiler.get_flat ()); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
438 } |