You are here

function xhprof_run_list in XHProf 6

Same name and namespace in other branches
  1. 7 xhprof.module \xhprof_run_list()

Display list of saved XHProf runs.

1 string reference to 'xhprof_run_list'
xhprof_menu in ./xhprof.module
Implementation of hook_menu().

File

./xhprof.module, line 228

Code

function xhprof_run_list() {
  global $pager_page_array, $pager_total, $pager_total_items;
  xhprof_include();
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  $element = 0;
  $limit = 50;
  $class = variable_get('xhprof_default_class', 'XHProfRunsFile');
  $xhprof_runs_impl = new $class();
  $pager_page_array = array(
    $page,
  );
  $pager_total_items[$element] = $xhprof_runs_impl
    ->getCount();
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  $pager_start = $page * 50;
  $pager_end = $pager_start + 50;
  $runs = $xhprof_runs_impl
    ->getRuns(array(), $limit);

  // Set the pager info in these globals since we need to fake them for
  // theme_pager.
  // Table attributes
  $attributes = array(
    'id' => 'xhprof-runs-table',
  );

  // Table header
  $header = array();
  $header[] = array(
    'data' => t('View'),
  );
  $header[] = array(
    'data' => t('Path'),
    'field' => 'path',
  );
  $header[] = array(
    'data' => t('Date'),
    'field' => 'date',
    'sort' => 'desc',
  );

  // Table rows
  $rows = array();
  foreach ($runs as $run) {
    $row = array();
    $link = XHPROF_PATH . '/' . $run['run_id'];
    $row[] = array(
      'data' => l($run['run_id'], $link),
    );
    $row[] = array(
      'data' => isset($run['path']) ? $run['path'] : '',
    );
    $row[] = array(
      'data' => format_date($run['date'], 'small'),
    );
    $rows[] = $row;
  }
  $output = theme('table', $header, $rows, $attributes);
  $output .= theme('pager');
  return $output;
}