--- performance.module.orig	2009-02-21 21:02:36.000000000 +0100
+++ performance.module	2009-04-21 13:18:25.046875000 +0200
@@ -1,9 +1,13 @@
 <?php
 // $Id: performance.module,v 1.2.2.23 2009/02/21 20:02:36 kbahey Exp $
 
-// Copyright Khalid Baheyeldin 2008 of http://2bits.com
+/**
+ * @file performance.module
+  * Logs detailed and/or summary page generation time and memory consumption for page requests.
+ * Copyright Khalid Baheyeldin 2008 of http://2bits.com
+ */
 
-define('PERFORMANCE_KEY', 'dru-perf:' . $_SERVER['HTTP_HOST'] . ':');
+define('PERFORMANCE_KEY', 'dru-perf:'. $_SERVER['HTTP_HOST'] .':');
 
 function performance_menu() {
   $items = array();
@@ -196,7 +200,7 @@ function performance_log_summary_apc($pa
   else {
     $data = array(
       'path'            => $params['path'],
-      'bytes_max'       => $params['mem'], 
+      'bytes_max'       => $params['mem'],
       'bytes_avg'       => $params['mem'],
       'millisecs_max'   => $params['timer'],
       'millisecs_avg'   => $params['timer'],
@@ -214,7 +218,7 @@ function performance_log_summary_apc($pa
 function performance_log_summary_db($params = array()) {
   $row = db_fetch_object(db_query("SELECT * FROM {performance_summary} WHERE path = '%s'", $params['path']));
   if (!empty($row)) {
-    db_query("UPDATE {performance_summary} 
+    db_query("UPDATE {performance_summary}
       SET last_access = %d,
       num_accesses = num_accesses + 1,
       bytes_max = %d,
@@ -243,12 +247,12 @@ function performance_log_summary_db($par
       (path, last_access, num_accesses,
       bytes_max, bytes_avg, millisecs_max, millisecs_avg,
       query_count_max, query_count_avg, query_timer_max, query_timer_avg)
-      VALUES 
+      VALUES
       ('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
       $params['path'],
       time(),
       1,
-      $params['mem'], 
+      $params['mem'],
       $params['mem'],
       $params['timer'],
       $params['timer'],
@@ -277,8 +281,8 @@ function performance_log_details($params
 function performance_apc_list_all() {
   $key_list = array();
   $list = apc_cache_info('user');
-  foreach($list['cache_list'] as $cache_id => $cache_data) {
-    $regex = '/^' . PERFORMANCE_KEY . '/';
+  foreach ($list['cache_list'] as $cache_id => $cache_data) {
+    $regex = '/^'. PERFORMANCE_KEY .'/';
     if (preg_match($regex, $cache_data['info'])) {
       $key_list[] = $cache_data['info'];
     }
@@ -320,7 +324,7 @@ function performance_view_summary() {
 
   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) {
+    foreach (performance_apc_list_all() as $key) {
       $data_list[] = apc_fetch($key);
     }
   }
@@ -329,12 +333,12 @@ function performance_view_summary() {
     $sql = "SELECT * FROM {performance_summary}";
     $tablesort = tablesort_sql($header);
     $result = pager_query($sql . $tablesort, 50);
-    while($row = db_fetch_array($result)) {
+    while ($row = db_fetch_array($result)) {
       $data_list[] = $row;
     }
   }
 
-  foreach($data_list as $data) {
+  foreach ($data_list as $data) {
     $total_rows++;
     $last_max = max($last_max, $data['last_access']);
     $last_min = min($last_min, $data['last_access']);
@@ -372,10 +376,10 @@ function performance_view_summary() {
   $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/>';
+      array('!threshold' => $threshold, '!shown' => $shown, '!total' => $total_rows)) .'<br/>';
   }
   else {
-    $output .= t('Showing all !total paths.', array('!total' => $total_rows)) . '<br/>';
+    $output .= t('Showing all !total paths.', array('!total' => $total_rows)) .'<br/>';
   }
 
   // Protect against divide by zero
@@ -388,11 +392,11 @@ function performance_view_summary() {
     $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 .= 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);
@@ -477,7 +481,7 @@ function performance_cron_apc_prune($tim
     return;
   }
 
-  foreach($list as $key) {
+  foreach ($list as $key) {
     if ($data = apc_fetch($key)) {
       if ($data['last_access'] <= $timestamp) {
         apc_delete($key);
@@ -488,7 +492,7 @@ function performance_cron_apc_prune($tim
 
 function performance_clear_apc_confirm() {
   $form['confirm'] = array(
-    '#value' => t('Confirm APC clear'), 
+    '#value' => t('Confirm APC clear'),
   );
   return confirm_form(
     $form,
@@ -499,7 +503,7 @@ function performance_clear_apc_confirm()
     t('Cancel'));
 }
 
-function performance_clear_apc_confirm_submit($form_id, &$form) {
+function performance_clear_apc_confirm_submit($form, &$form_state) {
   if (!function_exists('apc_cache_info')) {
     drupal_set_message(t('APC is not enabled. Nothing to do ...'), 'status', FALSE);
     drupal_goto('admin/settings/performance');
@@ -512,7 +516,7 @@ function performance_clear_apc_confirm_s
     return;
   }
 
-  foreach($list as $key) {
+  foreach ($list as $key) {
     if ($data = apc_fetch($key)) {
       apc_delete($key);
     }
@@ -523,7 +527,7 @@ function performance_clear_apc_confirm_s
 }
 
 /**
- * Implementation of hook_nagios_info()
+ * Implementation of hook_nagios_info().
  */
 function performance_nagios_info() {
   return array(
@@ -533,11 +537,11 @@ function performance_nagios_info() {
 }
 
 /**
- * Implementation of hook_nagios()
+ * Implementation of hook_nagios().
  */
 function performance_nagios() {
   $info = performance_nagios_info();
-  $id = $info['id']; 
+  $id = $info['id'];
 
   // Find out if we have what we need enabled
   $sum = array();
@@ -562,19 +566,19 @@ function performance_nagios() {
   // Check which data store to use
   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) {
+    foreach (performance_apc_list_all() as $key) {
       $data_list[] = apc_fetch($key);
     }
   }
   else {
     // Get the data form the database table for URLs that have been accessed in the last 15 minutes
     $result = db_query("SELECT * FROM {performance_summary} WHERE last_access >= %d", time() - 15*60);
-    while($row = db_fetch_array($result)) {
+    while ($row = db_fetch_array($result)) {
       $data_list[] = $row;
     }
   }
 
-  foreach($data_list as $data) {
+  foreach ($data_list as $data) {
     $total_rows++;
 
     // Calculate running averages
