Mercurial > hg > octave-nkf
comparison scripts/general/profile.m @ 12869:de9a9719e594
Extend data collection in profiler and add user-interface profile function.
* scripts/general/module.mk: Add profile.m.
* scripts/general/profile.m: New file.
* src/profiler.h (stats): New utility class.
(data): Field to replace old times, can now hold more info.
* src/profiler.cc (stats): Implementation of routines.
(profile_data_accumulator): Changes necessary because call_stack was
changed to be a std::vector now and for the new statistics map.
(profile_data_accumulator::get_data): Extended to produce much more
sophisticated output.
(profile_data_accumulator::enter_function): Collect some more data
than the timing.
author | Daniel Kraft <d@domob.eu> |
---|---|
date | Thu, 14 Jul 2011 22:16:24 +0200 |
parents | |
children | 23377c46516b |
comparison
equal
deleted
inserted
replaced
12868:b00181c65533 | 12869:de9a9719e594 |
---|---|
1 ## Copyright (C) 2011 Daniel Kraft | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} profile on | |
21 ## @deftypefnx {Function File} {} profile off | |
22 ## @deftypefnx {Function File} {} profile resume | |
23 ## @deftypefnx {Function File} {} profile clear | |
24 ## @deftypefnx {Function File} {@var{S} =} profile ('status') | |
25 ## @deftypefnx {Function File} {@var{T} =} profile ('info') | |
26 ## Control the built-in profiler. | |
27 ## | |
28 ## @table @code | |
29 ## @item profile on | |
30 ## Start the profiler, clearing all previously collected data if there | |
31 ## is any. | |
32 ## | |
33 ## @item profile off | |
34 ## Stop profiling. The collected data can later be retrieved and examined | |
35 ## with calls like @code{S = profile ('info')}. | |
36 ## | |
37 ## @item profile clear | |
38 ## Clear all collected profiler data. | |
39 ## | |
40 ## @item profile resume | |
41 ## Restart profiling without cleaning up the old data and instead | |
42 ## all newly collected statistics are added to the already existing ones. | |
43 ## | |
44 ## @item @var{S} = profile ('status') | |
45 ## Return a structure filled with certain information about the current status | |
46 ## of the profiler. At the moment, the only field is @code{ProfilerStatus} | |
47 ## which is either 'on' or 'off'. | |
48 ## | |
49 ## @item @var{T} = profile ('info') | |
50 ## Return the collected profiling statistics in the structure @var{T}. | |
51 ## Currently, the only field is @code{FunctionTable} which is an array | |
52 ## of structures, each entry corresponding to a function which was called | |
53 ## and for which profiling statistics are present. | |
54 ## @end table | |
55 ## @end deftypefn | |
56 | |
57 ## Built-in profiler. | |
58 ## Author: Daniel Kraft <d@domob.eu> | |
59 | |
60 function retval = profile (option) | |
61 | |
62 switch (option) | |
63 case 'on' | |
64 __profiler_reset (); | |
65 __profiler_enable (true); | |
66 | |
67 case 'off' | |
68 __profiler_enable (false); | |
69 | |
70 case 'clear' | |
71 __profiler_reset (); | |
72 | |
73 case 'resume' | |
74 __profiler_enable (true); | |
75 | |
76 case 'status' | |
77 enabled = __profiler_enable (); | |
78 if (enabled) | |
79 enabled = 'on'; | |
80 else | |
81 enabled = 'off'; | |
82 endif | |
83 retval = struct ('ProfilerStatus', enabled); | |
84 | |
85 case 'info' | |
86 data = __profiler_data (); | |
87 retval = struct ('FunctionTable', data); | |
88 | |
89 otherwise | |
90 print_usage (); | |
91 endswitch | |
92 | |
93 endfunction | |
94 | |
95 %!demo | |
96 %! profile ('on'); | |
97 %! A = rand (100); | |
98 %! B = expm (A); | |
99 %! profile ('off'); | |
100 %! profile ('resume'); | |
101 %! C = sqrtm (A); | |
102 %! profile ('off'); | |
103 %! T = profile ('info') |