You are here

function xhprof_profiler_report in XHProf 7

Same name and namespace in other branches
  1. 6 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);
  if ($diff_mode) {
    $diff_text = "Diff";
    $run1_link = l('View Run #' . $run1, xhprof_path_for_run($run1));
    $run2_txt = sprintf("<b>Run #%s:</b> %s", $run2, $run2_desc);
    $run2_link = l('View Run #' . $run2, xhprof_path_for_run($run2));
  }
  else {
    $diff_text = "Run";
  }

  // set up the action links for operations that can be done on this report
  $links = array();
  $links[] = l("View Top Level {$diff_text} Report", xhprof_path_for_run($run1, $run2));
  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[] = l('Invert ' . $diff_text . ' Report', xhprof_path_for_run($run2, $run1));
  }
  $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>' . '</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;
}