You are here

function performance_shutdown in Performance Logging and Monitoring 7.2

Same name and namespace in other branches
  1. 5 performance.module \performance_shutdown()
  2. 6.2 performance.module \performance_shutdown()
  3. 6 performance.module \performance_shutdown()
  4. 7 performance.module \performance_shutdown()

Shutdown function that collects all performance data.

1 string reference to 'performance_shutdown'
performance_boot in ./performance.module
Implements hook_boot().

File

./performance.module, line 250
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_shutdown() {
  global $user, $language;

  // Don't log drush access.
  if (drupal_is_cli() && variable_get('performance_nodrush', 1)) {
    return;
  }
  if (isset($_GET['q']) && $_GET['q']) {

    // q= has a value, use that for the path
    $path = $_GET['q'];
  }
  elseif (drupal_is_cli()) {
    $path = 'drush';
  }
  else {

    // q= is empty, use whatever the site_frontpage is set to
    $path = variable_get('site_frontpage', 'node');
  }

  // Skip if page from cache or on certain paths defined by the user.
  if (!function_exists('drupal_match_path') || drupal_match_path($path, variable_get('performance_skip_paths', ''))) {
    return;
  }
  $params = array(
    'timer' => timer_read('page'),
    'path' => $path,
  );

  // Memory.
  // No need to check if this function exists in D7, as it has a minimal
  // requirement of PHP 5.2.5.
  $params['mem'] = memory_get_peak_usage(TRUE);

  // Query time and count
  $query_count = $query_timer = $sum = 0;
  if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {

    // See http://drupal.org/node/1022204
    $queries = Database::getLog('performance', 'default');
    foreach ($queries as $query) {
      $sum += $query['time'];
      $query_count++;
    }
    $query_timer = round($sum * 1000, 2);
  }
  $params['query_count'] = $query_count;
  $params['query_timer'] = $query_timer;

  // Anonymous access?
  $params['anon'] = $user->uid ? 0 : 1;

  // Language
  $params['language'] = $language->language;

  // There used to be a module_invoke_all('performance', 'header', $header) call
  // here but it has been removed. $header was an associative array containing
  // path, timer (ms) and anon ('Yes' or 'No').
  if (variable_get('performance_detail', 0)) {

    // There used to be a module_invoke_all('performance', 'data') call here. As
    // it was undocumented and therefore unknown, it has been removed. The data
    // column has been kept so that we can re-implement if needed.
    $params['data'] = NULL;
    performance_log_details($params);
  }

  // There used to be a module_invoke_all('performance', 'disable') call here in
  // an else statement.
  if (variable_get('performance_summary', 0)) {
    performance_log_summary($params);
  }
}