annotate libinterp/corefcn/profiler.h @ 20791:f7084eae3318

maint: Use Octave coding conventions for #if statements. * mk-opts.pl, dialog.h, find-files-dialog.h, find-files-model.h, file-editor-tab.h, octave-qscintilla.h, octave-txt-lexer.h, main-window.h, octave-cmd.h, octave-dock-widget.h, octave-gui.h, thread-manager.h, workspace-model.h, workspace-view.h, builtins.h, Cell.h, bitfcns.cc, c-file-ptr-stream.h, cdisplay.h, comment-list.h, cutils.h, data.h, debug.h, defaults.in.h, defun-dld.h, defun-int.h, defun.h, dirfns.h, display.h, dynamic-ld.h, error.h, event-queue.h, file-io.h, filter.cc, getrusage.cc, gl-render.h, gl2ps-renderer.h, graphics.in.h, gripes.h, help.h, hook-fcn.h, input.h, jit-ir.h, jit-typeinfo.h, jit-util.h, load-path.h, load-save.h, ls-ascii-helper.h, ls-hdf5.h, ls-mat-ascii.h, ls-mat4.h, ls-mat5.h, ls-oct-binary.h, ls-oct-text.h, ls-utils.h, oct-errno.h, oct-fstrm.h, oct-handle.h, oct-hdf5-types.h, oct-hdf5.h, oct-hist.h, oct-iostrm.h, oct-lvalue.h, oct-map.h, oct-obj.h, oct-prcstrm.h, oct-procbuf.h, oct-stdstrm.h, oct-stream.h, oct-strstrm.h, oct.h, octave-link.h, pager.h, pr-output.h, procstream.h, profiler.h, pt-jit.h, sighandlers.cc, sighandlers.h, siglist.h, sparse-xdiv.h, sparse-xpow.h, symtab.h, syscalls.cc, sysdep.h, toplev.cc, toplev.h, utils.h, variables.h, workspace-element.h, xdiv.h, xnorm.h, xpow.h, dmperm.cc, oct-qhull.h, mkbuiltins, oct-conf.in.h, ov-base-diag.h, ov-base-int.h, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.h, ov-base.h, ov-bool-mat.h, ov-bool-sparse.h, ov-bool.h, ov-builtin.h, ov-cell.h, ov-ch-mat.h, ov-class.h, ov-classdef.h, ov-colon.h, ov-complex.h, ov-cs-list.h, ov-cx-diag.h, ov-cx-mat.h, ov-cx-sparse.h, ov-dld-fcn.h, ov-fcn-handle.h, ov-fcn-inline.h, ov-fcn.h, ov-float.h, ov-flt-complex.h, ov-flt-cx-diag.h, ov-flt-cx-mat.h, ov-flt-re-diag.h, ov-flt-re-mat.h, ov-int-traits.h, ov-int16.h, ov-int32.h, ov-int64.h, ov-int8.h, ov-java.h, ov-lazy-idx.h, ov-mex-fcn.h, ov-null-mat.h, ov-perm.h, ov-range.h, ov-re-diag.h, ov-re-mat.h, ov-re-sparse.h, ov-scalar.h, ov-str-mat.h, ov-struct.h, ov-type-conv.h, ov-typeinfo.h, ov-uint16.h, ov-uint32.h, ov-uint64.h, ov-uint8.h, ov-usr-fcn.h, ov.h, octave.h, ops.h, options-usage.h, lex.h, parse.h, pt-all.h, pt-arg-list.h, pt-array-list.h, pt-assign.h, pt-binop.h, pt-bp.h, pt-cbinop.h, pt-cell.h, pt-check.h, pt-classdef.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.h, pt-eval.h, pt-except.h, pt-exp.h, pt-fcn-handle.h, pt-funcall.h, pt-id.h, pt-idx.h, pt-jump.h, pt-loop.h, pt-mat.h, pt-misc.h, pt-pr-code.h, pt-select.h, pt-stmt.h, pt-unop.h, pt-walk.h, pt.h, token.h, version.in.h, Array-util.h, Array.h, CColVector.h, CDiagMatrix.h, CMatrix.h, CNDArray.h, CRowVector.h, CSparse.h, DiagArray2.h, MArray-decl.h, MArray-defs.h, MArray.h, MDiagArray2.h, MSparse.h, Matrix.h, MatrixType.h, PermMatrix.h, Range.h, Sparse.h, boolMatrix.h, boolNDArray.h, boolSparse.h, chMatrix.h, chNDArray.h, dColVector.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, dRowVector.h, dSparse.h, dim-vector.h, fCColVector.h, fCDiagMatrix.h, fCMatrix.h, fCNDArray.h, fCRowVector.h, fColVector.h, fDiagMatrix.h, fMatrix.h, fNDArray.h, fRowVector.h, idx-vector.h, int16NDArray.h, int32NDArray.h, int64NDArray.h, int8NDArray.h, intNDArray.h, uint16NDArray.h, uint32NDArray.h, uint64NDArray.h, uint8NDArray.h, f77-fcn.h, lo-error.h, quit.h, CmplxAEPBAL.h, CmplxCHOL.h, CmplxGEPBAL.h, CmplxHESS.h, CmplxLU.h, CmplxQR.h, CmplxQRP.h, CmplxSCHUR.h, CmplxSVD.h, CollocWt.h, DAE.h, DAEFunc.h, DAERT.h, DAERTFunc.h, DASPK.h, DASRT.h, DASSL.h, DET.h, EIG.h, LSODE.h, ODE.h, ODEFunc.h, ODES.h, ODESFunc.h, Quad.h, SparseCmplxCHOL.h, SparseCmplxLU.h, SparseCmplxQR.cc, SparseCmplxQR.h, SparseQR.h, SparsedbleCHOL.h, SparsedbleLU.h, base-aepbal.h, base-dae.h, base-de.h, base-lu.h, base-min.h, base-qr.h, bsxfun-decl.h, bsxfun-defs.cc, bsxfun.h, dbleAEPBAL.h, dbleCHOL.h, dbleGEPBAL.h, dbleHESS.h, dbleLU.h, dbleQR.h, dbleQRP.h, dbleSCHUR.h, dbleSVD.h, eigs-base.cc, fCmplxAEPBAL.h, fCmplxCHOL.h, fCmplxGEPBAL.h, fCmplxHESS.h, fCmplxLU.h, fCmplxQR.h, fCmplxQRP.h, fCmplxSCHUR.h, fCmplxSVD.h, fEIG.h, floatAEPBAL.h, floatCHOL.h, floatGEPBAL.h, floatHESS.h, floatLU.h, floatQR.h, floatQRP.h, floatSCHUR.h, floatSVD.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, oct-convn.h, oct-fftw.h, oct-norm.h, oct-rand.h, oct-spparms.h, randmtzig.c, sparse-base-chol.h, sparse-base-lu.h, sparse-dmsolve.cc, Sparse-diag-op-defs.h, Sparse-op-decls.h, Sparse-op-defs.h, Sparse-perm-op-defs.h, mk-ops.awk, mx-base.h, mx-defs.h, mx-ext.h, mx-inlines.cc, mx-op-decl.h, mx-op-defs.h, sparse-mk-ops.awk, dir-ops.h, file-ops.h, file-stat.h, lo-sysdep.h, mach-info.h, oct-env.h, oct-group.h, oct-openmp.h, oct-passwd.h, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.h, pathlen.h, sysdir.h, syswait.h, action-container.h, base-list.h, byte-swap.h, caseless-str.h, cmd-edit.h, cmd-hist.h, data-conv.h, functor.h, glob-match.h, kpse.cc, lo-array-gripes.h, lo-cutils.h, lo-ieee.h, lo-macros.h, lo-math.h, lo-regexp.h, lo-traits.h, lo-utils.h, oct-alloc.h, oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-glob.h, oct-inttypes.h, oct-locbuf.h, oct-mutex.h, oct-refcount.h, oct-rl-edit.h, oct-rl-hist.h, oct-shlib.h, oct-sort.h, oct-sparse.h, pathsearch.h, singleton-cleanup.h, sparse-sort.h, sparse-util.h, statdefs.h, str-vec.h, sun-utils.h, unwind-prot.h, url-transfer.h: Use Octave coding conventions for #if statements.
author Rik <rik@octave.org>
date Thu, 03 Dec 2015 10:23:38 -0800
parents 4197fc428c7d
children 538b57866b90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19327
diff changeset
3 Copyright (C) 2014-2015 Julien Bect
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19327
diff changeset
4 Copyright (C) 2012-2015 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
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
11 option) any later version.
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
12
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
16 for more details.
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
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
24 #if ! defined (octave_profiler_h)
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
25 #define octave_profiler_h 1
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
26
13188
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
27 #include <cstddef>
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
28 #include <map>
12869
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
29 #include <set>
12920
5d18231eee00 Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents: 12869
diff changeset
30 #include <string>
12869
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
31 #include <vector>
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
32
12869
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
33 class octave_value;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
34
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
35 class
13040
12ba32dd3458 Mark profiler class and data for export.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12960
diff changeset
36 OCTINTERP_API
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
37 profile_data_accumulator
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
38 {
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
39 public:
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
40
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
41 // This is a utility class that can be used to call the enter/exit
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
42 // functions in a manner protected from stack unwinding.
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
43 template<class T> class enter
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
44 {
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
45 private:
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
46
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
47 profile_data_accumulator& acc;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
48 std::string fcn;
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
49 bool is_active;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
50
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
51 public:
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
52
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
53 enter (profile_data_accumulator& a, const T& t) : acc (a)
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
54 {
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
55 // A profiling block cannot be active if the profiler is not
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
56 is_active = acc.is_active ();
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
57
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
58 if (is_active)
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
59 {
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
60 fcn = t.profiler_name ();
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
61
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
62 // NOTE: The test f != "" must be kept to prevent a blank line showing
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
63 // up in profiler statistics. See bug #39524. The root cause is that
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
64 // the function name is not set for the recurring readline hook function.
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
65 if (fcn == "")
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
66 is_active = false; // Inactive profiling block
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
67 else
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
68 acc.enter_function (fcn);
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
69 }
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
70 }
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
71
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
72 ~enter ()
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
73 {
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
74 if (is_active)
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
75 acc.exit_function (fcn);
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
76 }
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
77
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
78 private:
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
79
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
80 // No copying!
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
81 enter (const enter&);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
82 enter& operator = (const enter&);
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
83 };
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
84
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
85 profile_data_accumulator (void);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
86 virtual ~profile_data_accumulator ();
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
87
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
88 bool is_active (void) const { return enabled; }
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
89 void set_active (bool);
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
90
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
91 void reset (void);
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
92
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
93 octave_value get_flat (void) const;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
94 octave_value get_hierarchical (void) const;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
95
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
96 private:
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
97
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
98 // One entry in the flat profile (i.e., a collection of data for a single
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
99 // function). This is filled in when building the flat profile from the
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
100 // hierarchical call tree.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
101 struct stats
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
102 {
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
103 stats ();
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
104
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
105 double time;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
106 unsigned calls;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
107
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
108 bool recursive;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
109
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
110 typedef std::set<octave_idx_type> function_set;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
111 function_set parents;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
112 function_set children;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
113
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
114 // Convert a function_set list to an Octave array of indices.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
115 static octave_value function_set_value (const function_set&);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
116 };
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
117
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
118 typedef std::vector<stats> flat_profile;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13040
diff changeset
119
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
120 // Store data for one node in the call-tree of the hierarchical profiler
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
121 // data we collect.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
122 class tree_node
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
123 {
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
124 public:
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
125
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
126 tree_node (tree_node*, octave_idx_type);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
127 virtual ~tree_node ();
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
128
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
129 void add_time (double dt) { time += dt; }
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
130
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
131 // Enter a child function. It is created in the list of children if it
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
132 // wasn't already there. The now-active child node is returned.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
133 tree_node* enter (octave_idx_type);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
134
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
135 // Exit function. As a sanity-check, it is verified that the currently
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
136 // active function actually is the one handed in here. Returned is the
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
137 // then-active node, which is our parent.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
138 tree_node* exit (octave_idx_type);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
139
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
140 void build_flat (flat_profile&) const;
13188
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
141
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
142 // Get the hierarchical profile for this node and its children. If total
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
143 // is set, accumulate total time of the subtree in that variable as
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
144 // additional return value.
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
145 octave_value get_hierarchical (double* total = 0) const;
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
146
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
147 private:
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
148
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
149 tree_node* parent;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
150 octave_idx_type fcn_id;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
151
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
152 typedef std::map<octave_idx_type, tree_node*> child_map;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
153 child_map children;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
154
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
155 // This is only time spent *directly* on this level, excluding children!
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
156 double time;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
157
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
158 unsigned calls;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
159
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
160 // No copying!
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
161 tree_node (const tree_node&);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
162 tree_node& operator = (const tree_node&);
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
163 };
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
164
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
165 // Each function we see in the profiler is given a unique index (which
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
166 // simply counts starting from 1). We thus have to map profiler-names to
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
167 // those indices. For all other stuff, we identify functions by their index.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
168
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
169 typedef std::vector<std::string> function_set;
12869
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
170 typedef std::map<std::string, octave_idx_type> fcn_index_map;
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
171
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
172 function_set known_functions;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
173 fcn_index_map fcn_index;
12869
de9a9719e594 Extend data collection in profiler and add user-interface profile function.
Daniel Kraft <d@domob.eu>
parents: 12783
diff changeset
174
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
175 bool enabled;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
176
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
177 tree_node* call_tree;
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
178 tree_node* active_fcn;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
179
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
180 // Store last timestamp we had, when the currently active function was called.
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
181 double last_time;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
182
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
183 // These are private as only the unwind-protecting inner class enter
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
184 // should be allowed to call them.
12920
5d18231eee00 Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents: 12869
diff changeset
185 void enter_function (const std::string&);
5d18231eee00 Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents: 12869
diff changeset
186 void exit_function (const std::string&);
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
187
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
188 // Query a timestamp, used for timing calls (obviously).
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
189 // This is not static because in the future, maybe we want a flag
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
190 // in the profiler or something to choose between cputime, wall-time,
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
191 // user-time, system-time, ...
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
192 double query_time () const;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
193
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
194 // Add the time elapsed since last_time to the function we're currently in.
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
195 // This is called from two different positions, thus it is useful to have
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
196 // it as a seperate function.
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
197 void add_current_time (void);
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
198
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
199 // No copying!
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
200 profile_data_accumulator (const profile_data_accumulator&);
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
201 profile_data_accumulator& operator = (const profile_data_accumulator&);
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
202 };
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
203
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
204 // The instance used.
13040
12ba32dd3458 Mark profiler class and data for export.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12960
diff changeset
205 extern OCTINTERP_API profile_data_accumulator profiler;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
206
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12954
diff changeset
207 // Helper macro to profile a block of code.
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
208
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
209 #define BEGIN_PROFILER_BLOCK(classname) \
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12954
diff changeset
210 { \
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
211 profile_data_accumulator::enter<classname> pe (profiler, *this);
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
212
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12954
diff changeset
213 #define END_PROFILER_BLOCK \
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 17898
diff changeset
214 } // end of block => call pe's destructor
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12954
diff changeset
215
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
216 #endif