You are here

function performance_shutdown in Performance Logging and Monitoring 7

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.2 performance.module \performance_shutdown()

Shutdown function that collects all performance data.

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

File

./performance.module, line 310
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() {

  // 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 certain paths defined by the user.
  if (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;
  $anon = !empty($data['anon']) ? 'Yes' : 'No';
  $header = array(
    'path' => $path,
    'timer' => $params['timer'],
    'anon' => $anon,
  );

  // TODO: what is this for? Find out and document it, or remove it.
  module_invoke_all('performance', 'header', $header);
  if (variable_get('performance_detail', 0)) {

    // TODO: what is this for? Find out and document it, or remove it.
    $data = module_invoke_all('performance', 'data');
    if (!empty($data[0])) {
      $params['data'] = $data[0];
    }
    else {
      $params['data'] = NULL;
    }
    performance_log_details($params);
  }
  else {

    // TODO: what is this for? Find out and document it, or remove it.
    module_invoke_all('performance', 'disable');
  }
  foreach (performance_data_stores() as $store => $data) {
    if ($data['#enabled']) {
      call_user_func('performance_log_summary_' . $store, $params);
    }
  }
}