You are here

function performance_shutdown in Performance Logging and Monitoring 6

Same name and namespace in other branches
  1. 5 performance.module \performance_shutdown()
  2. 6.2 performance.module \performance_shutdown()
  3. 7.2 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
Implementation of hook_boot().

File

./performance.module, line 308
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 $queries;

  // Don't log drush access.
  if (performance_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 (performance_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
  if (function_exists('memory_get_peak_usage')) {
    $params['mem'] = memory_get_peak_usage(TRUE);
  }
  else {
    $params['mem'] = 0;
  }

  // Query time and count
  $query_count = $query_timer = $sum = 0;
  if (variable_get(PERFORMANCE_QUERY_VAR, 0) && is_array($queries)) {
    foreach ($queries as $query) {
      $sum += $query[1];
    }
    $query_count = count($queries);
    $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);
    }
  }
}