# HG changeset patch # User John W. Eaton # Date 1315069185 14400 # Node ID 43dcb0093ebd61aa4f530cae1554642508a41a80 # Parent 42e12f94fe1e0561b6a0445b4f50a3d5131f6970 allow profile ('info') to work if no profiling data is available * profiler.cc (profile_data_accumulator::get_flat): Return empty struct if call_tree isn't available. Use octave_map, not obsolete Octave_map. (profile_data_accumulator::get_hierarchical): Likewise. diff -r 42e12f94fe1e -r 43dcb0093ebd src/profiler.cc --- a/src/profiler.cc Sat Sep 03 18:48:56 2011 +0200 +++ b/src/profiler.cc Sat Sep 03 12:59:45 2011 -0400 @@ -174,7 +174,7 @@ } assert (i == n); - Octave_map retval; + octave_map retval; retval.assign ("Index", rv_indices); retval.assign ("SelfTime", rv_times); @@ -290,37 +290,61 @@ octave_value profile_data_accumulator::get_flat (void) const { + octave_value retval; + const octave_idx_type n = known_functions.size (); flat_profile flat (n); - assert (call_tree); - call_tree->build_flat (flat); - Cell rv_names (n, 1); - Cell rv_times (n, 1); - Cell rv_calls (n, 1); - Cell rv_recursive (n, 1); - Cell rv_parents (n, 1); - Cell rv_children (n, 1); - - for (octave_idx_type i = 0; i != n; ++i) + if (call_tree) { - rv_names(i) = octave_value (known_functions[i]); - rv_times(i) = octave_value (flat[i].time); - rv_calls(i) = octave_value (flat[i].calls); - rv_recursive(i) = octave_value (flat[i].recursive); - rv_parents(i) = stats::function_set_value (flat[i].parents); - rv_children(i) = stats::function_set_value (flat[i].children); - } + call_tree->build_flat (flat); + + Cell rv_names (n, 1); + Cell rv_times (n, 1); + Cell rv_calls (n, 1); + Cell rv_recursive (n, 1); + Cell rv_parents (n, 1); + Cell rv_children (n, 1); + + for (octave_idx_type i = 0; i != n; ++i) + { + rv_names(i) = octave_value (known_functions[i]); + rv_times(i) = octave_value (flat[i].time); + rv_calls(i) = octave_value (flat[i].calls); + rv_recursive(i) = octave_value (flat[i].recursive); + rv_parents(i) = stats::function_set_value (flat[i].parents); + rv_children(i) = stats::function_set_value (flat[i].children); + } + + octave_map m; - Octave_map retval; + m.assign ("FunctionName", rv_names); + m.assign ("TotalTime", rv_times); + m.assign ("NumCalls", rv_calls); + m.assign ("IsRecursive", rv_recursive); + m.assign ("Parents", rv_parents); + m.assign ("Children", rv_children); - retval.assign ("FunctionName", rv_names); - retval.assign ("TotalTime", rv_times); - retval.assign ("NumCalls", rv_calls); - retval.assign ("IsRecursive", rv_recursive); - retval.assign ("Parents", rv_parents); - retval.assign ("Children", rv_children); + retval = m; + } + else + { + static const char *fn[] = + { + "FunctionName", + "TotalTime", + "NumCalls", + "IsRecursive", + "Parents", + "Children", + 0 + }; + + static octave_map m (dim_vector (0, 1), string_vector (fn)); + + retval = m; + } return retval; } @@ -328,8 +352,27 @@ octave_value profile_data_accumulator::get_hierarchical (void) const { - assert (call_tree); - return call_tree->get_hierarchical (); + octave_value retval; + + if (call_tree) + retval = call_tree->get_hierarchical (); + else + { + static const char *fn[] = + { + "Index", + "SelfTime", + "NumCalls", + "Children", + 0 + }; + + static octave_map m (dim_vector (0, 1), string_vector (fn)); + + retval = m; + } + + return retval; } double