You are here

function performance_view_summary in Performance Logging and Monitoring 5

Same name and namespace in other branches
  1. 6.2 performance.module \performance_view_summary()
  2. 6 performance.module \performance_view_summary()
  3. 7.2 performance.module \performance_view_summary()
  4. 7 performance.module \performance_view_summary()
1 string reference to 'performance_view_summary'
performance_menu in ./performance.module

File

./performance.module, line 339

Code

function performance_view_summary() {
  $sum = array();
  $sum[] = variable_get('performance_summary_db', 0);
  $sum[] = variable_get('performance_summary_apc', 0);
  $go = array_sum($sum);
  if (!$go) {
    return t('Summary performance log is not enabled. Go to the !link to enable it.', array(
      '!link' => l(t('settings page'), 'admin/settings/performance_logging'),
    ));
  }
  $header = array(
    array(
      'data' => t('Path'),
      'field' => 'path',
    ),
    array(
      'data' => t('Last access'),
      'field' => 'last_access',
    ),
    array(
      'data' => t('# accesses'),
      'field' => 'num_accesses',
    ),
    array(
      'data' => t('Max Memory (MB)'),
      'field' => 'bytes_max',
    ),
    array(
      'data' => t('Avg Memory (MB)'),
      'field' => 'bytes_avg',
    ),
    array(
      'data' => t('Milliseconds (Max)'),
      'field' => 'millisecs_max',
    ),
    array(
      'data' => t('Milliseconds (Avg)'),
      'field' => 'millisecs_avg',
    ),
    array(
      'data' => t('Query Millisecs (Max)'),
      'field' => 'query_timer_max',
    ),
    array(
      'data' => t('Query Millisecs (Avg)'),
      'field' => 'query_timer_avg',
    ),
    array(
      'data' => t('Query Count (Max)'),
      'field' => 'query_count_max',
    ),
    array(
      'data' => t('Query Count (Avg)'),
      'field' => 'query_count_avg',
    ),
  );
  $total_rows = $shown = $last_max = $total_bytes = $total_millisecs = $total_accesses = 0;
  $last_min = time();
  $threshold = variable_get('performance_threshold_accesses', 0);
  if (variable_get('performance_summary_apc', 0) && function_exists('apc_cache_info')) {

    // Get the data from the APC cache
    foreach (performance_apc_list_all() as $key) {
      $data_list[] = apc_fetch($key);
    }
  }
  else {

    // Get the data form the database table
    $sql = "SELECT * FROM {performance_summary}";
    $tablesort = tablesort_sql($header);
    $result = pager_query($sql . $tablesort, 5000);
    while ($row = db_fetch_array($result)) {
      $data_list[] = $row;
    }
  }
  foreach ($data_list as $data) {
    $total_rows++;
    $last_max = max($last_max, $data['last_access']);
    $last_min = min($last_min, $data['last_access']);

    // Calculate running averages
    $total_bytes += $data['bytes_avg'];
    $total_millisecs += $data['millisecs_avg'];
    $total_accesses += $data['num_accesses'];
    if ($data['num_accesses'] > $threshold) {
      $shown++;
      $rows[] = array(
        'data' => array(
          performance_url($data['path'], $data['title']),
          format_date($data['last_access'], 'small'),
          $data['num_accesses'],
          number_format($data['bytes_max'] / 1024 / 1024, 2),
          number_format($data['bytes_avg'] / 1024 / 1024, 2),
          number_format($data['millisecs_max'], 1),
          number_format($data['millisecs_avg'], 1),
          number_format($data['query_timer_max'], 1),
          number_format($data['query_timer_avg'], 1),
          $data['query_count_max'],
          $data['query_count_avg'],
        ),
      );
    }
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No statistics available yet.'),
        'colspan' => count($header),
      ),
    );
  }
  if ($threshold) {
    $output .= t('Showing !shown paths with more than !threshold accesses, out of !total total paths.', array(
      '!threshold' => $threshold,
      '!shown' => $shown,
      '!total' => $total_rows,
    )) . '<br/>';
  }
  else {
    $output .= t('Showing all !total paths.', array(
      '!total' => $total_rows,
    )) . '<br/>';
  }

  // Protect against divide by zero
  if ($total_rows > 0) {
    $mb_avg = number_format($total_bytes / $total_rows / 1024 / 1024, 1);
    $ms_avg = number_format($total_millisecs / $total_rows, 2);
  }
  else {
    $mb_avg = 'n/a';
    $ms_avg = 'n/a';
  }
  $output .= t('Average memory per page: !mb_avg MB', array(
    '!mb_avg' => $mb_avg,
  )) . '<br/>';
  $output .= t('Average milliseconds per page: !ms_avg', array(
    '!ms_avg' => $ms_avg,
  )) . '<br/>';
  $output .= t('Total number of page accesses: !accesses', array(
    '!accesses' => $total_accesses,
  )) . '<br/>';
  $output .= t('First access: !access.', array(
    '!access' => format_date($last_min, 'small'),
  )) . '<br/>';
  $output .= t('Last access: !access.', array(
    '!access' => format_date($last_max, 'small'),
  )) . '<br/>';
  $output .= theme('table', $header, $rows);
  $output .= theme('pager', NULL, 50, 0);
  return $output;
}