comparison src/profiler.h @ 12783:ad9263d965dc

First experimental profiler implementation with flat profile. * profiler.cc: New file. * profiler.h: New file. * Makefile.am: Include new files in build process. * oct-parse.yy (frob_function): Store location of function parsed. * ov-fcn.h (octave_function::profiler_name): New method. * ov-builtin.cc (octave_builtin::do_multi_index_op): Record timings in profiler. * ov-mex-fcn.cc (octave_mex_function::do_multi_index_op): Ditto. * ov-usr-fcn.cc (octave_user_script::do_multi_index_op): Ditto. (octave_user_function::do_multi_index_op): Ditto. (octave_user_function::octave_user_function): Initialize location_line/column. (octave_user_function::profiler_name): New method. * ov-usr-fcn.h (octave_user_function): New variables location_line, location column and new method stash_fcn_location to set them. * pt-fcn-handle.cc (tree_anon_fcn_handle::rvalue1): Store location.
author Daniel Kraft <d@domob.eu>
date Thu, 30 Jun 2011 20:04:34 +0200
parents
children de9a9719e594
comparison
equal deleted inserted replaced
12778:0ca5672d5f1a 12783:ad9263d965dc
1 /*
2
3 Copyright (C) 2011 Daniel Kraft
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #if !defined (octave_profiler_h)
24 #define octave_profiler_h 1
25
26 #include <stack>
27 #include <map>
28
29 class octave_function;
30 class Cell;
31
32 class
33 OCTAVE_API
34 profile_data_accumulator
35 {
36 public:
37
38 // This is a utility class that can be used to call the enter/exit
39 // functions in a manner protected from stack unwinding.
40 class enter
41 {
42 private:
43
44 profile_data_accumulator& acc;
45
46 const octave_function* fcn;
47
48 public:
49
50 enter (profile_data_accumulator&, const octave_function& fcn);
51
52 virtual ~enter (void);
53
54 private:
55
56 // No copying!
57
58 enter (const enter&);
59
60 enter& operator = (const enter&);
61 };
62
63 profile_data_accumulator (void);
64
65 bool is_active (void) const { return enabled; }
66
67 void set_active (bool);
68
69 void reset (void);
70
71 Cell get_data (void) const;
72
73 private:
74
75 bool enabled;
76
77 std::stack<const octave_function*> call_stack;
78
79 typedef std::map<std::string, double> timing_map;
80 timing_map times;
81
82 // Store last timestamp we had, when the currently active function was called.
83 double last_time;
84
85 // These are private as only the unwind-protecting inner class enter
86 // should be allowed to call them.
87 void enter_function (const octave_function&);
88 void exit_function (const octave_function&);
89
90 // Query a timestamp, used for timing calls (obviously).
91 // This is not static because in the future, maybe we want a flag
92 // in the profiler or something to choose between cputime, wall-time
93 // user-time, system-time, ...
94 double query_time () const;
95
96 // Add the time elapsed since last_time to the function on the top
97 // of our call-stack. This is called from two different positions,
98 // thus it is useful to have it as a seperate function.
99 void add_current_time (void);
100
101 // No copying!
102
103 profile_data_accumulator (const profile_data_accumulator&);
104
105 profile_data_accumulator& operator = (const profile_data_accumulator&);
106 };
107
108 // The instance used.
109 extern profile_data_accumulator profiler;
110
111 #endif