You are here

function xhprof_profiler_report in XHProf 6

Same name and namespace in other branches
  1. 7 xhprof.inc \xhprof_profiler_report()

Analyze raw data & generate the profiler report (common for both single run mode and diff mode).

@author: Kannan

1 call to xhprof_profiler_report()
xhprof_display_run in ./xhprof.module
Display XHProf run report.

File

./xhprof.inc, line 587

Code

function xhprof_profiler_report($url_params, $rep_symbol, $sort, $run1, $run1_desc, $run1_data, $run2 = 0, $run2_desc = "", $run2_data = array()) {
  global $totals;
  global $totals_1;
  global $totals_2;
  global $stats;
  global $pc_stats;
  global $diff_mode;
  global $base_path;
  $output = '';

  // if we are reporting on a specific function, we can trim down
  // the report(s) to just stuff that is relevant to this function.
  // That way compute_flat_info()/compute_diff() etc. do not have
  // to needlessly work hard on churning irrelevant data.
  if (!empty($rep_symbol)) {
    $run1_data = xhprof_trim_run($run1_data, array(
      $rep_symbol,
    ));
    if ($diff_mode) {
      $run2_data = xhprof_trim_run($run2_data, array(
        $rep_symbol,
      ));
    }
  }
  if ($diff_mode) {
    $run_delta = xhprof_compute_diff($run1_data, $run2_data);
    $symbol_tab = xhprof_compute_flat_info($run_delta, $totals);
    $symbol_tab1 = xhprof_compute_flat_info($run1_data, $totals_1);
    $symbol_tab2 = xhprof_compute_flat_info($run2_data, $totals_2);
  }
  else {
    $symbol_tab = xhprof_compute_flat_info($run1_data, $totals);
  }
  $run1_txt = sprintf("<b>Run #%s:</b> %s", $run1, $run1_desc);
  $base_url_params = xhprof_array_unset(xhprof_array_unset($url_params, 'symbol'), 'all');
  $top_link_query_string = "{$base_path}/?" . http_build_query($base_url_params);
  if ($diff_mode) {
    $diff_text = "Diff";
    $base_url_params = xhprof_array_unset($base_url_params, 'run1');
    $base_url_params = xhprof_array_unset($base_url_params, 'run2');
    $run1_link = xhprof_xhprof_render_link('View Run #' . $run1, "{$base_path}/?" . http_build_query(xhprof_array_set($base_url_params, 'run', $run1)));
    $run2_txt = sprintf("<b>Run #%s:</b> %s", $run2, $run2_desc);
    $run2_link = xhprof_xhprof_render_link('View Run #' . $run2, "{$base_path}/?" . http_build_query(xhprof_array_set($base_url_params, 'run', $run2)));
  }
  else {
    $diff_text = "Run";
  }

  // set up the action links for operations that can be done on this report
  $links = array();
  $path_parts = explode('/', $_GET['q']);
  $links[] = l("View Top Level {$diff_text} Report", implode('/', array_slice($path_parts, 0, 4)));
  if ($diff_mode) {
    $inverted_params = $url_params;
    $inverted_params['run1'] = $url_params['run2'];
    $inverted_params['run2'] = $url_params['run1'];

    // view the different runs or invert the current diff
    $links[] = $run1_link;
    $links[] = $run2_link;
    $links[] = xhprof_xhprof_render_link('Invert ' . $diff_text . ' Report', "{$base_path}/?" . http_build_query($inverted_params));
  }

  // lookup function xhprof_typeahead form
  $links[] = '<input class="function_typeahead" ' . ' type="input" size="40" maxlength="100" />';
  $output .= xhprof_render_actions($links);
  $output .= '<dl class=xhprof_report_info>' . '  <dt>' . $diff_text . ' Report</dt>' . '  <dd>' . ($diff_mode ? $run1_txt . '<br><b>vs.</b><br>' . $run2_txt : $run1_txt) . '  </dd>' . '  <dt>Tip</dt>' . '  <dd>Click a function xhprof_name below to drill down.</dd>' . '</dl>';

  // data tables
  if (!empty($rep_symbol)) {
    if (!isset($symbol_tab[$rep_symbol])) {
      drupal_set_message(t("Symbol <strong>{$rep_symbol}</strong> not found in XHProf run"));
      return $output;
    }

    // Single function xhprof_report with parent/child information.
    if ($diff_mode) {
      $info1 = isset($symbol_tab1[$rep_symbol]) ? $symbol_tab1[$rep_symbol] : NULL;
      $info2 = isset($symbol_tab2[$rep_symbol]) ? $symbol_tab2[$rep_symbol] : NULL;
      $output .= xhprof_symbol_report($url_params, $run_delta, $symbol_tab[$rep_symbol], $sort, $rep_symbol, $run1, $info1, $run2, $info2);
    }
    else {
      $output .= xhprof_symbol_report($url_params, $run1_data, $symbol_tab[$rep_symbol], $sort, $rep_symbol, $run1);
    }
  }
  else {

    // flat top-level report of all functions.
    $output .= xhprof_full_report($url_params, $symbol_tab, $sort, $run1, $run2);
  }
  return $output;
}