performance_view_summary()sites/all/modules/devel/performance/performance.module, line 313
<?php
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 <a href="@link">settings page</a> to enable it.', array('@link' => url('admin/config/development/performance_logging')));
}
$header = array();
$header[] = array('data' => t('Path'), 'field' => 'path');
$header[] = array('data' => t('Last access'), 'field' => 'last_access');
$header[] = array('data' => t('# accesses'), 'field' => 'num_accesses');
$header[] = array('data' => t('Max Memory (MB)'), 'field' => 'bytes_max');
$header[] = array('data' => t('Avg Memory (MB)'), 'field' => 'bytes_avg');
$header[] = array('data' => t('Milliseconds (Max)'), 'field' => 'millisecs_max');
$header[] = array('data' => t('Milliseconds (Avg)'), 'field' => 'millisecs_avg');
if (variable_get('performance_query', 0)) {
$header[] = array('data' => t('Query Millisecs (Max)'), 'field' => 'query_timer_max');
$header[] = array('data' => t('Query Millisecs (Avg)'), 'field' => 'query_timer_avg');
$header[] = array('data' => t('Query Count (Max)'), 'field' => 'query_count_max');
$header[] = array('data' => t('Query Count (Avg)'), 'field' => 'query_count_avg');
}
$total_rows = $shown = $last_max = $total_bytes = $total_millisecs = $total_accesses = 0;
$last_min = REQUEST_TIME;
$threshold = variable_get('performance_threshold_accesses', 0);
$data_list = array();
if (variable_get('performance_summary_apc', 0) && drupal_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, 50);
while ($row = db_fetch_array($result)) {
$data_list[] = $row;
}
}
$rows = array();
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'];
$row_data = array();
if ($data['num_accesses'] > $threshold) {
$shown++;
$row_data[] = $data['path'];
$row_data[] = format_date($data['last_access'], 'small');
$row_data[] = $data['num_accesses'];
$row_data[] = number_format($data['bytes_max']/1024/1024, 2);
$row_data[] = number_format($data['bytes_avg']/1024/1024, 2);
$row_data[] = number_format($data['millisecs_max'], 1);
$row_data[] = number_format($data['millisecs_avg'], 1);
if (variable_get('performance_query', 0)) {
$row_data[] = number_format($data['query_timer_max'], 1);
$row_data[] = number_format($data['query_timer_avg'], 1);
$row_data[] = $data['query_count_max'];
$row_data[] = $data['query_count_avg'];
}
}
$rows[] = array('data' => $row_data);
}
if (!$rows) {
$rows[] = array(array('data' => t('No statistics available yet.'), 'colspan' => count($header)));
}
$output = '';
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;
}
?>