summaryrefslogtreecommitdiffstats
path: root/performance/performance.install
blob: cd2ef3a84cc53896a0f5c4fc2e1c5eabbbe7e7cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
// $Id$

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

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;
}

function performance_install() {
  drupal_install_schema('performance');

  // Set the weight so this module runs last
  db_query("UPDATE {system} SET weight = 3000 WHERE name = 'performance'");
}

function performance_uninstall() {
  drupal_uninstall_schema('performance');
  db_query("DELETE FROM {variable} WHERE name LIKE 'performance%'");
}

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'       => 'Enabled',
      'severity'    => REQUIREMENT_WARNING,
      'description' => t('Performance detailed logging is <a href="@link">enabled</a>. This can cause severe issues on live sites.', array('@link' => url('admin/config/development/performance_logging'))),
    );
  }

  if (variable_get('dev_query', 0)) {
    if (variable_get('performance_detail', 0) ||
        variable_get('performance_summary_db', 0) ||
        variable_get('performance_summary_apc', 0)) {
      $requirements['performance_query'] = array(
        'title'       => t('Performance logging query'),
        'value'       => 'Enabled',
        'severity'    => REQUIREMENT_WARNING,
        'description' => t('Query timing and count logging is <a href="@link">enabled</a>. This can cause memory size per page to be larger than normal.', array('@link' => url('admin/config/development/performance_logging'))),
      );
    }
  }

  if (!function_exists('apc_fetch')) {
    $requirements['performance_apc'] = array(
      'title'       => t('Performance logging APC'),
      'value'       => 'Disabled',
      'severity'    => REQUIREMENT_WARNING,
      'description' => t('Performance logging on live web sites works best if APC is enabled.'),
    );
  }

  $shm_size = ini_get('apc.shm_size');
  if ($shm_size < 48) {
    $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 48 MB of memory. If you encounter errors when viewing the summary report, then try to increase that limit for APC.', array('!size' => $shm_size)),
    );
  }

  return $requirements;
}

function performance_update_1() {
  $ret = array();
  db_drop_field($ret, 'performance_detail', 'title');
  db_drop_field($ret, 'performance_summary', 'title');
  return $ret;
}

function performance_update_2() {
  $ret = array();
  db_add_field($ret, 'performance_detail', 'data', array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'));
  return $ret;
}

/**
 * Harmonize notations for milliseconds to "ms".
 *
 * @return array
 */
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');
  }
}