Mercurial > hg > octave-terminal
changeset 12960:43d78e103984
Use macro to start profiler blocks.
profile.h: Define macros BEGIN/END_PROFILER_BLOCK.
ov-builtin.cc: Use it.
ov-mex-fcn.cc: Ditto.
ov-usr-fcn.cc: Ditto.
pt-binop.cc: Ditto.
pt-unop.cc: Ditto.
author | Daniel Kraft <d@domob.eu> |
---|---|
date | Fri, 12 Aug 2011 12:21:48 +0200 |
parents | 332a97ea63ba |
children | 8c64cc024e8c |
files | src/ov-builtin.cc src/ov-mex-fcn.cc src/ov-usr-fcn.cc src/profiler.h src/pt-binop.cc src/pt-unop.cc |
diffstat | 6 files changed, 45 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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 } } }