exporting patch: # HG changeset patch # User Daniel Kraft # Date 1313144508 -7200 # Node ID 43d78e103984a80288caf78c1c0019ba4a13c001 # Parent 332a97ea63baf6d664e0e5cfefb9bfc24ba73bed 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. diff -r 332a97ea63ba -r 43d78e103984 src/ov-builtin.cc --- a/src/ov-builtin.cc Thu Aug 11 21:12:56 2011 -0500 +++ b/src/ov-builtin.cc Fri Aug 12 12:21:48 2011 +0200 @@ -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) { diff -r 332a97ea63ba -r 43d78e103984 src/ov-mex-fcn.cc --- a/src/ov-mex-fcn.cc Thu Aug 11 21:12:56 2011 -0500 +++ b/src/ov-mex-fcn.cc Fri Aug 12 12:21:48 2011 +0200 @@ -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) { diff -r 332a97ea63ba -r 43d78e103984 src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Thu Aug 11 21:12:56 2011 -0500 +++ b/src/ov-usr-fcn.cc Fri Aug 12 12:21:48 2011 +0200 @@ -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 (); diff -r 332a97ea63ba -r 43d78e103984 src/profiler.h --- a/src/profiler.h Thu Aug 11 21:12:56 2011 -0500 +++ b/src/profiler.h Fri Aug 12 12:21:48 2011 +0200 @@ -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 diff -r 332a97ea63ba -r 43d78e103984 src/pt-binop.cc --- a/src/pt-binop.cc Thu Aug 11 21:12:56 2011 -0500 +++ b/src/pt-binop.cc Fri Aug 12 12:21:48 2011 +0200 @@ -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 } } } diff -r 332a97ea63ba -r 43d78e103984 src/pt-unop.cc --- a/src/pt-unop.cc Thu Aug 11 21:12:56 2011 -0500 +++ b/src/pt-unop.cc Fri Aug 12 12:21:48 2011 +0200 @@ -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 } } }