Mercurial > octave-nkf
annotate libinterp/corefcn/profiler.h @ 20614:10ec79b47808
use new string_value method to handle value extraction errors
* __voronoi__.cc, chol.cc, colamd.cc, fftw.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 18:15:56 -0400 |
parents | 4197fc428c7d |
children |
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 |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19361
diff
changeset
|
3 Copyright (C) 2014-2015 Julien Bect |
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19361
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 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
diff
changeset
|
24 #if !defined (octave_profiler_h) |
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. |
19361
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; |
19361
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 |
19361
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. |
19361
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 { \ |
19361
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 \ |
19361
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 |