You are here

performance.install in Performance Logging and Monitoring 7

Install and update for Performance Logging

Copyright Khalid Baheyeldin 2008 of http://2bits.com

File

performance.install
View source
<?php

/**
 * @file
 * Install and update for Performance Logging
 *
 * Copyright Khalid Baheyeldin 2008 of http://2bits.com
 */

// Minimum APC shm memory size to require
define('PERFORMANCE_MIN_MEMORY', 48);

/**
 * Implementation of hook_schema().
 */
function performance_schema() {
  $schema = array();
  $schema['performance_summary'] = array(
    'fields' => array(
      'path' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'last_access' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'bytes_max' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'bytes_avg' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'ms_max' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'ms_avg' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_count_max' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_count_avg' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_timer_max' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_timer_avg' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'num_accesses' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
    ),
    'primary key' => array(
      'path',
    ),
    'indexes' => array(
      'last_access' => array(
        'last_access',
      ),
    ),
  );
  $schema['performance_detail'] = array(
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'disp-width' => '11',
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'bytes' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'ms' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_count' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'query_timer' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '11',
      ),
      'anon' => array(
        'type' => 'int',
        'not null' => FALSE,
        'default' => 1,
        'disp-width' => '1',
      ),
      'path' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => FALSE,
      ),
      'data' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
    'indexes' => array(
      'timestamp' => array(
        'timestamp',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function performance_install() {

  // Set the weight so this module runs last
  // SQL: UPDATE {system} SET weight = 3000 WHERE name = 'performance'
  db_update('system')
    ->fields(array(
    'weight' => 3000,
  ))
    ->condition('name', 'performance')
    ->execute();
}

/**
 * Implementation of hook_uninstall().
 */
function performance_uninstall() {

  // SQL: DELETE FROM {variable} WHERE name LIKE 'performance\_%'
  db_delete('variable')
    ->condition('name', 'performance\\_%', 'LIKE')
    ->execute();
}

/**
 * Implementation of hook_requirements().
 */
function performance_requirements($phase) {
  $requirements = array();
  if ($phase != 'runtime') {
    return $requirements;
  }
  if (variable_get('performance_detail', 0)) {
    $requirements['performance_detail'] = array(
      'title' => t('Performance logging details'),
      'value' => t('Enabled'),
      'severity' => REQUIREMENT_WARNING,
      'description' => t('Performance detailed logging is !link. This can cause severe issues on live sites.', array(
        '!link' => l(t('enabled'), PERFORMANCE_SETTINGS),
      )),
    );
  }
  $logging = FALSE;
  foreach (performance_data_stores() as $data) {
    if ($data['#enabled']) {
      $logging = TRUE;
      break;
    }
  }
  if (variable_get(PERFORMANCE_QUERY_VAR, 0) && $logging) {
    $requirements['performance_query'] = array(
      'title' => t('Performance logging query'),
      'value' => t('Enabled'),
      'severity' => REQUIREMENT_WARNING,
      'description' => t('Query timing and count logging is !link. This can cause memory size per page to be larger than normal.', array(
        '!link' => l(t('enabled'), PERFORMANCE_SETTINGS),
      )),
    );
  }

  // Since these checks are done at runtime, performance_data_stores() is
  // available!
  $alt_cache = FALSE;
  foreach (performance_data_stores() as $store => $data) {
    if ($store != 'db' && $data['#enabled']) {
      $alt_cache = TRUE;
      break;
    }
  }
  if (!$alt_cache) {
    $requirements['performance_apc'] = array(
      'title' => t('Performance logging APC / memcache'),
      'value' => t('Disabled'),
      'severity' => REQUIREMENT_WARNING,
      'description' => t('Performance logging on live web sites works best if APC or Memcache is enabled.'),
    );
  }
  $shm_size = ini_get('apc.shm_size');
  if (function_exists('apc_fetch') && $shm_size < PERFORMANCE_MIN_MEMORY) {
    $requirements['performance_apc_mem'] = array(
      'title' => t('Performance logging APC memory size'),
      'value' => $shm_size,
      'severity' => REQUIREMENT_WARNING,
      'description' => t('APC has been configured for !size, which is less than the recommended !min_memory MB of memory. If you encounter errors when viewing the summary report, then try to increase that limit for APC.', array(
        '!size' => 1 * $shm_size,
        '!min_memory' => PERFORMANCE_MIN_MEMORY,
      )),
    );
  }
  return $requirements;
}

/**
 * Harmonize notations for milliseconds to "ms".
 */
function performance_update_7001() {
  $int_field = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'disp-width' => '11',
  );
  db_change_field('performance_summary', 'millisecs_max', 'ms_max', $int_field);
  db_change_field('performance_summary', 'millisecs_avg', 'ms_avg', $int_field);
  db_change_field('performance_detail', 'millisecs', 'ms', $int_field);

  // We don't have a cache update method, so it's better to clear it
  if (function_exists('apc_fetch')) {
    apc_clear_cache('user');
  }
}

Functions

Namesort descending Description
performance_install Implementation of hook_install().
performance_requirements Implementation of hook_requirements().
performance_schema Implementation of hook_schema().
performance_uninstall Implementation of hook_uninstall().
performance_update_7001 Harmonize notations for milliseconds to "ms".

Constants