annotate libinterp/parse-tree/profiler.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents 32d2b6604a9f
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
3 // Copyright (C) 2012-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
28 #endif
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"
29057
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
31 #include "event-manager.h"
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
32 #include "interpreter.h"
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
33 #include "oct-time.h"
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
34 #include "ov-struct.h"
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
35 #include "pager.h"
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
36 #include "profiler.h"
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
37
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30888
diff changeset
38 OCTAVE_BEGIN_NAMESPACE(octave)
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
39
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
40 profiler::stats::stats (void)
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
41 : m_time (0.0), m_calls (0), m_recursive (false),
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
42 m_parents (), m_children ()
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
45 octave_value
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
46 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
47 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
48 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
49
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
50 RowVector retval (n);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
51 octave_idx_type i = 0;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
52 for (const auto& nm : list)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
53 retval(i++) = nm;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
54
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
55 return retval;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
56 }
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 profiler::tree_node::tree_node (tree_node *p, octave_idx_type f)
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
59 : m_parent (p), m_fcn_id (f), m_children (), m_time (0.0), m_calls (0)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
60 { }
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
61
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
62 profiler::tree_node::~tree_node ()
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
63 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 for (auto& idx_tnode : m_children)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
65 delete idx_tnode.second;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
66 }
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 profiler::tree_node*
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
69 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
70 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
71 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
72
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
73 child_map::iterator pos = m_children.find (fcn);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
74 if (pos == m_children.end ())
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
75 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
76 retval = new tree_node (this, fcn);
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
77 m_children[fcn] = retval;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
78 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
79 else
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
80 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
81
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
82 ++retval->m_calls;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
83 return retval;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
84 }
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 profiler::tree_node*
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
87 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
88 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
89 // FIXME: These panic_unless statements don't make sense if profile() is
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
90 // called from within a function hierarchy to begin with. See bug #39587.
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
91 // panic_unless (m_parent);
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
92 // panic_unless (m_fcn_id == fcn);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
93
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
94 return m_parent;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
95 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
96
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
97 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
98 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
99 {
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
100 // If this is not the top-level node,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
101 // update profile entry for this function.
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
102 if (m_fcn_id != 0)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
103 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
104 stats& entry = data[m_fcn_id - 1];
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
105
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
106 entry.m_time += m_time;
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
107 entry.m_calls += m_calls;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
108
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
109 panic_unless (m_parent);
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
110 if (m_parent->m_fcn_id != 0)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
111 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
112 entry.m_parents.insert (m_parent->m_fcn_id);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
113 data[m_parent->m_fcn_id - 1].m_children.insert (m_fcn_id);
23753
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
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
116 if (! entry.m_recursive)
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
117 for (const tree_node *i = m_parent; i; i = i->m_parent)
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
118 if (i->m_fcn_id == m_fcn_id)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
119 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
120 entry.m_recursive = true;
23753
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.
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
126 for (const auto& idx_tnode : m_children)
23753
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
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
138 const octave_idx_type n = m_children.size ();
23753
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;
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
147 for (const auto& idx_tnode : m_children)
23753
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;
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
150 double child_total = entry.m_time;
23753
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);
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
153 rv_times(i) = octave_value (entry.m_time);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
154 rv_calls(i) = octave_value (entry.m_calls);
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
164 octave_map retval;
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
165
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
166 retval.assign ("Index", rv_indices);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
167 retval.assign ("SelfTime", rv_times);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
168 retval.assign ("TotalTime", rv_totals);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
169 retval.assign ("NumCalls", rv_calls);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
170 retval.assign ("Children", rv_children);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
171
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
172 return retval;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
173 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
174
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
175 profiler::profiler (void)
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
176 : m_known_functions (), m_fcn_index (),
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
177 m_enabled (false), m_call_tree (new tree_node (nullptr, 0)),
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
178 m_active_fcn (nullptr), m_last_time (-1.0)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
179 { }
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 profiler::~profiler (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
182 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
183 delete m_call_tree;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
184 }
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13052
diff changeset
185
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
186 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
187 profiler::set_active (bool value)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
188 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
189 m_enabled = value;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
190 }
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 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
193 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
194 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
195 // The enter class will check and only call us if the profiler is active.
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
196 panic_unless (enabled ());
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
197 panic_unless (m_call_tree);
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
198
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
199 // 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
200 // pushing the new one.
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
201 if (m_active_fcn && m_active_fcn != m_call_tree)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
202 add_current_time ();
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
203
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
204 // 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
205 octave_idx_type fcn_idx;
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
206 fcn_index_map::iterator pos = m_fcn_index.find (fcn);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
207 if (pos == m_fcn_index.end ())
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
208 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
209 m_known_functions.push_back (fcn);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
210 fcn_idx = m_known_functions.size ();
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
211 m_fcn_index[fcn] = fcn_idx;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
212 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
213 else
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
214 fcn_idx = pos->second;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
215
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
216 if (! m_active_fcn)
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
217 m_active_fcn = m_call_tree;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
218
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
219 m_active_fcn = m_active_fcn->enter (fcn_idx);
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
220
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
221 m_last_time = query_time ();
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
222
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
223 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
224
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
225 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
226 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
227 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
228 if (m_active_fcn)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
229 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
230 panic_unless (m_call_tree);
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
231 // FIXME: This panic_unless statements doesn't make sense if profile()
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
232 // is called from within a function hierarchy to begin with.
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
233 // See bug #39587.
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
234 // panic_unless (m_active_fcn != m_call_tree);
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
235
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
236 // Usually, if we are disabled this function is not even called. But
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
237 // the call disabling the profiler is an exception. So also check here
23753
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.
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
239 if (enabled ())
23753
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
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
242 fcn_index_map::iterator pos = m_fcn_index.find (fcn);
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
243 // FIXME: This panic_unless statements doesn't make sense if profile()
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
244 // is called from within a function hierarchy to begin with.
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
245 // See bug #39587.
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
246 // panic_unless (pos != m_fcn_index.end ());
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
247 m_active_fcn = m_active_fcn->exit (pos->second);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
248
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
249 // 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
250 // up the stack. So note the start-time for this!
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
251 m_last_time = query_time ();
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
255 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
256 profiler::reset (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
257 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
258 if (enabled ())
28919
7bc983bc2cbd maint: Prepend name of function to error() messages.
Rik <rik@octave.org>
parents: 28905
diff changeset
259 error ("profile: can't reset active profiler");
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
260
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
261 m_known_functions.clear ();
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
262 m_fcn_index.clear ();
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
263
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
264 if (m_call_tree)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
265 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
266 delete m_call_tree;
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
267 m_call_tree = new tree_node (nullptr, 0);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
268 m_active_fcn = nullptr;
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
269 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
270
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
271 m_last_time = -1.0;
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
274 octave_value
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
275 profiler::get_flat (void) const
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
276 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
277 octave_value retval;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
278
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
279 const octave_idx_type n = m_known_functions.size ();
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
280
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
281 flat_profile flat (n);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
282
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
283 if (m_call_tree)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
284 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
285 m_call_tree->build_flat (flat);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
286
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
287 Cell rv_names (n, 1);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
288 Cell rv_times (n, 1);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
289 Cell rv_calls (n, 1);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
290 Cell rv_recursive (n, 1);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
291 Cell rv_parents (n, 1);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
292 Cell rv_children (n, 1);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
293
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
294 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
295 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
296 rv_names(i) = octave_value (m_known_functions[i]);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
297 rv_times(i) = octave_value (flat[i].m_time);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
298 rv_calls(i) = octave_value (flat[i].m_calls);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
299 rv_recursive(i) = octave_value (flat[i].m_recursive);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
300 rv_parents(i) = stats::function_set_value (flat[i].m_parents);
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
301 rv_children(i) = stats::function_set_value (flat[i].m_children);
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
304 octave_map m;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
305
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
306 m.assign ("FunctionName", rv_names);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
307 m.assign ("TotalTime", rv_times);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
308 m.assign ("NumCalls", rv_calls);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
309 m.assign ("IsRecursive", rv_recursive);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
310 m.assign ("Parents", rv_parents);
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
311 m.assign ("Children", rv_children);
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
312
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
313 retval = m;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
314 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
315 else
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
316 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
317 static const char *fn[] =
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
318 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
319 "FunctionName",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
320 "TotalTime",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
321 "NumCalls",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
322 "IsRecursive",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
323 "Parents",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
324 "Children",
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23753
diff changeset
325 nullptr
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
326 };
13188
6d57e53b21ea Add field for total time to hierarchical profile.
Daniel Kraft <d@domob.eu>
parents: 13141
diff changeset
327
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
328 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
329
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
330 retval = m;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
331 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
332
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
333 return retval;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
334 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
335
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
336 octave_value
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
337 profiler::get_hierarchical (void) const
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
338 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
339 octave_value retval;
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
340
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
341 if (m_call_tree)
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
342 retval = m_call_tree->get_hierarchical ();
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
343 else
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
344 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
345 static const char *fn[] =
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
346 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
347 "Index",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
348 "SelfTime",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
349 "NumCalls",
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
350 "Children",
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23753
diff changeset
351 nullptr
23753
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
354 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
355
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
356 retval = m;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
357 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
358
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
359 return retval;
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
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
362 double
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
363 profiler::query_time (void) const
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
364 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
365 sys::time now;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
366
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
367 // 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
368 // 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
369 volatile double dnow = now.double_value ();
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
370
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
371 return dnow;
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
372 }
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
373
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
374 void
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
375 profiler::add_current_time (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
376 {
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
377 if (m_active_fcn)
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
378 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
379 const double t = query_time ();
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
380
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
381 m_active_fcn->add_time (t - m_last_time);
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
382 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
383 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
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 -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
388 @deftypefn {} {@var{state} =} __profiler_enable__ ()
21966
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
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
397 profiler& profiler = interp.get_profiler ();
23753
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)
29057
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
400 {
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
401 profiler.set_active (args(0).bool_value ());
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
402
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
403 std::string status = "off";
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
404 if (args(0).bool_value ())
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
405 status = "on";
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
406
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
407 event_manager& evmgr = interp.get_event_manager ();
29057
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
408 evmgr.gui_status_update ("profiler", status); // tell GUI
450920c987b8 update profiler status in gui from interpreter
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28919
diff changeset
409 }
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
410
24833
7c88cf242111 use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
411 return ovl (profiler.enabled ());
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
412 }
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
413
12870
39d813616c8f Restore the docstrings for internal profiler functions as C++ comments
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12869
diff changeset
414 // 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
415 DEFMETHOD (__profiler_reset__, interp, args, ,
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
416 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
417 @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
418 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
419 @end deftypefn */)
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
420 {
23752
6be1bf9455e3 fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents: 23751
diff changeset
421 if (args.length () != 0)
6be1bf9455e3 fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents: 23751
diff changeset
422 print_usage ();
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
423
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
424 profiler& profiler = interp.get_profiler ();
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
425
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
426 profiler.reset ();
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
427
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20939
diff changeset
428 return ovl ();
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
429 }
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
430
12870
39d813616c8f Restore the docstrings for internal profiler functions as C++ comments
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12869
diff changeset
431 // 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
432 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
433 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
434 @deftypefn {} {@var{data} =} __profiler_data__ ()
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
435 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
436 @end deftypefn */)
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
437 {
23752
6be1bf9455e3 fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents: 23751
diff changeset
438 if (args.length () != 0)
6be1bf9455e3 fix argument checks for internal profiler functions
John W. Eaton <jwe@octave.org>
parents: 23751
diff changeset
439 print_usage ();
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
440
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
441 profiler& profiler = interp.get_profiler ();
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23752
diff changeset
442
12954
a451ae847adb Collect hierarchical data profile.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
443 if (nargout > 1)
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20892
diff changeset
444 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
445 else
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20892
diff changeset
446 return ovl (profiler.get_flat ());
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff changeset
447 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
448
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30888
diff changeset
449 OCTAVE_END_NAMESPACE(octave)