Mercurial > hg > octave-terminal
changeset 12962:55c3da8f1c9a
Merge in Daniel's changes
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Sun, 14 Aug 2011 12:41:20 -0500 |
parents | 0c86ae6f7c34 (current diff) 8c64cc024e8c (diff) |
children | 27e5f0e79f19 |
files | |
diffstat | 7 files changed, 54 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/profile.m +++ b/scripts/general/profile.m @@ -48,9 +48,13 @@ ## ## @item @var{T} = profile ('info') ## Return the collected profiling statistics in the structure @var{T}. -## Currently, the only field is @code{FunctionTable} which is an array -## of structures, each entry corresponding to a function which was called -## and for which profiling statistics are present. +## The flat profile is returned in the field @code{FunctionTable} which is an +## array of structures, each entry corresponding to a function which was called +## and for which profiling statistics are present. Furthermore, the field +## @code{Hierarchical} contains the hierarchical call-tree. Each node +## has an index into the @code{FunctionTable} identifying the function it +## corresponds to as well as data fields for number of calls and time spent +## at this level in the call-tree. ## @end table ## @end deftypefn @@ -87,8 +91,8 @@ retval = struct ('ProfilerStatus', enabled); case 'info' - data = __profiler_data__ (); - retval = struct ('FunctionTable', data); + [flat, tree] = __profiler_data__ (); + retval = struct ('FunctionTable', flat, 'Hierarchical', tree); otherwise warning ("profile: Unrecognized option '%s'", option);
--- a/src/ov-builtin.cc +++ b/src/ov-builtin.cc @@ -126,7 +126,7 @@ try { - profile_data_accumulator::enter pe (profiler, profiler_name ()); + BEGIN_PROFILER_BLOCK (profiler_name ()) retval = (*f) (args, nargout); // Do not allow null values to be returned from functions. @@ -140,6 +140,8 @@ // the idiom is very common, so we solve that here. if (retval.length () == 1 && retval.xelem (0).is_undefined ()) retval.clear (); + + END_PROFILER_BLOCK } catch (octave_execution_exception) {
--- a/src/ov-mex-fcn.cc +++ b/src/ov-mex-fcn.cc @@ -148,8 +148,9 @@ try { - profile_data_accumulator::enter pe (profiler, profiler_name ()); + BEGIN_PROFILER_BLOCK (profiler_name ()) retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); + END_PROFILER_BLOCK } catch (octave_execution_exception) {
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -134,11 +134,9 @@ frame.protect_var (tree_evaluator::statement_context); tree_evaluator::statement_context = tree_evaluator::script; - { - profile_data_accumulator::enter pe (profiler, - profiler_name ()); - cmd_list->accept (*current_evaluator); - } + BEGIN_PROFILER_BLOCK (profiler_name ()) + cmd_list->accept (*current_evaluator); + END_PROFILER_BLOCK if (tree_return_command::returning) tree_return_command::returning = 0; @@ -455,26 +453,26 @@ bool special_expr = (is_inline_function () || cmd_list->is_anon_function_body ()); - { - profile_data_accumulator::enter pe (profiler, profiler_name ()); + BEGIN_PROFILER_BLOCK (profiler_name ()) - if (special_expr) - { - assert (cmd_list->length () == 1); + if (special_expr) + { + assert (cmd_list->length () == 1); - tree_statement *stmt = 0; + tree_statement *stmt = 0; - if ((stmt = cmd_list->front ()) - && stmt->is_expression ()) - { - tree_expression *expr = stmt->expression (); + if ((stmt = cmd_list->front ()) + && stmt->is_expression ()) + { + tree_expression *expr = stmt->expression (); - retval = expr->rvalue (nargout); - } - } - else - cmd_list->accept (*current_evaluator); - } + retval = expr->rvalue (nargout); + } + } + else + cmd_list->accept (*current_evaluator); + + END_PROFILER_BLOCK if (echo_commands) print_code_function_trailer ();
--- a/src/profiler.h +++ b/src/profiler.h @@ -175,4 +175,11 @@ // The instance used. extern profile_data_accumulator profiler; +// Helper macro to profile a block of code. +#define BEGIN_PROFILER_BLOCK(name) \ + { \ + profile_data_accumulator::enter pe (profiler, (name)); +#define END_PROFILER_BLOCK \ + } + #endif
--- a/src/pt-binop.cc +++ b/src/pt-binop.cc @@ -121,8 +121,7 @@ if (! error_state && b.is_defined ()) { - profile_data_accumulator::enter pe (profiler, - "binary " + oper ()); + BEGIN_PROFILER_BLOCK ("binary " + oper ()) // Note: The profiler does not catch the braindead // short-circuit evaluation code above, but that should be @@ -134,6 +133,8 @@ if (error_state) retval = octave_value (); + + END_PROFILER_BLOCK } } }
--- a/src/pt-unop.cc +++ b/src/pt-unop.cc @@ -73,13 +73,14 @@ if (! error_state) { - profile_data_accumulator::enter pe (profiler, - "prefix " + oper ()); + BEGIN_PROFILER_BLOCK ("prefix " + oper ()) ref.do_unary_op (etype); if (! error_state) retval = ref.value (); + + END_PROFILER_BLOCK } } else @@ -88,8 +89,7 @@ if (! error_state && val.is_defined ()) { - profile_data_accumulator::enter pe (profiler, - "prefix " + oper ()); + BEGIN_PROFILER_BLOCK ("prefix " + oper ()) // Attempt to do the operation in-place if it is unshared // (a temporary expression). @@ -100,6 +100,8 @@ if (error_state) retval = octave_value (); + + END_PROFILER_BLOCK } } } @@ -160,10 +162,9 @@ { retval = ref.value (); - profile_data_accumulator::enter pe (profiler, - "postfix " + oper ()); - + BEGIN_PROFILER_BLOCK ("postfix " + oper ()) ref.do_unary_op (etype); + END_PROFILER_BLOCK } } else @@ -172,13 +173,14 @@ if (! error_state && val.is_defined ()) { - profile_data_accumulator::enter pe (profiler, - "postfix " + oper ()); + BEGIN_PROFILER_BLOCK ("postfix " + oper ()) retval = ::do_unary_op (etype, val); if (error_state) retval = octave_value (); + + END_PROFILER_BLOCK } } }