function performance_view_summary in Performance Logging and Monitoring 6.2
Same name and namespace in other branches
- 5 performance.module \performance_view_summary()
- 6 performance.module \performance_view_summary()
- 7.2 performance.module \performance_view_summary()
- 7 performance.module \performance_view_summary()
Summary page callback.
1 string reference to 'performance_view_summary'
- performance_menu in ./
performance.module - Implementation of hook_menu().
File
- ./
performance.module, line 492 - Logs detailed and/or summary page generation time and memory consumption for page requests. Copyright Khalid Baheyeldin 2008 of http://2bits.com
Code
function performance_view_summary() {
drupal_set_title(t('Performance logs: Summary'));
global $pager_page_array, $pager_total_items, $pager_limits, $pager_total;
// array of element-keyed total number of pages
$rows = $data_list = array();
// Build table header.
$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('MB Memory (Max)'),
'field' => 'bytes_max',
),
array(
'data' => t('MB Memory (Avg)'),
'field' => 'bytes_sum',
),
array(
'data' => t('ms (Max)'),
'field' => 'ms_max',
),
array(
'data' => t('ms (Avg)'),
'field' => 'ms_sum',
),
array(
'data' => t('Language'),
'field' => 'language',
),
array(
'data' => t('Anonymous?'),
'field' => 'anon',
),
);
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
$header[] = array(
'data' => t('Query ms (Max)'),
'field' => 'query_timer_max',
);
$header[] = array(
'data' => t('Query ms (Avg)'),
'field' => 'query_timer_sum',
);
$header[] = array(
'data' => t('Query Count (Max)'),
'field' => 'query_count_max',
);
$header[] = array(
'data' => t('Query Count (Avg)'),
'field' => 'query_count_sum',
);
}
// Set up pager since this is not done automatically when using caching bins.
// Note that there can be data in these variables already hence the 'keyed'
// setup of the arrays.
$pager_height = 50;
$pager_total_items = array(
0 => 0,
);
$pager_limits = array(
0 => $pager_height,
);
$page = isset($_GET['page']) ? sprintf('%d', $_GET['page']) : 0;
$pager_page_array = array(
0 => $page,
);
$data_list = performance_traverse_cache('performance_get_summary');
if (empty($data_list) && !variable_get('performance_summary', 0)) {
return t('Summary performance log is not enabled. Go to the !link to enable it.', array(
'!link' => l(t('settings page'), PERFORMANCE_SETTINGS, array(
'query' => drupal_get_destination(),
)),
));
}
elseif (!variable_get('performance_summary', 0)) {
drupal_set_message(t('Summary performance log is not enabled! Showing stored logs.'), 'warning');
}
$pager_total = array(
0 => ceil($pager_total_items[0] / $pager_limits[0]),
);
// Setup sorting since this is not done automatically when using caching bins.
$sort_direction = tablesort_get_sort($header);
$sort_field = tablesort_get_order($header);
// TODO: find a solution for the avg columns! These need to be calculated
// first, prolly...
$data_list = performance_sort_summary($data_list, $sort_direction, $sort_field['sql']);
// Format data into table.
$threshold = variable_get('performance_threshold_accesses', 0);
$total_rows = $shown = $last_max = $total_bytes = $total_ms = $total_accesses = 0;
$last_min = time();
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_sum'] / $data['num_accesses'];
$total_ms += $data['ms_sum'] / $data['num_accesses'];
$total_accesses += $data['num_accesses'];
$row_data = array();
if ($data['num_accesses'] > $threshold) {
$shown++;
$row_data[] = l($data['path'], $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_sum'] / $data['num_accesses'] / 1024 / 1024, 2);
$row_data[] = number_format($data['ms_max'], 1);
$row_data[] = number_format($data['ms_sum'] / $data['num_accesses'], 1);
$row_data[] = $data['language'];
$row_data[] = $data['anon'] ? t('Yes') : t('No');
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
$row_data[] = number_format($data['query_timer_max'], 1);
$row_data[] = number_format($data['query_timer_sum'] / $data['num_accesses'], 1);
$row_data[] = $data['query_count_max'];
$row_data[] = $data['query_count_sum'] / $data['num_accesses'];
}
}
$rows[] = array(
'data' => $row_data,
);
}
if (!$rows) {
$rows[] = array(
array(
'data' => t('No statistics available yet.'),
'colspan' => count($header),
),
);
}
$output = '<p>';
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_ms / $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 duration 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 .= '</p><p> </p>';
$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, $pager_height, 0);
$output .= l(t('Clear logs'), 'admin/reports/performance-logging/clear/summary');
return $output;
}